# HG changeset patch # User Simon Law # Date 1188237049 14400 # Node ID cb22e7675abc39d702a95c0f10b278e19961f19c # Parent 00cc9acdcf3e113668d48bdb2c9744e1a5a740f7 `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 @@ return (" ") % 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 @@ 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. +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. - 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. + 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. - The tip option or the snapshot file are exclusive. + Look at the help text for the update command for more information. """ - 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) + + 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 doit(repo, root, path, rev, mq_applied): - if mq_applied: - ui.write(_("skipped, mq patches applied\n")) + def function(tree, ignore, opts): + rev = opts['rev'] + if type(rev) is str: + rev = rev + elif rev: + rev = rev[0] else: - commands.update(repo.ui, repo, node=rev, **opts) + 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__() - snapshot(ui, toprepo, doit) + @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 @@ _("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 @@ 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 default 2>&1 \ | sed "s@\(/private\)*$HGTMP@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 @@ +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 +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 @@ [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