[PATCH 1 of 2] status: moved code from commands to hg

Erik Zielke ez at aragost.com
Mon Oct 4 05:59:09 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1286183166 -7200
# Node ID 1f5dd0b643e292a6d4c495ac06ef14e184ff6626
# Parent  f365aed7cc5b4ce5f42d1e2d20001e2dc7951c5b
status: moved code from commands to hg

Part of the code for status is moved from commands to hg. This is the
first step in another way of having a recursive version of hg status

diff -r f365aed7cc5b -r 1f5dd0b643e2 mercurial/commands.py
--- a/mercurial/commands.py	Fri Oct 01 23:16:11 2010 +0200
+++ b/mercurial/commands.py	Mon Oct 04 11:06:06 2010 +0200
@@ -3404,46 +3404,7 @@
         node1, node2 = cmdutil.revpair(repo, revs)
 
     cwd = (pats and repo.getcwd()) or ''
-    end = opts.get('print0') and '\0' or '\n'
-    copy = {}
-    states = 'modified added removed deleted unknown ignored clean'.split()
-    show = [k for k in states if opts.get(k)]
-    if opts.get('all'):
-        show += ui.quiet and (states[:4] + ['clean']) or states
-    if not show:
-        show = ui.quiet and states[:4] or states[:5]
-
-    stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
-                       'ignored' in show, 'clean' in show, 'unknown' in show,
-                       opts.get('subrepos'))
-    changestates = zip(states, 'MAR!?IC', stat)
-
-    if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
-        ctxn = repo[nullid]
-        ctx1 = repo[node1]
-        ctx2 = repo[node2]
-        added = stat[1]
-        if node2 is None:
-            added = stat[0] + stat[1] # merged?
-
-        for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
-            if k in added:
-                copy[k] = v
-            elif v in added:
-                copy[v] = k
-
-    for state, char, files in changestates:
-        if state in show:
-            format = "%s %%s%s" % (char, end)
-            if opts.get('no_status'):
-                format = "%%s%s" % end
-
-            for f in files:
-                ui.write(format % repo.pathto(f, cwd),
-                         label='status.' + state)
-                if f in copy:
-                    ui.write('  %s%s' % (repo.pathto(copy[f], cwd), end),
-                             label='status.copied')
+    hg.status(ui, repo, node1, node2, *pats, **opts)
 
 def summary(ui, repo, **opts):
     """summarize working directory state
diff -r f365aed7cc5b -r 1f5dd0b643e2 mercurial/hg.py
--- a/mercurial/hg.py	Fri Oct 01 23:16:11 2010 +0200
+++ b/mercurial/hg.py	Mon Oct 04 11:06:06 2010 +0200
@@ -15,6 +15,7 @@
 import merge as mergemod
 import verify as verifymod
 import errno, os, shutil
+import copies
 
 def _local(path):
     path = util.expandpath(util.drop_scheme('file', path))
@@ -408,6 +409,49 @@
         repo.ui.status(_("(branch merge, don't forget to commit)\n"))
     return stats[3] > 0
 
+def status(ui, repo, node1, node2, *pats, **opts):
+    cwd = (pats and repo.getcwd()) or ''
+    end = opts.get('print0') and '\0' or '\n'
+    copy = {}
+    states = 'modified added removed deleted unknown ignored clean'.split()
+    show = [k for k in states if opts.get(k)]
+    if opts.get('all'):
+        show += ui.quiet and (states[:4] + ['clean']) or states
+    if not show:
+        show = ui.quiet and states[:4] or states[:5]
+
+    stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
+                       'ignored' in show, 'clean' in show, 'unknown' in show,
+                       opts.get('subrepos'))
+    changestates = zip(states, 'MAR!?IC', stat)
+
+    if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
+        ctxn = repo[nullid]
+        ctx1 = repo[node1]
+        ctx2 = repo[node2]
+        added = stat[1]
+        if node2 is None:
+            added = stat[0] + stat[1] # merged?
+
+        for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
+            if k in added:
+                copy[k] = v
+            elif v in added:
+                copy[v] = k
+
+    for state, char, files in changestates:
+        if state in show:
+            format = "%s %%s%s" % (char, end)
+            if opts.get('no_status'):
+                format = "%%s%s" % end
+
+            for f in files:
+                ui.write(format % repo.pathto(f, cwd),
+                         label='status.' + state)
+                if f in copy:
+                    ui.write('  %s%s' % (repo.pathto(copy[f], cwd), end),
+                             label='status.copied')
+
 def incoming(ui, repo, source, opts):
     def recurse():
         ret = 1


More information about the Mercurial-devel mailing list