[cig-commits] commit: `hg fupdate` now behaves much like `hg update`

Mercurial hg at geodynamics.org
Mon Nov 24 11:27:12 PST 2008


changeset:   69:cb22e7675abc
user:        Simon Law <simon at akoha.org>
date:        Mon Aug 27 13:50:49 2007 -0400
files:       forest.py test-forest test-forest.out
description:
`hg fupdate` now behaves much like `hg update`


diff -r 00cc9acdcf3e -r cb22e7675abc forest.py
--- a/forest.py	Mon Aug 27 13:49:23 2007 -0400
+++ b/forest.py	Mon Aug 27 13:50:49 2007 -0400
@@ -737,69 +737,6 @@ class Forest(object):
         return ("<forest.Forest object - trees: %s> ") % self.trees
 
 
-class ForestSnapshot(object):
-
-    __slots__ = ('forest')
-
-    def __init__(self, snapfile=None):
-        self.forest = Forest(snapfile=snapfile)
-
-    def __call__(self, ui, toprepo, func, pathalias=None, mq_check=True):
-        """Apply a function to trees matching a snapshot entry.
-
-        Call func(repo, root, path, rev, mq_applied) for each repo in
-        toprepo and its nested repositories where repo matches a
-        snapshot entry.
-        """
-        if self.forest.snapfile:
-            self.forest = Forest(snapfile=self.forest.snapfile,
-                                 top=toprepo)
-            self.forest.update(ui)
-        pfx = toprepo.url()
-        for t in self.forest.trees:
-            root = relpath(self.forest.top().root, t.root)
-            ui.status("[%s]\n" % root)
-            path = t.paths.get(pathalias, None)
-            if pathalias is not None and path is None:
-                ui.warn(_("skipped, no path alias '%s' defined\n\n")
-                         % pathalias)
-                continue
-            if not t.repo:
-                ui.warn(_("skipped, no valid repo found\n\n"))
-            rev = None
-            if t.revs:
-                rev = t.revs[0]
-            func(t.repo, root, path, rev, (mq_check and t.mq_applied()))
-            ui.status("\n")
-
-
-    def update(self, ui, repo, mq_fatal, walkhg='', tip=False):
-        """Update a snapshot by scanning a forest.
-
-        If the ForestSnapshot instance to update was initialized from
-        a snapshot file, this regenerates the list of trees with their
-        current revisions but does not add any path alias to updated
-        tree entries. Newly created tree entries get all the path aliases
-        from the corresponding repository.
-        """
-
-        if self.forest.top():
-            self.forest.update(ui)
-        else:
-            if repo:
-                self.forest = Forest(top=repo)
-            self.forest.scan(walkhg)
-        if mq_fatal or not tip:
-            for tree in self.forest.trees:
-                if mq_fatal:
-                    tree.die_on_mq(self.forest.top())
-                if not tip:
-                    tree.revs = tree.working_revs()
-
-    def write(self, ui):
-        self.forest.write(ui, oldstyle=True)
-
-
 def qclone(ui, source, sroot, dest, rpath, opts):
     """Helper function to clone from a remote repository.
 
@@ -1134,32 +1071,58 @@ def trees(ui, top, **opts):
             ui.write("%s\n" % util.localpath(tree.root))
 
 
-def update(ui, toprepo, snapfile=None, tip=False, walkhg='', **opts):
-    """Update working directories to tip or according to a snapshot file.
-
-    When the tip option is specified, the working directory of the
-    toplevel repository and of each nested repository found in the
-    local filesystem is updated to its tip. When a snapshot file is
-    specified, the working directory of each repository listed in the
-    snapshot file is updated to the revision recorded in the snapshot.
-
-    The tip option or the snapshot file are exclusive.
-    """
-    if snapfile is not None and tip or snapfile is None and not tip:
-        raise util.Abort(_("need either --tip or SNAPSHOT-FILE"))
-    if tip:
-        snapshot = ForestSnapshot()
-        snapshot.update(ui, toprepo, False, walkhgenabled(ui, walkhg), True)
-    else:
-        snapshot = ForestSnapshot(snapfile)
-
-    def doit(repo, root, path, rev, mq_applied):
-        if mq_applied:
-            ui.write(_("skipped, mq patches applied\n"))
-        else:
-            commands.update(repo.ui, repo, node=rev, **opts)
-
-    snapshot(ui, toprepo, doit)
+def update(ui, top, revision=None, **opts):
+    """update working forest
+
+    Update the working forest to the specified revision, or the
+    tip of the current branch if none is specified.
+
+    You may specify a snapshot file, which is generated by the fsnap
+    command.  For each tree in this file, update to the revision
+    recorded for that tree.
+
+    Look at the help text for the update command for more information.
+    """
+
+    snapfile = None
+    if revision:
+        cp = ConfigParser.RawConfigParser()
+        try:
+            if cp.read([revision]):
+                # Compatibility with old 'hg fupdate SNAPFILE' syntax
+                snapfile = revision
+        except Exception, err:
+            if isinstance(err, ConfigParser.Error):
+                ui.warn(_("warning: %s\n") % err)
+            else:
+                raise err
+            snapfile = opts['snapfile']
+            opts['rev'] = revision
+    tip = opts['tip']
+    forest = Forest(top=top, snapfile=snapfile,
+                    walkhg=walkhgenabled(ui, opts['walkhg']))
+
+    def function(tree, ignore, opts):
+        rev = opts['rev']
+        if type(rev) is str:
+            rev = rev
+        elif rev:
+            rev = rev[0]
+        else:
+            rev = None
+        try:
+            commands.update(ui, tree.getrepo(ui),
+                            rev=rev, clean=opts['clean'], date=opts['date'])
+        except Exception, err:
+            ui.warn(_("skipped: %s\n") % err)
+            tree.repo.transaction().__del__()
+
+    @Forest.Tree.skip
+    def check_mq(tree):
+        tree.die_on_mq(top.root)
+
+    forest.apply(ui, function, None, opts,
+                 prehooks=[lambda tree: check_mq(tree)])
 
 
 cmdtable = None
@@ -1211,13 +1174,14 @@ def uisetup(ui):
                _("convert paths to mercurial representation")),
               walkhgopts],
              _('hg ftrees [OPTIONS]')),
-        "fupdate" :
+        "^fupdate|fup|fcheckout|fco" :
             (update,
-             [('', 'tip', False,
-               _("update working directories to a specified revision")),
+             [snapfileopts,
+              ('', 'tip', False,
+               _("use tip instead of revisions stored in the snapshot file")),
               walkhgopts]
-             + cmd_options(ui, 'update', remove=('d',)),
-             _('hg fupdate [OPTIONS] (--tip | SNAPSHOT-FILE)'))
+             + cmd_options(ui, 'update'),
+             _('hg fupdate [OPTION]...'))
         }
 
 commands.norepo += " fclone fseed"
diff -r 00cc9acdcf3e -r cb22e7675abc test-forest
--- a/test-forest	Mon Aug 27 13:49:23 2007 -0400
+++ b/test-forest	Mon Aug 27 13:50:49 2007 -0400
@@ -58,10 +58,23 @@ diff -u top-snap1 top-snap2 | \
 
 echo "# fupdate"
 hg fclone toplevel newtop > /dev/null
-hg fupdate -R newtop top-snap > /dev/null
+hg fupdate -R newtop top-snap
 hg parents --cwd newtop/d/d/t
 hg parents --cwd newtop/t/t
-hg fupdate --cwd newtop --tip > /dev/null
+hg fupdate --cwd newtop --tip
+hg update --cwd newtop 0
+hg update --cwd newtop/t/t 0
+hg fupdate --cwd newtop
+hg update --cwd newtop 0
+hg update --cwd newtop/t/t 0
+hg fupdate --cwd newtop --rev tip
+hg update --cwd newtop 0
+hg update --cwd newtop/t/t 0
+hg fupdate --cwd newtop tip
+hg update --cwd newtop 0
+hg update --cwd newtop/t/t 0
+rm -f newtop/f newtop/t/t/f
+hg fupdate --cwd newtop -C
 hg parents --cwd newtop/d/d/t
 hg parents --cwd newtop/t/t
 rm -rf newtop
@@ -151,6 +164,9 @@ hg fpush --cwd topcopy ../top-snap defau
 hg fpush --cwd topcopy ../top-snap default 2>&1 \
     | sed "s@\(/private\)*$HGTMP at HGTMP@g"
 
+echo "# fupdate + mq"
+hg fupdate --cwd topcopy
+
 echo "# walk **/.hg"
 hg init walkhg
 hg init walkhg/.hg/h
diff -r 00cc9acdcf3e -r cb22e7675abc test-forest.out
--- a/test-forest.out	Mon Aug 27 13:49:23 2007 -0400
+++ b/test-forest.out	Mon Aug 27 13:50:49 2007 -0400
@@ -71,6 +71,21 @@ adding d/d/f2
 +revision = e7ef7301b2ddca4eca0c4e80fe0cc8c943d05645
  
 # fupdate
+[.]
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
 changeset:   0:11d08ba64b67
 tag:         tip
 user:        test
@@ -82,6 +97,89 @@ date:        Thu Jan 01 00:00:00 1970 +0
 date:        Thu Jan 01 00:00:00 1970 +0000
 summary:     start
 
+[.]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[.]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[.]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[.]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+[.]
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
 changeset:   0:11d08ba64b67
 tag:         tip
 user:        test
@@ -570,6 +668,25 @@ skipped: 't' has mq patches applied
 [t/t]
 skipped: 't/t' has mq patches applied
 
+# fupdate + mq
+[.]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+skipped: 't' has mq patches applied
+
+[t/t]
+skipped: 't/t' has mq patches applied
+
+[t/t/.hg/patches]
+skipped: branch default not found
+
 # walk **/.hg
 .
 a



More information about the CIG-COMMITS mailing list