changeset 37:44e66014dd8d

new fupdate command The fupdate command updates working directories to tip or according to a snapshot file.
author Robin Farine <robin.farine@terminus.org>
date Thu, 21 Dec 2006 16:51:24 +0100
parents 01a10f7bd85c
children b29f327bdc10
files forest.py test-forest test-forest.out
diffstat 3 files changed, 71 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/forest.py	Thu Dec 21 15:05:23 2006 +0100
+++ b/forest.py	Thu Dec 21 16:51:24 2006 +0100
@@ -159,7 +159,7 @@
                 self.rootmap[root] = tree
                 self.trees.append(tree)
 
-    def __call__(self, ui, toprepo, func, pathalias):
+    def __call__(self, ui, toprepo, func, pathalias=None):
         """Apply a function to trees matching a snapshot entry.
 
         Call func(repo, rev, path) for each repo in toprepo and its
@@ -170,7 +170,7 @@
         for t in self.trees:
             root, rev, path = t.info(pathalias)
             ui.write("[%s]\n" % root)
-            if path is None:
+            if pathalias is not None and path is None:
                 ui.write(_("skipped, no path alias '%s' defined\n\n")
                          % pathalias)
                 continue
@@ -363,6 +363,34 @@
     for t in l:
         ui.write(t + '\n')
 
+def update(ui, toprepo, snapfile=None, tip=False, **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:
+        for rpath in enumerate_repos(ui):
+            repo = repository(ui, rpath)
+            ui.write("[%s]\n" % util.pconvert(rpath))
+            commands.update(repo.ui, repo, node='tip', **opts)
+            ui.write("\n")
+    else:
+
+        def doit(repo, path, rev):
+            commands.update(repo.ui, repo, node=rev, **opts)
+
+        snapshot = ForestSnapshot(snapfile)
+        snapshot(ui, toprepo, doit)
+
 
 def uisetup(ui):
     global cmdtable
@@ -400,5 +428,11 @@
             (trees,
              [('c', 'convert', None,
                _("convert paths to mercurial representation"))],
-             _('hg ftrees [OPTIONS]'))
+             _('hg ftrees [OPTIONS]')),
+        "fupdate" :
+            (update,
+             [('', 'tip', False,
+               _("update working directories to a specified revision"))]
+             + cmd_options(ui, 'update', remove=('d',)),
+             _('hg fupdate (--tip | SNAPSHOT-FILE)'))
         }
--- a/test-forest	Thu Dec 21 15:05:23 2006 +0100
+++ b/test-forest	Thu Dec 21 16:51:24 2006 +0100
@@ -54,6 +54,16 @@
     sed -e 's/--- top-snap1.*$/--- top-snap1/' \
         -e 's/+++ top-snap2.*$/+++ top-snap2/'
 
+echo "# fupdate"
+hg fclone toplevel newtop > /dev/null
+hg fupdate --cwd newtop ../top-snap > /dev/null
+hg parents --cwd newtop/d/d/t
+hg parents --cwd newtop/t/t
+hg fupdate --cwd newtop --tip > /dev/null
+hg parents --cwd newtop/d/d/t
+hg parents --cwd newtop/t/t
+rm -rf newtop
+
 echo "# fseed"
 hg clone toplevel newtop
 hg fseed --cwd newtop ../top-snap default
--- a/test-forest.out	Thu Dec 21 15:05:23 2006 +0100
+++ b/test-forest.out	Thu Dec 21 16:51:24 2006 +0100
@@ -72,6 +72,30 @@
  
  [tree5.paths]
  
+# fupdate
+changeset:   0:11d08ba64b67
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     start
+
+changeset:   0:5d60830890a2
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     start
+
+changeset:   0:11d08ba64b67
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     start
+
+changeset:   1:e7ef7301b2dd
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     new line
+
 # fseed
 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
 [d/d/t]