convert: some tidyups, doc improvements, and test fixes

The various back end options are now documented.
The hg source can now be configured not to hand out a revision ID.
This commit is contained in:
Bryan O'Sullivan 2007-11-27 09:44:09 -08:00
parent a364fef5fb
commit 314630c85c
11 changed files with 75 additions and 27 deletions

View File

@ -332,6 +332,24 @@ def convert(ui, src, dest=None, revmapfile=None, **opts):
The 'rename' directive renames a file or directory. To rename from a
subdirectory into the root of the repository, use '.' as the path to
rename to.
Back end options:
--config convert.hg.clonebranches=False (boolean)
hg target: XXX not documented
--config convert.hg.saverev=True (boolean)
hg source: allow target to preserve source revision ID
--config convert.hg.tagsbranch=default (branch name)
hg target: XXX not documented
--config convert.hg.usebranchnames=True (boolean)
hg target: preserve branch names
--config convert.svn.branches=branches (directory name)
svn source: specify the directory containing branches
--config convert.svn.tags=tags (directory name)
svn source: specify the directory containing tags
--config convert.svn.trunk=trunk (directory name)
svn source: specify the name of the trunk branch
"""
util._encoding = 'UTF-8'

View File

@ -40,7 +40,7 @@ class commit(object):
class converter_source(object):
"""Conversion source interface"""
def __init__(self, ui, path, rev=None):
def __init__(self, ui, path=None, rev=None):
"""Initialize conversion source (or raise NoRepo("message")
exception if path is not a valid repository)"""
self.ui = ui

View File

@ -7,7 +7,7 @@
import shlex
from mercurial.i18n import _
from mercurial import util
from common import SKIPREV
from common import SKIPREV, converter_source
def rpairs(name):
e = len(name)
@ -110,9 +110,9 @@ class filemapper(object):
# touch files we're interested in, but also merges that merge two
# or more interesting revisions.
class filemap_source(object):
class filemap_source(converter_source):
def __init__(self, ui, baseconverter, filemap):
self.ui = ui
super(filemap_source, self).__init__(ui)
self.base = baseconverter
self.filemapper = filemapper(ui, filemap)
self.commits = {}
@ -344,9 +344,3 @@ class filemap_source(object):
def gettags(self):
return self.base.gettags()
def before(self):
pass
def after(self):
pass

View File

@ -1,10 +1,16 @@
# hg backend for convert extension
# Note for hg->hg conversion: Old versions of Mercurial didn't trim
# the whitespace from the ends of commit messages, but new versions
# do. Changesets created by those older versions, then converted, may
# thus have different hashes for changesets that are otherwise
# identical.
# Notes for hg->hg conversion:
#
# * Old versions of Mercurial didn't trim the whitespace from the ends
# of commit messages, but new versions do. Changesets created by
# those older versions, then converted, may thus have different
# hashes for changesets that are otherwise identical.
#
# * By default, the source revision is stored in the converted
# revision. This will cause the converted revision to have a
# different identity than the source. To avoid this, use the
# following option: "--config convert.hg.saverev=false"
import os, time
@ -181,6 +187,7 @@ class mercurial_sink(converter_sink):
class mercurial_source(converter_source):
def __init__(self, ui, path, rev=None):
converter_source.__init__(self, ui, path, rev)
self.saverev = ui.configbool('convert', 'hg.saverev', True)
try:
self.repo = hg.repository(self.ui, path)
# try to provoke an exception if this isn't really a hg
@ -239,8 +246,12 @@ class mercurial_source(converter_source):
def getcommit(self, rev):
ctx = self.changectx(rev)
parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid]
if self.saverev:
crev = rev
else:
crev = None
return commit(author=ctx.user(), date=util.datestr(ctx.date()),
desc=ctx.description(), rev=rev, parents=parents,
desc=ctx.description(), rev=crev, parents=parents,
branch=ctx.branch(), extra=ctx.extra())
def gettags(self):

View File

@ -1,7 +1,11 @@
#!/bin/sh
echo "[extensions]" >> $HGRCPATH
echo "convert=" >> $HGRCPATH
cat >> $HGRCPATH <<EOF
[extensions]
convert=
[convert]
hg.saverev=False
EOF
hg help convert

View File

@ -44,7 +44,6 @@ c
checking in src/a,v
checking in src/b/c,v
% convert again
destination src-hg is a Mercurial repository
connecting to cvsrepo
scanning source...
sorting...
@ -56,7 +55,6 @@ c
c
c
% convert again with --filemap
destination src-filemap is a Mercurial repository
connecting to cvsrepo
scanning source...
sorting...

View File

@ -1,7 +1,11 @@
#!/bin/sh
echo "[extensions]" >> $HGRCPATH
echo "hgext.convert=" >> $HGRCPATH
cat >> $HGRCPATH <<EOF
[extensions]
convert=
[convert]
hg.saverev=False
EOF
hg init orig
cd orig

View File

@ -37,7 +37,6 @@ no changes found
a 0 -1 unset baz
copy: bar -> baz
% add a new revision in the original repo
destination new is a Mercurial repository
scanning source...
sorting...
converting...

View File

@ -1,7 +1,11 @@
#!/bin/sh
echo "[extensions]" >> $HGRCPATH
echo "hgext.convert=" >> $HGRCPATH
cat >> $HGRCPATH <<EOF
[extensions]
convert=
[convert]
hg.saverev=False
EOF
hg init orig
cd orig

View File

@ -25,7 +25,6 @@ Transmitting file data ..
Committed revision 3.
% test incremental conversion
assuming destination trunk-hg
destination trunk-hg is a Mercurial repository
scanning source...
sorting...
converting...
@ -86,7 +85,6 @@ Sending letter2.txt
Transmitting file data .
Committed revision 11.
% test incremental conversion
destination A-hg is a Mercurial repository
scanning source...
sorting...
converting...

View File

@ -55,6 +55,24 @@ Convert a foreign SCM repository to a Mercurial one.
subdirectory into the root of the repository, use '.' as the path to
rename to.
Back end options:
--config convert.hg.clonebranches=False (boolean)
hg target: XXX not documented
--config convert.hg.saverev=True (boolean)
hg source: allow target to preserve source revision ID
--config convert.hg.tagsbranch=default (branch name)
hg target: XXX not documented
--config convert.hg.usebranchnames=True (boolean)
hg target: preserve branch names
--config convert.svn.branches=branches (directory name)
svn source: specify the directory containing branches
--config convert.svn.tags=tags (directory name)
svn source: specify the directory containing tags
--config convert.svn.trunk=trunk (directory name)
svn source: specify the name of the trunk branch
options:
-A --authors username mapping filename