Mercurial > hg > hgforest
changeset 32:8732cc34aea6
filesystem vs mercurial path representation
author | Robin Farine <robin.farine@terminus.org> |
---|---|
date | Sun, 17 Dec 2006 17:09:27 +0100 |
parents | bfb2a805b490 |
children | 54ab5a322cac |
files | forest.py test-forest |
diffstat | 2 files changed, 47 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/forest.py Sun Dec 17 15:34:50 2006 +0100 +++ b/forest.py Sun Dec 17 17:09:27 2006 +0100 @@ -5,6 +5,13 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. +# Repository path representation +# +# Repository paths stored in the filesystem representation are stored +# in variables named 'rpath'. Repository roots in the mercurial +# representation, stored in variables named 'root', are used in +# snapshot files and in command output. + """Operations on trees with nested Mercurial repositories. This extension provides commands that apply to a composite tree called @@ -63,11 +70,11 @@ dirs.append(path) -def mq_patches_applied(rootpath): - rootpath = os.path.join(rootpath, ".hg") - entries = os.listdir(rootpath) +def mq_patches_applied(rpath): + rpath = os.path.join(rpath, ".hg") + entries = os.listdir(rpath) for e in entries: - path = os.path.join(rootpath, e) + path = os.path.join(rpath, e) if e == "data" or not os.path.isdir(path): continue series = os.path.join(path, "series") @@ -78,13 +85,14 @@ return True return False -def repository(ui, root): - while os.path.islink(root): - path = os.readlink(root) + +def repository(ui, rpath): + while os.path.islink(rpath): + path = os.readlink(rpath) if not os.path.isabs(path): - path = os.path.join(os.path.dirname(root), path) - root = path - return hg.repository(ui, root) + path = os.path.join(os.path.dirname(rpath), path) + rpath = path + return hg.repository(ui, rpath) class ForestSnapshot(object): @@ -154,7 +162,7 @@ repo = toprepo else: try: - repo = repository(ui, root) + repo = repository(ui, util.localpath(root)) except RepoError: ui.write(_("skipped, no valid repo found\n\n")) continue @@ -177,11 +185,12 @@ rootmap = {} self.trees = [] - for root in enumerate_repos(ui): - if mq_patches_applied(root): + for rpath in enumerate_repos(ui): + root = util.pconvert(rpath) + if mq_patches_applied(rpath): raise util.Abort(_("'%s' has mq patches applied") % root) - if root != '.': - repo = repository(ui, root) + if rpath != '.': + repo = repository(ui, rpath) if opts['tip']: rev = 'tip' else: @@ -212,22 +221,23 @@ dest = os.path.normpath(dest) opts['rev'] = [] roots = [] - for root in enumerate_repos(ui, source): - if root == '.': + for rpath in enumerate_repos(ui, source): + if rpath == '.': srcpath = source destpath = dest else: - subdir = util.localpath(root) + subdir = rpath srcpath = os.path.join(source, subdir) destpath = os.path.join(dest, subdir) if mq_patches_applied(srcpath): - raise util.Abort(_("'%s' has mq patches applied") % root) - roots.append((root, srcpath, destpath)) + raise util.Abort( + _("'%s' has mq patches applied") % util.pconvert(rpath)) + roots.append((rpath, srcpath, destpath)) for root in roots: destpfx = os.path.dirname(root[2]) if destpfx and not os.path.exists(destpfx): os.makedirs(destpfx) - ui.write("[%s]\n" % root[0]) + ui.write("[%s]\n" % util.pconvert(root[0])) commands.clone(ui, root[1], root[2], **opts) ui.write("\n") @@ -327,12 +337,12 @@ def status(ui, repo, *pats, **opts): """Display the status of a forest of working directories.""" - for root in enumerate_repos(ui): + for rpath in enumerate_repos(ui): mqflag = "" - if mq_patches_applied(root): + if mq_patches_applied(rpath): mqflag = " *mq*" - ui.write("[%s]%s\n" % (root, mqflag)) - repo = repository(ui, root) + ui.write("[%s]%s\n" % (util.pconvert(rpath), mqflag)) + repo = repository(ui, rpath) commands.status(repo.ui, repo, *pats, **opts) ui.write("\n") @@ -340,8 +350,12 @@ def trees(ui, *unused, **opts): """List the roots of the repositories.""" - for root in enumerate_repos(ui, ''): - ui.write(root + '\n') + if opts['convert']: + l = [util.pconvert(p) for p in enumerate_repos(ui)] + else: + l = enumerate_repos(ui) + for t in l: + ui.write(t + '\n') def uisetup(ui): @@ -371,12 +385,14 @@ (snapshot, [('t', 'tip', None, _("record tip instead of actual child revisions"))], - 'hg fsnap [OPTIONS] [SNAPSHOT-FILE]'), + _('hg fsnap [OPTIONS] [SNAPSHOT-FILE]')), "fstatus" : (status, cmd_options(ui, 'status'), _('hg fstatus [OPTIONS]')), "ftrees" : - (trees, '', - 'hg ftrees [OPTIONS]'), + (trees, + [('c', 'convert', None, + _("convert paths to mercurial representation"))], + _('hg ftrees [OPTIONS]')) }