Commits

Bożydar Sobczak  committed 46b27b3

push command wrapped

  • Participants
  • Parent commits 1e8c30a

Comments (0)

Files changed (2)

 \.pyc
+\.pyo

File hgcodesmell.py

 import re
 import fnmatch
 
-from mercurial import commands, cmdutil, extensions, patch, util
+from mercurial import commands, cmdutil, extensions, patch, util, hg
 
 if util.version() >= '1.9':
     # cmdutil.match and cmdutil.revpair moved to scmutil
 vim_cmd = (re.compile(r':(w|wq|q|x)$', re.M), 'vim exit command')
 windows_nl = (re.compile(r'\r'), 'Windows newline')
 merge_marker = (re.compile(r'^(>>>>>>>|<<<<<<<)'), 'merge marker')
-imported_patch = (re.compile(r'^imported patch.*'), 'message from MQ')
+imported_patch = (re.compile(r'^imported patch.*'), 'MQ autogenerated message')
+mq_patch = (re.compile(r'^\[mq\].*'), 'MQ autogenerated message')
+config_patch = (re.compile(r'^config.*'), 'Configuration patch')
 
 # the master dict maps glob patterns to a list of smelly patterns
 SMELLY_STUFF = {
     '*.py': [print_stmt, zero_div, set_trace],
     '*': [vim_cmd, merge_marker],
 }
-SMELLY_MESSAGE_STUFF = [imported_patch]
+SMELLY_MESSAGE_STUFF = [imported_patch, mq_patch, config_patch]
 
 if os.name != 'nt':
     # only pick on Windows newlines if not on Windows
             if repo.dirstate._ignore(fn):
                 ui.warn('File %r added, but it would be ignored.\n' % fn)
                 smelly_count += 1
-    
-    for rex, reason in SMELLY_MESSAGE_STUFF:
-        if rex.match(change_message):
-            ui.warn('Smelly change message (%s)\n' % reason)
-            smelly_count += 1
             
     diff = patch.diff(repo, *revs, match=match)
     smellies = []
                          default='n').lower().startswith('y'):
             return smelly_count
     return orig_commit(ui, repo, *pats, **opts)
+    
+def new_push(orig_push, ui, repo, *pats, **opts):
+    revs = hg._outgoing(ui, repo, None, opts)
+    if revs:
+        smelly_count = 0
+        for rev in revs:
+            ctx = repo[rev]
+            for rex, reason in SMELLY_MESSAGE_STUFF:
+                description = ctx.description()
+                if rex.match(ctx.description()):
+                    smelly_count += 1
+                    ui.warn("Problem in rev %d. '%s' -> %s\n" % (ctx.rev(), description, reason))
+                    
+        if smelly_count:
+            if not ui.prompt('Found %d smelly change%s. Continue (y/N)?' %
+                             (smelly_count, smelly_count != 1 and 's' or ''),
+                             default='n').lower().startswith('y'):
+                return smelly_count
+    return orig_push(ui, repo, *pats, **opts)
 
 def uisetup(ui):
     extensions.wrapcommand(commands.table, 'commit', new_commit)
+    extensions.wrapcommand(commands.table, 'push', new_push)