[cig-commits] commit: optionally walk .hg directories
Mercurial
hg at geodynamics.org
Mon Nov 24 11:26:56 PST 2008
changeset: 29:422907bd754f
user: Robin Farine <robin.farine at terminus.org>
date: Sat Dec 09 13:33:30 2006 +0100
files: forest.py test-forest test-forest.out
description:
optionally walk .hg directories
A configuration item and a command-line option let the user decide
whether to walk .hg directories or to skip them.
diff -r f0a9e7f6b7d1 -r 422907bd754f forest.py
--- a/forest.py Fri Dec 08 14:01:32 2006 +0100
+++ b/forest.py Sat Dec 09 13:33:30 2006 +0100
@@ -22,6 +22,18 @@ The 'fsnap' command generates or updates
The 'fsnap' command generates or updates such a file based on a forest
in the file system. Other commands use this information to populate a
forest or to pull/push changes.
+
+
+Configuration
+
+This extension recognizes the following item in the forest
+configuration section:
+
+walkhg = (0|1)
+
+ Whether repositories under a .hg directory should be skipped (0) or
+ not (1). The default value is 0. Some commands accept the --walkhg
+ command-line option to override the behavior selected by this item.
"""
import ConfigParser
@@ -44,9 +56,12 @@ def cmd_options(ui, cmd, remove=None):
return res
-def enumerate_repos(top=''):
+def enumerate_repos(ui, top='', **opts):
"""Generate a lexicographically sorted list of repository roots."""
+ walkhg = opts['walkhg']
+ if walkhg == 2:
+ walkhg = ui.configbool('forest', 'walkhg', 0)
dirs = ['.']
while dirs:
root = dirs.pop()
@@ -61,6 +76,8 @@ def enumerate_repos(top=''):
continue
if e == '.hg':
yield util.normpath(root)
+ if not walkhg:
+ continue
dirs.append(path)
@@ -166,7 +183,7 @@ class ForestSnapshot(object):
ui.write("\n")
- def update(self, ui, repo, tip):
+ def update(self, ui, repo, **opts):
"""Update a snapshot by scanning a forest.
If the ForestSnapshot instance to update was initialized from
@@ -178,12 +195,12 @@ class ForestSnapshot(object):
rootmap = {}
self.trees = []
- for root in enumerate_repos():
+ for root in enumerate_repos(ui, **opts):
if mq_patches_applied(root):
raise util.Abort(_("'%s' has mq patches applied") % root)
if root != '.':
repo = repository(ui, root)
- if tip:
+ if opts['tip']:
rev = 'tip'
else:
rev = node.hex(repo.dirstate.parents()[0])
@@ -213,7 +230,7 @@ def clone(ui, source, dest, **opts):
dest = os.path.normpath(dest)
opts['rev'] = []
roots = []
- for root in enumerate_repos(source):
+ for root in enumerate_repos(ui, source, **opts):
if root == '.':
srcpath = source
destpath = dest
@@ -304,8 +321,8 @@ def seed(ui, snapshot, pathalias='defaul
destpfx = os.path.dirname(dest)
if destpfx and not os.path.exists(destpfx):
os.makedirs(destpfx)
- # 'clone -r rev' not implemented for remote repos (<= 0.9), use
- # 'update' if necessary
+ # 'clone -r rev' not implemented for all remote repos, clone
+ # everything and then use 'update' if necessary
opts['rev'] = []
commands.clone(ui, source, dest, **opts)
if not opts['tip']:
@@ -321,14 +338,14 @@ def snapshot(ui, repo, snapfile=None, **
"""Generate a new or updated forest snapshot and display it."""
snapshot = ForestSnapshot(snapfile)
- snapshot.update(ui, repo, opts['tip'])
+ snapshot.update(ui, repo, **opts)
snapshot.write(ui)
def status(ui, repo, *pats, **opts):
"""Display the status of a forest of working directories."""
- for root in enumerate_repos():
+ for root in enumerate_repos(ui, **opts):
mqflag = ""
if mq_patches_applied(root):
mqflag = " *mq*"
@@ -338,19 +355,21 @@ def status(ui, repo, *pats, **opts):
ui.write("\n")
-def trees(ui, *unused):
+def trees(ui, *unused, **opts):
"""List the roots of the repositories."""
- for root in enumerate_repos():
+ for root in enumerate_repos(ui, '', **opts):
ui.write(root + '\n')
def uisetup(ui):
global cmdtable
+ walkhgopt = ('', 'walkhg', 2,
+ _("whether to walk (1) repositories under '.hg' or not (0)"))
cmdtable = {
"fclone" :
(clone,
- cmd_options(ui, 'clone', remove=('r',)),
+ [walkhgopt] + cmd_options(ui, 'clone', remove=('r',)),
_('hg fclone [OPTIONS] SOURCE DESTINATION')),
"fpull" :
(pull,
@@ -365,19 +384,20 @@ def uisetup(ui):
[('t', 'tip', None,
_("use tip instead of revisions stored in the snapshot file")),
('', 'root', '',
- _("create root as well as children under <root>"))] +
- cmd_options(ui, 'clone', remove=('r',)),
+ _("create root as well as children under <root>")),
+ walkhgopt] + cmd_options(ui, 'clone', remove=('r',)),
_('hg fseed [OPTIONS] SNAPSHOT-FILE [PATH-ALIAS]')),
"fsnap" :
(snapshot,
[('t', 'tip', None,
- _("record tip instead of actual child revisions"))],
- 'hg fsnap [SNAPSHOT-FILE]'),
+ _("record tip instead of actual child revisions")),
+ walkhgopt],
+ 'hg fsnap [OPTIONS] [SNAPSHOT-FILE]'),
"fstatus" :
(status,
- cmd_options(ui, 'status'),
+ [walkhgopt] + cmd_options(ui, 'status'),
_('hg fstatus [OPTIONS]')),
"ftrees" :
- (trees, [],
- 'hg ftrees'),
+ (trees, [walkhgopt],
+ 'hg ftrees [OPTIONS]'),
}
diff -r f0a9e7f6b7d1 -r 422907bd754f test-forest
--- a/test-forest Fri Dec 08 14:01:32 2006 +0100
+++ b/test-forest Sat Dec 09 13:33:30 2006 +0100
@@ -90,3 +90,15 @@ hg fpull --cwd topcopy -u ../top-snap de
echo "# fpush + mq"
hg fpush --cwd topcopy ../top-snap default | sed "s@$HGTMP at HGTMP@g"
+
+echo "# walk **/.hg"
+hg init walkhg
+hg init walkhg/.hg/h
+hg init walkhg/a
+hg init walkhg/a/.hg/h
+hg ftrees --cwd walkhg
+hg ftrees --cwd walkhg --walkhg=1
+echo "[forest]" >> walkhg/.hg/hgrc
+echo "walkhg = 1" >> walkhg/.hg/hgrc
+hg ftrees --cwd walkhg
+hg ftrees --cwd walkhg --walkhg=0
diff -r f0a9e7f6b7d1 -r 422907bd754f test-forest.out
--- a/test-forest.out Fri Dec 08 14:01:32 2006 +0100
+++ b/test-forest.out Sat Dec 09 13:33:30 2006 +0100
@@ -212,3 +212,16 @@ searching for changes
searching for changes
no changes found
+# walk **/.hg
+.
+a
+.
+.hg/h
+a
+a/.hg/h
+.
+.hg/h
+a
+a/.hg/h
+.
+a
More information about the CIG-COMMITS
mailing list