[PATCH 1 of 1] Add basic subrepo support to 'hg status'
macke at yar.nu
macke at yar.nu
Sun Jan 31 20:13:11 UTC 2010
# HG changeset patch
# User Marcus Lindblom <macke at yar.nu>
# Date 1264968249 -3600
# Node ID b0832622ac10c81047279302589b43f460b8139f
# Parent b47a9e591e41e81b6836bf9425eabecf80eb7a00
Add basic subrepo support to 'hg status'
Shows status recursively, for hg and svn subrepos.
Does not yet show status of subrepos when --rev is specified.
diff -r b47a9e591e41 -r b0832622ac10 mercurial/commands.py
--- a/mercurial/commands.py Sat Jan 30 15:45:09 2010 +0100
+++ b/mercurial/commands.py Sun Jan 31 21:04:09 2010 +0100
@@ -2866,7 +2866,22 @@
if revs and change:
msg = _('cannot specify --rev and --change at the same time')
raise util.Abort(msg)
- elif change:
+
+ # status subrepos depth-first for coherent ordering
+ # add _subrepo key to opts to report path
+ c = repo['']
+ subs = c.substate # only repos that are committed
+ subrepo = opts.get('_subrepo', [])
+
+ if (revs or change) and (subs or subrepo):
+ ui.warn(_('not showing subrepo status: --rev option not supported yet\n'))
+ else:
+ for s in sorted(subs):
+ opts2 = dict(opts)
+ opts2['_subrepo'] = subrepo + [s]
+ c.sub(s).status(*pats, **opts2)
+
+ if change:
node2 = repo.lookup(change)
node1 = repo[node2].parents()[0].node()
else:
@@ -2900,8 +2915,17 @@
elif v in added:
copy[v] = k
+ subrepoinfoshown = False
+
for state, char, files in changestates:
if state in show:
+ if files and not subrepoinfoshown:
+ subrepoinfoshown = True
+ if subrepo:
+ ui.status(_('status in subrepo %s:\n') % '/'.join(subrepo))
+ elif subs:
+ ui.status(_('status in main repo:\n'))
+
format = "%s %%s%s" % (char, end)
if opts.get('no_status'):
format = "%%s%s" % end
diff -r b47a9e591e41 -r b0832622ac10 mercurial/subrepo.py
--- a/mercurial/subrepo.py Sat Jan 30 15:45:09 2010 +0100
+++ b/mercurial/subrepo.py Sun Jan 31 21:04:09 2010 +0100
@@ -168,8 +168,9 @@
# get(self, state): run whatever commands are needed to put the
# subrepo into this state
# merge(self, state): merge currently-saved state with the new state.
-# push(self, force): perform whatever action is analagous to 'hg push'
+# push(self, force): perform whatever action is analogous to 'hg push'
# This may be a no-op on some systems.
+# status(self, *pats, **opts): show changed files in the working directory
class hgsubrepo(object):
def __init__(self, ctx, path, state):
@@ -253,6 +254,11 @@
other = hg.repository(self._repo.ui, dsturl)
self._repo.push(other, force)
+ def status(self, *pats, **opts):
+ import mercurial.commands
+ mercurial.commands.status(self._repo.ui, self._repo, *pats, **opts)
+
+
class svnsubrepo(object):
def __init__(self, ctx, path, state):
self._path = path
@@ -354,6 +360,14 @@
# nothing for svn
pass
+ def status(self, *pats, **opts):
+ # TODO: mimic hg and don't show any output if we only get svn:externals status
+ status = self._svncommand(['status'])
+ self._ui.status(_('status in subrepo %s:\n') % self._path)
+ self._ui.status(status)
+
+
+
types = {
'hg': hgsubrepo,
'svn': svnsubrepo,
diff -r b47a9e591e41 -r b0832622ac10 tests/test-subrepo-status
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-subrepo-status Sun Jan 31 21:04:09 2010 +0100
@@ -0,0 +1,54 @@
+hg.py#!/bin/sh
+
+rm -rf sub
+mkdir sub
+cd sub
+hg init t
+cd t
+
+echo % first revision, no sub
+echo a > a
+hg ci -Am0
+
+echo % add first sub
+echo s = s > .hgsub
+hg add .hgsub
+hg init s
+echo a > s/a
+hg -R s ci -Ams0
+hg ci -m1
+
+echo % add sub sub
+echo ss = ss > s/.hgsub
+hg init s/ss
+echo a > s/ss/a
+hg -R s add s/.hgsub
+hg -R s/ss add s/ss/a
+hg ci -m2
+
+echo % bump sub rev
+echo b > s/a
+hg -R s ci -ms1
+hg ci -m3
+
+echo % issuing status commands
+echo % no changes
+hg st
+
+echo % add b
+echo b > b
+hg st
+
+echo % add s/b
+echo b > s/b
+hg st
+
+echo % add s/ss/b
+echo b > s/ss/b
+hg st
+
+
+echo % test --rev option
+hg st --rev 1
+
+exit 0
diff -r b47a9e591e41 -r b0832622ac10 tests/test-subrepo-status.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-subrepo-status.out Sun Jan 31 21:04:09 2010 +0100
@@ -0,0 +1,33 @@
+hg.py#!/bin/sh: No such file or directory
+% first revision, no sub
+adding a
+% add first sub
+adding a
+committing subrepository s
+% add sub sub
+committing subrepository s
+committing subrepository ss
+% bump sub rev
+committing subrepository s
+% issuing status commands
+% no changes
+% add b
+status in main:
+? b
+% add s/b
+status in subrepo s:
+? b
+status in main:
+? b
+% add s/ss/b
+status in subrepo s/ss:
+? b
+status in subrepo s:
+? b
+status in main:
+? b
+% test --rev option
+not showing subrepo status: --rev option not supported yet
+status in main:
+M .hgsubstate
+? b
diff -r b47a9e591e41 -r b0832622ac10 tests/test-subrepo-svn
--- a/tests/test-subrepo-svn Sat Jan 30 15:45:09 2010 +0100
+++ b/tests/test-subrepo-svn Sun Jan 31 21:04:09 2010 +0100
@@ -63,9 +63,10 @@
hg commit -m 'Message!'
hg debugsub | $filterpath
+
echo
echo a > s/a
-echo % should be empty despite change to s/a
+echo % should show change to s/a in subrepo
hg st
echo
diff -r b47a9e591e41 -r b0832622ac10 tests/test-subrepo-svn.out
--- a/tests/test-subrepo-svn.out Sat Jan 30 15:45:09 2010 +0100
+++ b/tests/test-subrepo-svn.out Sun Jan 31 21:04:09 2010 +0100
@@ -39,7 +39,12 @@
source file:///root/svn-repo/src
revision 3
-% should be empty despite change to s/a
+% should show change to s/a in subrepo
+status in subrepo s:
+? s/a
+X s/externals
+
+Performing status on external item at 's/externals'
% add a commit from svn
U alpha
More information about the Mercurial-devel
mailing list