Mercurial > hg > hgforest
changeset 29:422907bd754f
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.
author | Robin Farine <robin.farine@terminus.org> |
---|---|
date | Sat, 09 Dec 2006 13:33:30 +0100 |
parents | f0a9e7f6b7d1 |
children | ddf24d7eb625 |
files | forest.py test-forest test-forest.out |
diffstat | 3 files changed, 64 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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 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 @@ 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 @@ continue if e == '.hg': yield util.normpath(root) + if not walkhg: + continue dirs.append(path) @@ -166,7 +183,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ """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 @@ 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 @@ [('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]'), }
--- 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 @@ echo "# fpush + mq" hg fpush --cwd topcopy ../top-snap default | sed "s@$HGTMP@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