summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2007-07-22 13:45:12 -0700
committerNathan Binkert <nate@binkert.org>2007-07-22 13:45:12 -0700
commit089fce4f59fd0086202e9cf5f7b2a46c6545f7b6 (patch)
tree7a4aad525373b3515217eab12bbddd247d4e3f28 /util
parent78759ad17622e5af7fb4698e77fd33500b3e55b1 (diff)
downloadgem5-089fce4f59fd0086202e9cf5f7b2a46c6545f7b6.tar.xz
do proper style checks for merged files
--HG-- extra : convert_revision : f9d4c61ded4b13655dbe86f0bb6a0b3beaf45151
Diffstat (limited to 'util')
-rw-r--r--util/style.py50
1 files changed, 33 insertions, 17 deletions
diff --git a/util/style.py b/util/style.py
index 47c992755..b5e9e142e 100644
--- a/util/style.py
+++ b/util/style.py
@@ -230,8 +230,23 @@ def validate(filename, stats, verbose, exit_code):
msg(i, line, 'improper spacing after %s' % match.group(1))
bad()
+def modified_lines(old_data, new_data):
+ from itertools import count
+ from mercurial import bdiff, mdiff
+
+ modified = set()
+ counter = count()
+ for pbeg, pend, fbeg, fend in bdiff.blocks(old_data, new_data):
+ for i in counter:
+ if i < fbeg:
+ modified.add(i)
+ elif i + 1 >= fend:
+ break
+ return modified
+
def check_whitespace(ui, repo, hooktype, node, parent1, parent2):
- from mercurial import bdiff, mdiff, util
+ from mercurial import mdiff
+
if hooktype != 'pretxncommit':
raise AttributeError, \
"This hook is only meant for pretxncommit, not %s" % hooktype
@@ -269,25 +284,26 @@ def check_whitespace(ui, repo, hooktype, node, parent1, parent2):
for fname in modified:
fctx = wctx.filectx(fname)
pctx = fctx.parents()
- assert len(pctx) == 1
+ assert len(pctx) in (1, 2)
- pdata = pctx[0].data()
- fdata = fctx.data()
+ file_data = fctx.data()
+ mod_lines = modified_lines(pctx[0].data(), file_data)
+ if len(pctx) == 2:
+ m2 = modified_lines(pctx[1].data(), file_data)
+ mod_lines = mod_lines & m2 # only the lines that are new in both
fixonly = set()
- lines = enumerate(mdiff.splitnewlines(fdata))
- for pbeg, pend, fbeg, fend in bdiff.blocks(pdata, fdata):
- for i, line in lines:
- if i < fbeg:
- if checkwhite_line(line):
- continue
-
- ui.write("invalid whitespace: %s:%d\n" % (fname, i+1))
- if verbose:
- ui.write(">>%s<<\n" % line[:-1])
- fixonly.add(i)
- elif i + 1 >= fend:
- break
+ for i,line in enumerate(mdiff.splitnewlines(file_data)):
+ if i not in mod_lines:
+ continue
+
+ if checkwhite_line(line):
+ continue
+
+ ui.write("invalid whitespace: %s:%d\n" % (fname, i+1))
+ if verbose:
+ ui.write(">>%s<<\n" % line[:-1])
+ fixonly.add(i)
if fixonly:
if prompt(fname, fixonly):