[PATCH] sburepo: change default path in hgrc of subrepo after cloning

Saint Germain saintger at gmail.com
Wed Mar 3 17:25:09 CST 2010


Hello Matt,

After discussion with tonfa and sjl, I would like to introduce a --subrepo flag in order
to trigger some actions specific to subrepositories.

In the following patch for instance, we force update the subrepositories only if the --subrepo
flag is passed along with the --clean flag for the 'update' action.
It seems that this flag could be useful for actions as well (hg status for instance).

What do you think about this point ?

Regards,

# HG changeset patch
# User Saint Germain <saintger at gmail.com>
# Date 1267658379 -3600
# Branch stable
# Node ID 55fdca7327f169a339c674db577df8e08812b8ad
# Parent  612c142b7a822ad78b85622de581dd7e95d9ceca
subrepo: Force updating subrepos if using --subrepo with update --clean

Even if .hgsubstate doesn't need updating, subrepos may be 'dirty'. So if using --subrepo with
update --clean, add a check for 'dirty' subrepos and if found, force the update.

diff -r 612c142b7a82 -r 55fdca7327f1 mercurial/commands.py
--- a/mercurial/commands.py	Wed Mar 03 22:32:51 2010 +0100
+++ b/mercurial/commands.py	Thu Mar 04 00:19:39 2010 +0100
@@ -3253,7 +3253,8 @@
 
     return postincoming(ui, repo, modheads, opts.get('update'), None)
 
-def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
+def update(ui, repo, node=None, rev=None, clean=False, date=None,
+           check=False, subrepo=False):
     """update working directory
 
     Update the repository's working directory to the specified
@@ -3309,7 +3310,7 @@
         rev = cmdutil.finddate(ui, repo, date)
 
     if clean or check:
-        return hg.clean(repo, rev)
+        return hg.clean(repo, rev, subrepo=subrepo)
     else:
         return hg.update(repo, rev)
 
@@ -3833,6 +3834,8 @@
     "^update|up|checkout|co":
         (update,
          [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
+          ('', 'subrepo', None, _('discard uncommitted changes (no backup)'
+                                  ' also in subrepositories')),
           ('c', 'check', None, _('check for uncommitted changes')),
           ('d', 'date', '', _('tipmost revision matching date')),
           ('r', 'rev', '', _('revision'))],
diff -r 612c142b7a82 -r 55fdca7327f1 mercurial/hg.py
--- a/mercurial/hg.py	Wed Mar 03 22:32:51 2010 +0100
+++ b/mercurial/hg.py	Thu Mar 04 00:19:39 2010 +0100
@@ -367,9 +367,9 @@
 # naming conflict in clone()
 _update = update
 
-def clean(repo, node, show_stats=True):
+def clean(repo, node, show_stats=True, subrepo=False):
     """forcibly switch the working directory to node, clobbering changes"""
-    stats = _merge.update(repo, node, False, True, None)
+    stats = _merge.update(repo, node, False, True, None, subrepo)
     if show_stats:
         _showstats(repo, stats)
     return stats[3] > 0
diff -r 612c142b7a82 -r 55fdca7327f1 mercurial/merge.py
--- a/mercurial/merge.py	Wed Mar 03 22:32:51 2010 +0100
+++ b/mercurial/merge.py	Thu Mar 04 00:19:39 2010 +0100
@@ -117,7 +117,7 @@
 
     return action
 
-def manifestmerge(repo, p1, p2, pa, overwrite, partial):
+def manifestmerge(repo, p1, p2, pa, overwrite, partial, subrepo=False):
     """
     Merge p1 and p2 with ancestor ma and generate merge action list
 
@@ -186,6 +186,17 @@
             if n == m2[f] or m2[f] == a: # same or local newer
                 if m1.flags(f) != rflags:
                     act("update permissions", "e", f, rflags)
+                # in case of subrepos, update if overwrite and subrepos is dirty
+                if f == '.hgsubstate':
+                    for s in p1.substate:
+                        if p1.sub(s).dirty(): # if dirty, force update
+                            if subrepo and overwrite:
+                                act("remote is newer", "g", f, rflags)
+                            elif overwrite:
+                                raise util.Abort("subrepos have uncommitted"
+                                                 " changes, use 'hg update"
+                                                 " --subrepo -C' to overwrite\n")
+                            break
             elif n == a: # remote newer
                 act("remote is newer", "g", f, rflags)
             else: # both changed
@@ -406,7 +417,7 @@
                 if f:
                     repo.dirstate.forget(f)
 
-def update(repo, node, branchmerge, force, partial):
+def update(repo, node, branchmerge, force, partial, subrepo=False):
     """
     Perform a merge between the working directory and the given node
 
@@ -496,7 +507,8 @@
         if not util.checkcase(repo.path):
             _checkcollision(p2)
         action += _forgetremoved(wc, p2, branchmerge)
-        action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
+        action += manifestmerge(repo, wc, p2, pa, overwrite,
+                                partial, subrepo)
 
         ### apply phase
         if not branchmerge: # just jump to the new rev
diff -r 612c142b7a82 -r 55fdca7327f1 tests/test-subrepo
--- a/tests/test-subrepo	Wed Mar 03 22:32:51 2010 +0100
+++ b/tests/test-subrepo	Thu Mar 04 00:19:39 2010 +0100
@@ -207,4 +207,20 @@
     | "$TESTDIR/filtertmp.py"
 rm -rf mercurial mercurial2
 
+echo % test repositoy clean/overwrite updating
+hg init mercurial
+cd mercurial
+hg init nested
+echo test > nested/foo
+hg -R nested add nested/foo
+echo nested = nested > .hgsub
+hg add .hgsub
+hg ci -mtest
+echo modification > nested/foo
+hg -R nested commit -mmodif
+hg update -C
+hg update --subrepo -C
+cd ..
+rm -rf mercurial
+
 exit 0
diff -r 612c142b7a82 -r 55fdca7327f1 tests/test-subrepo.out
--- a/tests/test-subrepo.out	Wed Mar 03 22:32:51 2010 +0100
+++ b/tests/test-subrepo.out	Thu Mar 04 00:19:39 2010 +0100
@@ -266,3 +266,8 @@
 default = $HGTMP/test-subrepo/sub/mercurial/main/nested_absolute
 [paths]
 default = $HGTMP/test-subrepo/sub/mercurial/main/nested_relative
+% test repositoy clean/overwrite updating
+committing subrepository nested
+abort: subrepos have uncommitted changes, use 'hg update --subrepo -C' to overwrite
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved



More information about the Mercurial-devel mailing list