Mercurial > hg > hgforest
changeset 44:3a2665d193d0
restore support for repositories under .hg
This change set adds the 'walkhg' configuration and command-line
option back. This option directs the relevant forest commands to
handle or to ignore repositories *directly* under a .hg directory,
e.g. mq patch repositories.
author | Robin Farine <robin.farine@terminus.org> |
---|---|
date | Thu, 11 Jan 2007 15:38:21 +0100 |
parents | 60036a82c3c4 |
children | c00f4879211c |
files | forest.py test-forest test-forest.out |
diffstat | 3 files changed, 93 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/forest.py Wed Jan 10 11:10:12 2007 +0100 +++ b/forest.py Thu Jan 11 15:38:21 2007 +0100 @@ -29,6 +29,19 @@ 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|no|false|1|yes|true) + + Whether repositories directly under a .hg directory should be + skipped (0|no|false) or not (1|yes|true). The default value is 0. + Some commands accept the --walkhg command-line option to override + the behavior selected by this item. """ import ConfigParser @@ -51,8 +64,18 @@ res = [opt for opt in res if opt[0] not in remove] return res +def walkhgenabled(ui, walkhg): + if walkhg == '': + walkhg = ui.config('forest', 'walkhg', 'false') + try: + res = { '0' : False, 'false' : False, 'no' : False, + '1' : True, 'true' : True, 'yes' : True }[walkhg.lower()] + except KeyError: + raise util.Abort(_("invalid value for 'walkhg': %s" % walkhg)) + return res -def enumerate_repos(ui, top): + +def enumerate_repos(ui, top, walkhg): """Generate a lexicographically sorted list of repository roots. Return a list of roots in filesystem representation. @@ -75,6 +98,13 @@ p = os.path.join(root, d) if os.path.islink(p): paths.append(p) + if walkhg: + for root in list(res): + hgroot = os.path.join(root, '.hg') + for e in os.listdir(hgroot): + path = os.path.join(hgroot, e) + if os.path.isdir(os.path.join(path, '.hg')): + res.append(path) res.sort() return res @@ -190,7 +220,7 @@ ui.write("\n") - def update(self, ui, repo, mq_fatal, tip=False): + 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 @@ -203,7 +233,7 @@ rootmap = {} self.trees = [] pfxlen = len(repo.root + os.sep) - for rpath in enumerate_repos(ui, repo.root): + for rpath in enumerate_repos(ui, repo.root, walkhg): root = util.pconvert(rpath[pfxlen:]) if root == '': root = '.' @@ -235,7 +265,7 @@ index += 1 -def clone(ui, source, dest, **opts): +def clone(ui, source, dest, walkhg, **opts): """Clone a local forest.""" dest = os.path.normpath(dest) @@ -252,7 +282,7 @@ snapshot = ForestSnapshot() repo = hg.repository(ui, source) - snapshot.update(ui, repo, True) + snapshot.update(ui, repo, True, walkhgenabled(ui, walkhg)) snapshot(ui, repo, doit, mq_check=False) @@ -304,12 +334,12 @@ snapshot(ui, toprepo, doit, pathalias) -def seed(ui, snapshot, pathalias='default', **opts): +def seed(ui, snapshot, pathalias='default', root='', tip=False, **opts): """Populate a forest according to a snapshot file.""" cfg = ConfigParser.RawConfigParser() cfg.read(snapshot) - pfx = opts['root'] + pfx = root for section in tree_sections(cfg, bool(pfx)): root = cfg.get(section, 'root') ui.write("[%s]\n" % root) @@ -329,7 +359,7 @@ # everything and then use 'update' if necessary opts['rev'] = [] commands.clone(ui, source, dest, **opts) - if not opts['tip']: + if not tip: rev = cfg.get(section, 'revision') if rev and rev != 'tip' and rev != node.nullid: repo = hg.repository(ui, dest) @@ -337,15 +367,15 @@ ui.write("\n") -def snapshot(ui, repo, snapfile=None, **opts): +def snapshot(ui, repo, snapfile=None, tip=False, walkhg='', **opts): """Generate a new or updated forest snapshot and display it.""" snapshot = ForestSnapshot(snapfile) - snapshot.update(ui, repo, True, **opts) + snapshot.update(ui, repo, True, walkhgenabled(ui, walkhg), tip) snapshot.write(ui) -def status(ui, repo, *pats, **opts): +def status(ui, repo, walkhg='', *pats, **opts): """Display the status of a forest of working directories.""" def doit(repo, root, path, rev, mq_applied): @@ -354,24 +384,26 @@ commands.status(repo.ui, repo, *pats, **opts) snapshot = ForestSnapshot() - snapshot.update(ui, repo, False) + snapshot.update(ui, repo, False, walkhgenabled(ui, walkhg)) snapshot(ui, repo, doit) -def trees(ui, repo, **opts): +def trees(ui, repo, convert=False, walkhg='', **opts): """List the roots of the repositories.""" - if opts['convert']: + walkhg = walkhgenabled(ui, walkhg) + if convert: pfxlen = len(repo.root + os.sep) - l = [util.pconvert(p[pfxlen:]) for p in enumerate_repos(ui, repo.root)] + l = [util.pconvert(p[pfxlen:]) + for p in enumerate_repos(ui, repo.root, walkhg)] l.remove('') l.insert(0, '.') else: - l = enumerate_repos(ui, repo.root) + l = enumerate_repos(ui, repo.root, walkhg) for t in l: ui.write(t + '\n') -def update(ui, toprepo, snapfile=None, tip=False, **opts): +def update(ui, toprepo, snapfile=None, tip=False, walkhg='', **opts): """Update working directories to tip or according to a snapshot file. When the tip option is specified, the working directory of the @@ -382,12 +414,11 @@ The tip option or the snapshot file are exclusive. """ - 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, True) + snapshot.update(ui, toprepo, False, walkhgenabled(ui, walkhg), True) else: snapshot = ForestSnapshot(snapfile) @@ -402,10 +433,13 @@ def uisetup(ui): global cmdtable + walkhgopt = ('', 'walkhg', '', + _("whether to walk (1|yes|true) repositories under '.hg' or " + "not (0|no|false)")) cmdtable = { "fclone" : (clone, - cmd_options(ui, 'clone', remove=('r',)), + [walkhgopt] + cmd_options(ui, 'clone', remove=('r',)), _('hg fclone [OPTIONS] SOURCE DESTINATION')), "fpull" : (pull, @@ -417,30 +451,33 @@ _('hg fpush [OPTIONS] SNAPSHOT-FILE PATH-ALIAS')), "fseed" : (seed, - [('t', 'tip', None, - _("use tip instead of revisions stored in the snapshot file")), - ('', 'root', '', - _("create root as well as children under <root>"))] + [('', 'root', '', + _("create root as well as children under <root>")), + ('t', 'tip', False, + _("use tip instead of revisions stored in the snapshot file"))] + 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"))], + [('t', 'tip', False, + _("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, - [('c', 'convert', None, - _("convert paths to mercurial representation"))], + [('c', 'convert', False, + _("convert paths to mercurial representation")), + walkhgopt], _('hg ftrees [OPTIONS]')), "fupdate" : (update, [('', 'tip', False, - _("update working directories to a specified revision"))] + _("update working directories to a specified revision")), + walkhgopt] + cmd_options(ui, 'update', remove=('d',)), - _('hg fupdate (--tip | SNAPSHOT-FILE)')) + _('hg fupdate [OPTIONS] (--tip | SNAPSHOT-FILE)')) }
--- a/test-forest Wed Jan 10 11:10:12 2007 +0100 +++ b/test-forest Thu Jan 11 15:38:21 2007 +0100 @@ -131,3 +131,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 --convert +hg ftrees -R walkhg --convert --walkhg=1 +echo "[forest]" >> walkhg/.hg/hgrc +echo "walkhg = Yes" >> walkhg/.hg/hgrc +hg ftrees -R walkhg --convert +hg ftrees --cwd walkhg --convert --walkhg=FALSE