# HG changeset patch # User Simon Law # Date 1188236586 14400 # Node ID 95a1f9aab6abf6b512977ffb40822aedf04266d3 # Parent 5d770477eb1a6b6370c289cb4bd08e518b6da099 `hg fpull` now behaves much like `hg pull` diff -r 5d770477eb1a -r 95a1f9aab6ab forest.py --- a/forest.py Mon Aug 27 13:40:21 2007 -0400 +++ b/forest.py Mon Aug 27 13:43:06 2007 -0400 @@ -563,6 +563,8 @@ self.read(snapfile, toppath) elif top: self.trees.append(Forest.Tree(repo=top)) + if top.ui: + top.ui.note(_("searching for repos in %s\n") % top.root) self.scan(walkhg) def apply(self, ui, function, paths, opts, prehooks=[]): @@ -863,29 +865,86 @@ ui.status("\n") -def pull(ui, toprepo, snapfile, pathalias, **opts): - """Pull changes from remote repositories to a local forest. +def pull(ui, top, source="default", pathalias=None, **opts): + """pull changes from the specified forest + + Pull changes from a remote forest to a local one. - Iterate over the entries in the snapshot file and, for each entry - matching an actual tree in the forest and with a location - associated with 'pathalias', pull changes from this location to - the tree. + You may specify a snapshot file, which is generated by the fsnap + command. For each tree in this file, pull the specified revision + from the specified source path. - Skip entries that do not match or trees for which there is no entry. + Look at the help text for the pull command for more information. """ - opts['force'] = None - opts['rev'] = [] + die_on_numeric_revs(opts['rev']) + if pathalias: + # Compatibility with old 'hg fpull SNAPFILE PATH-ALIAS' syntax + snapfile = source + source = pathalias + else: + snapfile = opts['snapfile'] + source = [source] + walkhg = walkhgenabled(ui, opts['walkhg']) + forest = Forest(top=top, snapfile=snapfile, walkhg=walkhg) + if not snapfile: + # Look for new remote paths from source + srcrepo = hg.repository(ui, forest.top().getpath(source)) + newrepos = [util.localpath(root) for root in srcrepo.forests(walkhg)] + toproot = forest.top().root + for tree in forest.trees: + try: + newrepos.remove(relpath(toproot, tree.root)) + except Exception, err: + pass + forest.trees.extend([Forest.Tree(root=os.path.join(toproot, new)) + for new in newrepos]) + forest.trees.sort(key=(lambda tree: tree.root)) + opts['pull'] = True + opts['uncompressed'] = None + opts['noupdate'] = not opts['update'] - def doit(repo, root, path, rev, mq_applied): - if mq_applied: - ui.write(_("skipped, mq patches applied\n")) + def function(tree, srcpath, opts): + if snapfile: + opts['rev'] = tree.revs else: - commands.pull(repo.ui, repo, path, **opts) + destpath = relpath(os.path.abspath(os.curdir), tree.root) + rpath = util.pconvert(relpath(toproot, tree.root)) + if not srcpath: + srcpath = forest.top().getpath(source) + if srcpath: + srcpath = '/'.join((srcpath, rpath)) + else: + ui.warn(_("warning: %s\n") % + _("repository %s not found") % source[0]) + try: + tree.getrepo(ui) + except RepoError: + # Need to clone + quiet = ui.quiet + try: + ui.quiet = True # Hack to shut up qclone's ui.status() + qclone(ui=ui, + source=srcpath, sroot=source, + dest=destpath, rpath=rpath, + opts=opts) + except util.Abort, err: + ui.warn(_("skipped: %s\n") % err) + ui.quiet = quiet + return + try: + commands.pull(ui, tree.getrepo(ui), srcpath, **opts) + except Exception, err: + ui.warn(_("skipped: %s\n") % err) + if tree._repo: + tree.repo.transaction().__del__() - snapshot = ForestSnapshot(snapfile) - snapshot(ui, toprepo, doit, pathalias) + @Forest.Tree.skip + def check_mq(tree): + tree.die_on_mq(top.root) + forest.apply(ui, function, source, opts, + prehooks=[lambda tree: check_mq(tree)]) def push(ui, toprepo, snapfile, pathalias, **opts): """Push changes in a local forest to remote destinations. @@ -1009,16 +1068,18 @@ def uisetup(ui): global cmdtable walkhgopts = ('', 'walkhg', '', - _("walk repositories under '.hg' (yes/no)")) + _("walk repositories under '.hg' (yes/no)")) + snapfileopts = ('', 'snapfile', '', + _("snapshot file generated by fsnap")) cmdtable = { "^fclone" : (clone, [walkhgopts] + cmd_options(ui, 'clone'), _('hg fclone [OPTION]... SOURCE [DEST]')), - "fpull" : + "^fpull" : (pull, - cmd_options(ui, 'pull', remove=('f', 'r')), - _('hg fpull [OPTIONS] SNAPSHOT-FILE PATH-ALIAS')), + [walkhgopts, snapfileopts] + cmd_options(ui, 'pull', remove=('f',)), + _('hg fpull [OPTION]... [SOURCE]')), "fpush" : (push, cmd_options(ui, 'push', remove=('f', 'r')), diff -r 5d770477eb1a -r 95a1f9aab6ab test-forest --- a/test-forest Mon Aug 27 13:40:21 2007 -0400 +++ b/test-forest Mon Aug 27 13:43:06 2007 -0400 @@ -75,7 +75,13 @@ rm -rf newtop echo "# fpull" -hg fpull --cwd topcopy -u ../top-snap default \ +hg fpull --cwd topcopy -u --snapfile=../top-snap default 2>&1 \ + | sed "s@\(/private\)*$HGTMP@HGTMP@g" +hg fpull --cwd topcopy -u ../top-snap default 2>&1 \ + | sed "s@\(/private\)*$HGTMP@HGTMP@g" +# Simulate a new repository +rm -rf topcopy/t +hg fpull -R topcopy -u 2>&1 \ | sed "s@\(/private\)*$HGTMP@HGTMP@g" echo "# fpush" @@ -98,7 +104,7 @@ hg fseed --cwd missing ../top-snap-missing default hg ftrees -R missing --convert # pull (should find toplevel changesets) -hg fpull -R missing top-snap-missing default \ +hg fpull -R missing top-snap-missing default 2>&1 \ | sed "s@\(/private\)*$HGTMP@HGTMP@g" rm -rf missing @@ -137,7 +143,7 @@ hg fsnap --cwd topcopy ../top-snap1 echo "# fpull + mq" -hg fpull --cwd topcopy -u ../top-snap default \ +hg fpull --cwd topcopy -u ../top-snap default 2>&1 \ | sed "s@\(/private\)*$HGTMP@HGTMP@g" echo "# fpush + mq" diff -r 5d770477eb1a -r 95a1f9aab6ab test-forest.out --- a/test-forest.out Mon Aug 27 13:40:21 2007 -0400 +++ b/test-forest.out Mon Aug 27 13:43:06 2007 -0400 @@ -154,10 +154,9 @@ pulling from HGTMP/test-forest/toplevel searching for changes adding changesets -adding manifests -adding file changes -added 1 changesets with 1 changes to 1 files -1 files updated, 0 files merged, 0 files removed, 0 files unresolved +transaction abort! +rollback completed +skipped: received changelog group is empty [d/d/t] pulling from HGTMP/test-forest/toplevel/d/d/t @@ -178,11 +177,76 @@ pulling from HGTMP/test-forest/toplevel/t/t searching for changes adding changesets +transaction abort! +rollback completed +skipped: received changelog group is empty + +[.] +pulling from HGTMP/test-forest/toplevel +searching for changes +adding changesets +transaction abort! +rollback completed +skipped: received changelog group is empty + +[d/d/t] +pulling from HGTMP/test-forest/toplevel/d/d/t +searching for changes +no changes found + +[e/d] +pulling from HGTMP/test-forest/toplevel/e/d +searching for changes +no changes found + +[t] +pulling from HGTMP/test-forest/toplevel/t +searching for changes +no changes found + +[t/t] +pulling from HGTMP/test-forest/toplevel/t/t +searching for changes +adding changesets +transaction abort! +rollback completed +skipped: received changelog group is empty + +[.] +pulling from HGTMP/test-forest/toplevel +searching for changes +adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files 1 files updated, 0 files merged, 0 files removed, 0 files unresolved +[d/d/t] +pulling from HGTMP/test-forest/toplevel/d/d/t +searching for changes +no changes found + +[e/d] +pulling from HGTMP/test-forest/toplevel/e/d +searching for changes +no changes found + +[t] +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved + +[t/t] +requesting all changes +adding changesets +adding manifests +adding file changes +added 2 changesets with 2 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved + # fpush [.] pushing to HGTMP/test-forest/toplevel @@ -258,7 +322,7 @@ adding changesets adding manifests adding file changes -added 3 changesets with 4 changes to 4 files +added 1 changesets with 3 changes to 3 files (run 'hg update' to get a working copy) [e/d] @@ -383,10 +447,10 @@ no changes found [t] -skipped, mq patches applied +skipped: 't' has mq patches applied [t/t] -skipped, mq patches applied +skipped: 't/t' has mq patches applied # fpush + mq [.]