[cig-commits] commit: `hg fpull` now behaves much like `hg pull`
Mercurial
hg at geodynamics.org
Mon Nov 24 11:27:10 PST 2008
changeset: 63:95a1f9aab6ab
user: Simon Law <simon at akoha.org>
date: Mon Aug 27 13:43:06 2007 -0400
files: forest.py test-forest test-forest.out
description:
`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 @@ class Forest(object):
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 @@ def clone(ui, source, dest=None, **opts)
ui.status("\n")
-def pull(ui, toprepo, snapfile, pathalias, **opts):
- """Pull changes from remote repositories to a local forest.
-
- 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.
-
- Skip entries that do not match or trees for which there is no entry.
- """
-
- opts['force'] = None
- opts['rev'] = []
-
- def doit(repo, root, path, rev, mq_applied):
- if mq_applied:
- ui.write(_("skipped, mq patches applied\n"))
+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.
+
+ 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.
+
+ Look at the help text for the pull command for more information.
+ """
+
+ 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 function(tree, srcpath, opts):
+ if snapfile:
+ opts['rev'] = tree.revs
else:
- commands.pull(repo.ui, repo, path, **opts)
-
- snapshot = ForestSnapshot(snapfile)
- snapshot(ui, toprepo, doit, pathalias)
-
+ 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__()
+
+ @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):
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
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 at HGTMP@g"
+hg fpull --cwd topcopy -u ../top-snap default 2>&1 \
+ | sed "s@\(/private\)*$HGTMP at HGTMP@g"
+# Simulate a new repository
+rm -rf topcopy/t
+hg fpull -R topcopy -u 2>&1 \
| sed "s@\(/private\)*$HGTMP at HGTMP@g"
echo "# fpush"
@@ -98,7 +104,7 @@ hg fseed --cwd missing ../top-snap-missi
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 at HGTMP@g"
rm -rf missing
@@ -137,7 +143,7 @@ hg fsnap --cwd topcopy ../top-snap1
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 at 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,6 +154,68 @@ pulling from HGTMP/test-forest/toplevel
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
+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
@@ -170,17 +232,19 @@ no changes found
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
+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
@@ -258,7 +322,7 @@ adding changesets
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
no changes found
[t]
-skipped, mq patches applied
-
-[t/t]
-skipped, mq patches applied
+skipped: 't' has mq patches applied
+
+[t/t]
+skipped: 't/t' has mq patches applied
# fpush + mq
[.]
More information about the CIG-COMMITS
mailing list