style.py (4782:50a634ae064a) | style.py (4784:e8b1f87b3a85) |
---|---|
1#! /usr/bin/env python 2# Copyright (c) 2007 The Regents of The University of Michigan 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 230 unchanged lines hidden (view full) --- 239 if cpp: 240 match = any_control.search(line) 241 if match and not good_control.search(line): 242 stats.badcontrol += 1 243 if verbose > 1: 244 msg(i, line, 'improper spacing after %s' % match.group(1)) 245 bad() 246 | 1#! /usr/bin/env python 2# Copyright (c) 2007 The Regents of The University of Michigan 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 230 unchanged lines hidden (view full) --- 239 if cpp: 240 match = any_control.search(line) 241 if match and not good_control.search(line): 242 stats.badcontrol += 1 243 if verbose > 1: 244 msg(i, line, 'improper spacing after %s' % match.group(1)) 245 bad() 246 |
247def modified_lines(old_data, new_data): | 247def modified_lines(old_data, new_data, max_lines): |
248 from itertools import count 249 from mercurial import bdiff, mdiff 250 251 modified = set() 252 counter = count() 253 for pbeg, pend, fbeg, fend in bdiff.blocks(old_data, new_data): 254 for i in counter: 255 if i < fbeg: 256 modified.add(i) 257 elif i + 1 >= fend: 258 break | 248 from itertools import count 249 from mercurial import bdiff, mdiff 250 251 modified = set() 252 counter = count() 253 for pbeg, pend, fbeg, fend in bdiff.blocks(old_data, new_data): 254 for i in counter: 255 if i < fbeg: 256 modified.add(i) 257 elif i + 1 >= fend: 258 break |
259 elif i > max_lines: 260 break |
|
259 return modified 260 261def check_whitespace(ui, repo, hooktype, node, parent1, parent2): 262 from mercurial import mdiff 263 264 if hooktype != 'pretxncommit': 265 raise AttributeError, \ 266 "This hook is only meant for pretxncommit, not %s" % hooktype --- 29 unchanged lines hidden (view full) --- 296 297 wctx = repo.workingctx() 298 for fname in modified: 299 fctx = wctx.filectx(fname) 300 pctx = fctx.parents() 301 assert len(pctx) in (1, 2) 302 303 file_data = fctx.data() | 261 return modified 262 263def check_whitespace(ui, repo, hooktype, node, parent1, parent2): 264 from mercurial import mdiff 265 266 if hooktype != 'pretxncommit': 267 raise AttributeError, \ 268 "This hook is only meant for pretxncommit, not %s" % hooktype --- 29 unchanged lines hidden (view full) --- 298 299 wctx = repo.workingctx() 300 for fname in modified: 301 fctx = wctx.filectx(fname) 302 pctx = fctx.parents() 303 assert len(pctx) in (1, 2) 304 305 file_data = fctx.data() |
304 mod_lines = modified_lines(pctx[0].data(), file_data) | 306 lines = mdiff.splitnewlines(file_data) 307 mod_lines = modified_lines(pctx[0].data(), file_data, len(lines)) |
305 if len(pctx) == 2: 306 m2 = modified_lines(pctx[1].data(), file_data) 307 mod_lines = mod_lines & m2 # only the lines that are new in both 308 309 fixonly = set() | 308 if len(pctx) == 2: 309 m2 = modified_lines(pctx[1].data(), file_data) 310 mod_lines = mod_lines & m2 # only the lines that are new in both 311 312 fixonly = set() |
310 for i,line in enumerate(mdiff.splitnewlines(file_data)): | 313 for i,line in enumerate(lines): |
311 if i not in mod_lines: 312 continue 313 314 if checkwhite_line(line): 315 continue 316 317 ui.write("invalid whitespace: %s:%d\n" % (fname, i+1)) 318 if verbose: --- 87 unchanged lines hidden --- | 314 if i not in mod_lines: 315 continue 316 317 if checkwhite_line(line): 318 continue 319 320 ui.write("invalid whitespace: %s:%d\n" % (fname, i+1)) 321 if verbose: --- 87 unchanged lines hidden --- |