Fazlul Shahriar avatar Fazlul Shahriar committed af57329

Mercurial 1.9 compatibity and take care of a TODO

Comments (0)

Files changed (1)

 The second hook enforces Go's standard coding style, as dictated by gofmt.
 """
 
-# TODO:
-#   enforce style on code obtained from hg pull
-#   should only check files being commited, not *all* modified files
-
 from __future__ import with_statement
 
 import os
 import sys
 import subprocess
-from mercurial import cmdutil, error, util
+from mercurial import error, scmutil, util
+from os.path import join, relpath
+
 from . import pyindent
 
-
 def getchanged(ui, repo, args, opts):
-    matcher = cmdutil.match(repo, args, opts)
+    matcher = scmutil.match(repo[None], pats=opts['pats'], opts=opts['opts'])
     modified, added, _, _, _, _, _ = repo.status(match=matcher)
     return sorted(modified + added)
 
-def relpath(path, cwd):
-    """Return path relative to cwd
-    """
-    n = len(cwd)
-    if path.startswith(cwd) and path[n] == '/':
-        return path[n+1:]
-    return path
-
 def exceptionDetail():
     s = str(sys.exc_info()[0])
     if s.startswith("<type '") and s.endswith("'>"):
     """Hook that prevents transaction if modified .go file needs
     be to gofmt'ed.
     """
-    cwd = os.getcwd()
-    files = [relpath(repo.root + '/' + f, cwd)
+    files = [relpath(join(repo.root, f))
                 for f in getchanged(ui, repo, args, opts)
                     if f.endswith('.go')]
     if not files:
     """Hook that prevents transaction if modified .py file need
     reindenting.
     """
-    cwd = os.getcwd()
-    files = [relpath(repo.root + '/' + f, cwd)
+    files = [relpath(join(repo.root, f))
                 for f in getchanged(ui, repo, args, opts)
                     if f.endswith('.py')]
     bad = []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.