From ea12de8b05226cf24aa6edb8b99415157a901b10 Mon Sep 17 00:00:00 2001 From: Andy Grimm Date: Mon, 21 Nov 2011 18:07:40 -0500 Subject: Add --baseline option --- cmds.py | 18 ++++++++++++++++-- exporter.py | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cmds.py b/cmds.py index 7e20a1d..a92e326 100644 --- a/cmds.py +++ b/cmds.py @@ -606,6 +606,16 @@ class cmd_fast_export(Command): unsupported in git with an underscore instead, specify --rewrite-tag-names. + :History truncation: + + When code has been significantly refactored over time (e.g., to separate + proprietary code from open source code), it is sometimes convenient to + simply truncate the revision history at a certain point. The --baseline + option, to be used in conjunction with -r, emits a baseline commit + containing the state of the entire source tree immediately prior to the + first requested revision. This allows a user to produce a tree identical + to the original without munging multiple exports. + :Examples: To produce data destined for import into Bazaar:: @@ -656,12 +666,16 @@ class cmd_fast_export(Command): help="Replace characters invalid in git with '_'" " (plain mode only).", ), + Option('baseline', + help="Export an 'abolute' baseline commit prior to" + "the first relative commit", + ), ] 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, rewrite_tag_names=False): + plain=True, rewrite_tag_names=False, baseline=False): load_fastimport() from bzrlib.branch import Branch from bzrlib.plugins.fastimport import exporter @@ -676,7 +690,7 @@ class cmd_fast_export(Command): outf=outf, git_branch=git_branch, checkpoint=checkpoint, import_marks_file=import_marks, export_marks_file=export_marks, revision=revision, verbose=verbose, plain_format=plain, - rewrite_tags=rewrite_tag_names) + rewrite_tags=rewrite_tag_names, baseline=baseline) return exporter.run() diff --git a/exporter.py b/exporter.py index e4b5132..b5c6651 100644 --- a/exporter.py +++ b/exporter.py @@ -148,7 +148,8 @@ class BzrFastExporter(object): def __init__(self, source, outf, git_branch=None, checkpoint=-1, import_marks_file=None, export_marks_file=None, revision=None, - verbose=False, plain_format=False, rewrite_tags=False): + verbose=False, plain_format=False, rewrite_tags=False, + baseline=False): """Export branch data in fast import format. :param plain_format: if True, 'classic' fast-import format is @@ -170,6 +171,7 @@ class BzrFastExporter(object): self.excluded_revisions = set() self.plain_format = plain_format self.rewrite_tags = rewrite_tags + self.baseline = baseline self._multi_author_api_available = hasattr(bzrlib.revision.Revision, 'get_apparent_authors') self.properties_to_exclude = ['authors', 'author'] @@ -225,6 +227,9 @@ class BzrFastExporter(object): self._commit_total) if not self.plain_format: self.emit_features() + if self.baseline: + self._commit_total += 1 + self.emit_baseline(interesting[0], self.git_branch) for revid in interesting: self.emit_commit(revid, self.git_branch) if self.branch.supports_tags(): @@ -302,6 +307,19 @@ class BzrFastExporter(object): for feature in sorted(commands.FEATURE_NAMES): self.print_cmd(commands.FeatureCommand(feature)) + def emit_baseline(self, revid, git_branch): + # Emit a full source tree of the first commit's parent + git_ref = 'refs/heads/%s' % (git_branch,) + revobj = self.branch.repository.get_revision(revid) + assert(len(revobj.parent_ids)) + previd = revobj.parent_ids[0] + prevobj = self.branch.repository.get_revision(previd) + mark = 1 + self.revid_to_mark[previd] = mark + file_cmds = self._get_filecommands(bzrlib.revision.NULL_REVISION, previd) + self.print_cmd(self._get_commit_command(git_ref, mark, prevobj, + file_cmds)) + def emit_commit(self, revid, git_branch): if revid in self.revid_to_mark or revid in self.excluded_revisions: return -- cgit v1.2.1