summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:14:07 -0400
committerAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:14:07 -0400
commit35bc5210d3987cc97bcc557f1229e700327c9564 (patch)
treeca92a48a84657e91e67cf2f38d17f664299df388 /util
parent70176fecd1ff04f7b8957f3110497d758310b569 (diff)
downloadgem5-35bc5210d3987cc97bcc557f1229e700327c9564.tar.xz
style: Fixup strange semantics in hg m5style
The 'hg m5style' command had some rather strange semantics. When called without arguments, it applied the style checker to all added files and modified regions of modified files. However, when providing a list of files, it used that list as an ignore list instead of specifically checking those files. This patch makes the m5style command behave more like other Mercurial commands where the arguments are used to specify which files to work on instead of which files to ignore.
Diffstat (limited to 'util')
-rw-r--r--util/style.py110
1 files changed, 62 insertions, 48 deletions
diff --git a/util/style.py b/util/style.py
index 08c127765..fb3440541 100644
--- a/util/style.py
+++ b/util/style.py
@@ -1,4 +1,16 @@
#! /usr/bin/env python
+# Copyright (c) 2014 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2006 The Regents of The University of Michigan
# Copyright (c) 2007,2011 The Hewlett-Packard Development Company
# All rights reserved.
@@ -35,7 +47,7 @@ import sys
from os.path import dirname, join as joinpath
from itertools import count
-from mercurial import bdiff, mdiff
+from mercurial import bdiff, mdiff, commands
current_dir = dirname(__file__)
sys.path.insert(0, current_dir)
@@ -378,27 +390,25 @@ def validate(filename, stats, verbose, exit_code):
msg(i, line, 'improper spacing after %s' % match.group(1))
bad()
-def do_check_style(hgui, repo, *files, **args):
- """check files for proper m5 style guidelines"""
- from mercurial import mdiff, util
- auto = args.get('auto', False)
- if auto:
- auto = 'f'
- ui = MercurialUI(hgui, hgui.verbose, auto)
+def do_check_style(hgui, repo, *pats, **opts):
+ """check files for proper m5 style guidelines
- if files:
- files = frozenset(files)
+ Without an argument, checks all modified and added files for gem5
+ coding style violations. A list of files can be specified to limit
+ the checker to a subset of the repository. The style rules are
+ normally applied on a diff of the repository state (i.e., added
+ files are checked in their entirety while only modifications of
+ modified files are checked).
- def skip(name):
- # We never want to handle symlinks, so always skip them: If the location
- # pointed to is a directory, skip it. If the location is a file inside
- # the gem5 directory, it will be checked as a file, so symlink can be
- # skipped. If the location is a file outside gem5, we don't want to
- # check it anyway.
- if os.path.islink(name):
- return True
- return files and name in files
+ The --all option can be specified to include clean files and check
+ modified files in their entirety.
+ """
+ from mercurial import mdiff, util
+
+ opt_fix_white = opts.get('fix_white', False)
+ opt_all = opts.get('all', False)
+ ui = MercurialUI(hgui, hgui.verbose, opt_fix_white)
def prompt(name, func, regions=all_regions):
result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a')
@@ -409,39 +419,40 @@ def do_check_style(hgui, repo, *files, **args):
return False
- modified, added, removed, deleted, unknown, ignore, clean = repo.status()
-
- whitespace = Whitespace(ui)
- sorted_includes = SortedIncludes(ui)
- for fname in added:
- if skip(fname):
- continue
-
- fpath = joinpath(repo.root, fname)
-
- if whitespace.apply(fpath, prompt):
- return True
-
- if sorted_includes.apply(fpath, prompt):
- return True
+ # Import the match (repository file name matching helper)
+ # function. Different versions of Mercurial keep it in different
+ # modules and implement them differently.
try:
- wctx = repo.workingctx()
- except:
- from mercurial import context
- wctx = context.workingctx(repo)
+ from mercurial import scmutil
+ m = scmutil.match(repo[None], pats, opts)
+ except ImportError:
+ from mercurial import cmdutil
+ m = cmdutil.match(repo, pats, opts)
+
+ modified, added, removed, deleted, unknown, ignore, clean = \
+ repo.status(match=m, clean=opt_all)
+ if not opt_all:
+ try:
+ wctx = repo.workingctx()
+ except:
+ from mercurial import context
+ wctx = context.workingctx(repo)
- for fname in modified:
- if skip(fname):
- continue
+ files = [ (fn, all_regions) for fn in added ] + \
+ [ (fn, modregions(wctx, fn)) for fn in modified ]
+ else:
+ files = [ (fn, all_regions) for fn in added + modified + clean ]
+ whitespace = Whitespace(ui)
+ sorted_includes = SortedIncludes(ui)
+ for fname, mod_regions in files:
fpath = joinpath(repo.root, fname)
- regions = modregions(wctx, fname)
- if whitespace.apply(fpath, prompt, regions):
+ if whitespace.apply(fpath, prompt, mod_regions):
return True
- if sorted_includes.apply(fpath, prompt, regions):
+ if sorted_includes.apply(fpath, prompt, mod_regions):
return True
return False
@@ -499,10 +510,13 @@ except ImportError:
return arg
cmdtable = {
- '^m5style' :
- ( do_check_style,
- [ ('a', 'auto', False, _("automatically fix whitespace")) ],
- _('hg m5style [-a] [FILE]...')),
+ '^m5style' : (
+ do_check_style, [
+ ('w', 'fix-white', False, _("automatically fix whitespace")),
+ ('a', 'all', False,
+ _("include clean files and unmodified parts of modified files")),
+ ] + commands.walkopts,
+ _('hg m5style [-a] [FILE]...')),
'^m5format' :
( do_check_format,
[ ],