mirror of
https://github.com/oskar456/dzonegit.git
synced 2024-05-11 05:55:41 +00:00
Support comparsion between revisions as well (test pending)
This commit is contained in:
45
dzonegit.py
45
dzonegit.py
@@ -51,9 +51,13 @@ def get_head():
|
|||||||
return "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
return "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||||
|
|
||||||
|
|
||||||
def check_whitespace_errors(against):
|
def check_whitespace_errors(against, revision=None):
|
||||||
|
if revision:
|
||||||
|
cmd = ["git", "diff-tree", "--check", against, revision]
|
||||||
|
else:
|
||||||
|
cmd = ["git", "diff-index", "--check", "--cached", against]
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
["git", "diff-index", "--check", "--cached", against],
|
cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
@@ -62,8 +66,20 @@ def check_whitespace_errors(against):
|
|||||||
raise HookException("Whitespace errors", stderr=r.stdout)
|
raise HookException("Whitespace errors", stderr=r.stdout)
|
||||||
|
|
||||||
|
|
||||||
def get_file_contents(path, revision=""):
|
def check_tree_whitespace_errors(tree1, tree2):
|
||||||
|
r = subprocess.run(
|
||||||
|
["git", "diff-tree", "--check", tree1, tree2],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
if r.returncode != 0:
|
||||||
|
raise HookException("Whitespace errors", stderr=r.stdout)
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_contents(path, revision=None):
|
||||||
""" Return contents of a file in staged env or in some revision. """
|
""" Return contents of a file in staged env or in some revision. """
|
||||||
|
revision = "" if revision is None else revision
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
["git", "show", f"{revision}:{path}"],
|
["git", "show", f"{revision}:{path}"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@@ -120,12 +136,21 @@ def get_increased_serial(old):
|
|||||||
return str(old + 1)
|
return str(old + 1)
|
||||||
|
|
||||||
|
|
||||||
def get_altered_files(against, diff_filter=None):
|
def get_altered_files(against, diff_filter=None, revision=None):
|
||||||
""" Return list of changed files. """
|
""" Return list of changed files.
|
||||||
cmd = ["git", "diff", "--cached", "--name-only", "-z"]
|
If revision is None, list changes between staging area and
|
||||||
|
revision. Otherwise differences between two revisions are computed.
|
||||||
|
"""
|
||||||
|
cmd = ["git", "diff", "--name-only", "-z"]
|
||||||
if diff_filter:
|
if diff_filter:
|
||||||
cmd.append(f"--diff-filter={diff_filter}")
|
cmd.append(f"--diff-filter={diff_filter}")
|
||||||
cmd.append(against)
|
if revision:
|
||||||
|
cmd.append(against)
|
||||||
|
cmd.append(revision)
|
||||||
|
else:
|
||||||
|
cmd.append("--cached")
|
||||||
|
cmd.append(against)
|
||||||
|
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@@ -173,13 +198,13 @@ def get_zone_name(path, zonedata):
|
|||||||
return stemname
|
return stemname
|
||||||
|
|
||||||
|
|
||||||
def check_updated_zones(against):
|
def check_updated_zones(against, revision=None):
|
||||||
""" Check whether all updated zone files compile. """
|
""" Check whether all updated zone files compile. """
|
||||||
for f in get_altered_files(against, "AM"):
|
for f in get_altered_files(against, "AM", revision):
|
||||||
if not f.suffix == ".zone":
|
if not f.suffix == ".zone":
|
||||||
continue
|
continue
|
||||||
print(f"Checking file {f}")
|
print(f"Checking file {f}")
|
||||||
zonedata = get_file_contents(f)
|
zonedata = get_file_contents(f, revision)
|
||||||
zname = get_zone_name(f, zonedata)
|
zname = get_zone_name(f, zonedata)
|
||||||
rnew = compile_zone(zname, zonedata)
|
rnew = compile_zone(zname, zonedata)
|
||||||
if not rnew.success:
|
if not rnew.success:
|
||||||
|
|||||||
Reference in New Issue
Block a user