Deleted Added
sdiff udiff text old ( 5309:4d3a6e086488 ) new ( 5465:4cff095bbf2b )
full compact
1#! /usr/bin/env python
2# Copyright (c) 2006 The Regents of The University of Michigan
3# Copyright (c) 2007 The Hewlett-Packard Development Company
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the

--- 244 unchanged lines hidden (view full) ---

256 if i < fbeg:
257 modified.add(i)
258 elif i + 1 >= fend:
259 break
260 elif i > max_lines:
261 break
262 return modified
263
264def do_check_whitespace(ui, repo, *files, **args):
265 """check files for proper m5 style guidelines"""
266 from mercurial import mdiff, util
267
268 if files:
269 files = frozenset(files)
270
271 def skip(name):
272 return files and name in files
273
274 def prompt(name, fixonly=None):
275 if args.get('auto', False):
276 result = 'f'
277 else:
278 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", "^[aif]$", "a")
279 if result == 'a':
280 return True
281 elif result == 'i':
282 pass
283 elif result == 'f':
284 fixwhite(repo.wjoin(name), args['tabsize'], fixonly)
285 else:
286 raise util.Abort(_("Invalid response: '%s'") % result)
287
288 return False
289
290 modified, added, removed, deleted, unknown, ignore, clean = repo.status()
291
292 for fname in added:
293 if skip(fname):
294 continue
295
296 ok = True
297 for line,num in checkwhite(repo.wjoin(fname)):
298 ui.write("invalid whitespace in %s:%d\n" % (fname, num))
299 if ui.verbose:
300 ui.write(">>%s<<\n" % line[-1])
301 ok = False
302
303 if not ok:
304 if prompt(fname):
305 return True
306
307 wctx = repo.workingctx()
308 for fname in modified:
309 if skip(fname):
310 continue
311
312 if not whitespace_file(fname):
313 continue
314
315 fctx = wctx.filectx(fname)
316 pctx = fctx.parents()
317 assert len(pctx) in (1, 2)
318
319 file_data = fctx.data()

--- 7 unchanged lines hidden (view full) ---

327 for i,line in enumerate(lines):
328 if i not in mod_lines:
329 continue
330
331 if checkwhite_line(line):
332 continue
333
334 ui.write("invalid whitespace: %s:%d\n" % (fname, i+1))
335 if ui.verbose:
336 ui.write(">>%s<<\n" % line[:-1])
337 fixonly.add(i)
338
339 if fixonly:
340 if prompt(fname, fixonly):
341 return True
342
343def check_whitespace(ui, repo, hooktype, node, parent1, parent2):
344 if hooktype != 'pretxncommit':
345 raise AttributeError, \
346 "This hook is only meant for pretxncommit, not %s" % hooktype
347
348 args = { 'tabsize' : 8 }
349 do_check_whitespace(ui, repo, **args)
350
351def check_format(ui, repo, hooktype, node, parent1, parent2):
352 if hooktype != 'pretxncommit':
353 raise AttributeError, \
354 "This hook is only meant for pretxncommit, not %s" % hooktype
355
356 modified, added, removed, deleted, unknown, ignore, clean = repo.status()
357
358 verbose = 0

--- 5 unchanged lines hidden (view full) ---

364 stats.dump()
365 result = ui.prompt("invalid formatting\n(i)gnore or (a)bort?",
366 "^[ia]$", "a")
367 if result.startswith('i'):
368 pass
369 elif result.startswith('a'):
370 return True
371 else:
372 raise util.Abort(_("Invalid response: '%s'") % result)
373
374 return False
375
376try:
377 from mercurial.i18n import _
378except ImportError:
379 def _(arg):
380 return arg
381
382cmdtable = {
383 '^m5style' :
384 ( do_check_whitespace,
385 [ ('a', 'auto', False, _("automatically fix whitespace")),
386 ('t', 'tabsize', 8, _("Number of spaces TAB indents")) ],
387 _('hg m5check [-t <tabsize>] [FILE]...')),
388}
389if __name__ == '__main__':
390 import getopt
391
392 progname = sys.argv[0]
393 if len(sys.argv) < 2:
394 sys.exit('usage: %s <command> [<command args>]' % progname)
395
396 fixwhite_usage = '%s fixwhite [-t <tabsize> ] <path> [...] \n' % progname

--- 47 unchanged lines hidden ---