[PATCH 5 of 5] subrepo: basic support for status of git subrepos

Eric Eisner ede at MIT.EDU
Mon Dec 20 13:11:11 CST 2010


# HG changeset patch
# User Eric Eisner <ede at mit.edu>
# Date 1292871573 18000
# Node ID 2537bd17421d10b0ece2542f6e24c1b9ae68925d
# Parent  413bef846806cc5fbd71dbcf14e444ce6ecf05cd
subrepo: basic support for status of git subrepos

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -903,6 +903,29 @@ class gitsubrepo(abstractsubrepo):
         ui.progress(_('archiving (%s)') % relpath, None)
 
 
+    def status(self, rev2, **opts):
+        rev1 = self._state[1]
+        modified, added, removed = [], [], []
+        if rev2:
+            command = ['diff-tree', rev1, rev2]
+        else:
+            command = ['diff-index', rev1]
+        out = self._gitcommand(command)
+        for line in out.split('\n'):
+            tab = line.find('\t')
+            if tab == -1:
+                continue
+            status, f = line[tab - 1], line[tab + 1:]
+            if status == 'M':
+                modified.append(f)
+            elif status == 'A':
+                added.append(f)
+            elif status == 'D':
+                removed.append(f)
+
+        deleted = unknown = ignored = clean = []
+        return modified, added, removed, deleted, unknown, ignored, clean
+
 types = {
     'hg': hgsubrepo,
     'svn': svnsubrepo,
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -52,6 +52,8 @@ record a new commit from upstream from a
   $ git checkout -q -b testing origin/testing >/dev/null
 
   $ cd ..
+  $ hg status --subrepos
+  M s/g
   $ hg commit -m 'update git subrepo'
   committing subrepository s
   $ hg debugsub
@@ -99,6 +101,8 @@ clone root, make local change
 
   $ cd ../ta
   $ echo ggg >> s/g
+  $ hg status --subrepos
+  M s/g
   $ hg commit -m ggg
   committing subrepository s
   $ hg debugsub
@@ -119,6 +123,8 @@ clone root separately, make different lo
   $ git add f
   $ cd ..
 
+  $ hg status --subrepos
+  A s/f
   $ hg commit -m f
   committing subrepository s
   $ hg debugsub
@@ -160,6 +166,10 @@ user a pulls, merges, commits
   ggg
   $ hg commit -m 'merge'
   committing subrepository s
+  $ hg status --subrepos --rev 1:5
+  M .hgsubstate
+  M s/g
+  A s/f
   $ hg debugsub
   path s
    source   ../gitroot
@@ -282,6 +292,8 @@ create nested repo
 nested commit
 
   $ echo ffff >> inner/s/f
+  $ hg status --subrepos
+  M inner/s/f
   $ hg commit -m nested
   committing subrepository inner
   committing subrepository inner/s


More information about the Mercurial-devel mailing list