Exclude tag cmd from pretxcommit hook; exclude .hg files extension
authorChristian Ebert <blacktrash@gmx.net>
Thu, 21 Dec 2006 00:48:56 +0100
branchextension
changeset 44 dc6e7d0e607f
parent 43 fe5d9b9e78fc
child 45 5acf520f2115
Exclude tag cmd from pretxcommit hook; exclude .hg files Return unchanged data in superclass read() after every if clause. Perhaps a bit more readable.
hgkw/keyword.py
hgkw/pretxnkw.py
--- a/hgkw/keyword.py	Wed Dec 20 17:41:46 2006 +0100
+++ b/hgkw/keyword.py	Thu Dec 21 00:48:56 2006 +0100
@@ -22,34 +22,39 @@
 
         def read(self, node):
             data = super(kwfilelog, self).read(node)
-            if not util.binary(data):
-                c = context.filectx(self._repo, self._path, fileid=node,
-                                     filelog=self)
-                f = c.path()
-                for pat, opt in self._repo.ui.configitems('keyword'):
-                    if opt == 'expand':
-                        mf = util.matcher(self._repo.root,
-                                '', [pat], [], [])[1]
-                        if mf(f):
-                            re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
+            if util.binary(data):
+                return data
+
+            c = context.filectx(self._repo, self._path, fileid=node,
+                                 filelog=self)
+            f = c.path()
+            if f.startswith('.hg'):
+                return data
+
+            for pat, opt in self._repo.ui.configitems('keyword'):
+                if opt == 'expand':
+                    mf = util.matcher(self._repo.root,
+                            '', [pat], [], [])[1]
+                    if mf(f):
+                        re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
 
-                            def kwexpand(matchobj):
-                                RCSFile = os.path.basename(f)+',v'
-                                Source = os.path.join(self._repo.root, f)+',v'
-                                Revision = c.changectx()
-                                Date = util.datestr(date=c.date())
-                                Author = c.user()
-                                revdateauth = '%s %s %s' % (
-                                        Revision,
-                                        util.datestr(date=c.date(),
-                                            format=util.defaultdateformats[0]),
-                                        util.shortuser(Author))
-                                Header = '%s %s' % (Source, revdateauth)
-                                Id = '%s %s' % (RCSFile, revdateauth)
-                                return '$%s: %s $' % (
-                                        matchobj.group(1), eval(matchobj.group(1)))
+                        def kwexpand(matchobj):
+                            RCSFile = os.path.basename(f)+',v'
+                            Source = os.path.join(self._repo.root, f)+',v'
+                            Revision = c.changectx()
+                            Date = util.datestr(date=c.date())
+                            Author = c.user()
+                            revdateauth = '%s %s %s' % (
+                                    Revision,
+                                    util.datestr(date=c.date(),
+                                        format=util.defaultdateformats[0]),
+                                    util.shortuser(Author))
+                            Header = '%s %s' % (Source, revdateauth)
+                            Id = '%s %s' % (RCSFile, revdateauth)
+                            return '$%s: %s $' % (
+                                    matchobj.group(1), eval(matchobj.group(1)))
 
-                            return re_kw.sub(kwexpand, data)
+                        return re_kw.sub(kwexpand, data)
             return data
 
         def add(self, text, meta, tr, link, p1=None, p2=None):
--- a/hgkw/pretxnkw.py	Wed Dec 20 17:41:46 2006 +0100
+++ b/hgkw/pretxnkw.py	Thu Dec 21 00:48:56 2006 +0100
@@ -14,12 +14,15 @@
         return True
 
     # reparse args, opts again as pretxncommit hook is silent about them
-    sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[2:]
+    cmd, sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[1:]
+    # exclude tagging
+    if repr(cmd).split()[1] == 'tag':
+        return False
     files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
 
     # validity checks should have been done already
     modified, added = repo.status(files=files, match=match)[:2]
-    candidates = modified + added
+    candidates = [f for f in modified + added if not f.startswith('.hg')]
 
     if not candidates:
         return False