summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Usov <oleksandr.usov@tibra.com>2011-10-12 12:20:53 +0100
committerOleksandr Usov <oleksandr.usov@tibra.com>2011-10-12 12:20:53 +0100
commit503d62deb715d7a14d8c12073c22180f087f828b (patch)
tree7a830cb972030f0c071fe681d8e022cb31ead729
parent02fe09a21d1548b901fede6f90434c6455cc675b (diff)
downloadbzr-fastimport-503d62deb715d7a14d8c12073c22180f087f828b.tar.gz
Rewrite tag names when exporting plain stream
-rw-r--r--cmds.py12
-rw-r--r--exporter.py20
2 files changed, 26 insertions, 6 deletions
diff --git a/cmds.py b/cmds.py
index 537e0f0..362113e 100644
--- a/cmds.py
+++ b/cmds.py
@@ -578,6 +578,10 @@ class cmd_fast_export(Command):
future once the feature names and definitions are formally agreed
to by the broader fast-import developer community.
+ Git has much stricter naming rules for tags and fast-export --plain
+ will skip tags which can't be imported into git. If you want to rename
+ these tags use --rewrite-tag-names.
+
:Examples:
To produce data destined for import into Bazaar::
@@ -624,12 +628,15 @@ class cmd_fast_export(Command):
Option('plain',
help="Exclude metadata to maximise interoperability."
),
+ Option('rewrite-tag-names',
+ help="Rewrite invalid tag names in plain mode."
+ ),
]
encoding_type = 'exact'
def run(self, source, destination=None, verbose=False,
git_branch="master", checkpoint=10000, marks=None,
import_marks=None, export_marks=None, revision=None,
- plain=True):
+ plain=True, rewrite_tag_names=False):
load_fastimport()
from bzrlib.plugins.fastimport import exporter
@@ -639,7 +646,8 @@ class cmd_fast_export(Command):
destination=destination,
git_branch=git_branch, checkpoint=checkpoint,
import_marks_file=import_marks, export_marks_file=export_marks,
- revision=revision, verbose=verbose, plain_format=plain)
+ revision=revision, verbose=verbose, plain_format=plain,
+ rewrite_tags=rewrite_tag_names)
return exporter.run()
diff --git a/exporter.py b/exporter.py
index e67a621..fd1de00 100644
--- a/exporter.py
+++ b/exporter.py
@@ -152,13 +152,17 @@ class BzrFastExporter(object):
def __init__(self, source, destination, git_branch=None, checkpoint=-1,
import_marks_file=None, export_marks_file=None, revision=None,
- verbose=False, plain_format=False):
+ verbose=False, plain_format=False, rewrite_tags=False):
"""Export branch data in fast import format.
:param plain_format: if True, 'classic' fast-import format is
used without any extended features; if False, the generated
data is richer and includes information like multiple
authors, revision properties, etc.
+
+ :param rewrite_tags: if True tag names will be rewritten to be
+ git-compatible. Otherwise tags which aren't valid for git will
+ be skiped.
"""
self.source = source
self.outf = _get_output_stream(destination)
@@ -169,6 +173,8 @@ class BzrFastExporter(object):
self.revision = revision
self.excluded_revisions = set()
self.plain_format = plain_format
+ self.rewrite_tags = rewrite_tags
+ self.rewrite_dict = dict()
self._multi_author_api_available = hasattr(bzrlib.revision.Revision,
'get_apparent_authors')
self.properties_to_exclude = ['authors', 'author']
@@ -594,9 +600,15 @@ class BzrFastExporter(object):
else:
git_ref = 'refs/tags/%s' % tag.encode("utf-8")
if self.plain_format and not check_ref_format(git_ref):
- self.warning('not creating tag %r as its name would not be '
- 'valid in git.', git_ref)
- continue
+ if self.rewrite_tags:
+ new_ref = sanitize_ref_name_for_git(self.rewrite_dict, git_ref)
+ self.warning('tag %r is exported as %r to be valid in git.',
+ git_ref, new_ref)
+ git_ref = new_ref
+ else:
+ self.warning('not creating tag %r as its name would not be '
+ 'valid in git.', git_ref)
+ continue
self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))
def _next_tmp_branch_name(self):