|
--- fastimport/exporter.py.dist 2017-10-26 09:00:36.375185796 -0400 |
|
+++ fastimport/exporter.py 2017-12-18 12:28:39.386484215 -0500 |
|
@@ -57,6 +57,7 @@ |
|
progress, |
|
trace, |
|
) |
|
+from bzrlib.log import _compute_revno_str |
|
|
|
from bzrlib.plugins.fastimport import ( |
|
helpers, |
|
@@ -425,7 +426,70 @@ |
|
# Filter the revision properties. Some metadata (like the |
|
# author information) is already exposed in other ways so |
|
# don't repeat it here. |
|
+ addlines = [] |
|
+ message = revobj.message.encode("utf-8") |
|
+ fixed_bugs = [] |
|
+ if b'\nLP: ' in message: |
|
+ # Join any old LP: # in the bzr commit message to avoid duplicate |
|
+ lines = [] |
|
+ for line in message.splitlines(): |
|
+ if not line.startswith(b'LP: '): |
|
+ lines.append(line) |
|
+ continue |
|
+ replace_line = True |
|
+ linebugs = [] |
|
+ for tok in line.split(): |
|
+ if tok == b'LP:': |
|
+ continue |
|
+ tok = tok.replace(b"#", "").replace(b",", "") |
|
+ try: |
|
+ int(tok) |
|
+ linebugs.append(tok) |
|
+ except ValueError as e: |
|
+ sys.stderr.write( |
|
+ "WARNING: failed to parse '%s': %s\n" % (tok, line)) |
|
+ replace_line = False |
|
+ break |
|
+ if replace_line: |
|
+ fixed_bugs.extend(linebugs) |
|
+ else: |
|
+ lines.append(line) |
|
+ if fixed_bugs: |
|
+ sys.stderr.write( |
|
+ "UPDATED: adjusted existing bzr LP: for %s\n" % fixed_bugs) |
|
+ message = b'\n'.join(lines) |
|
+ if fixed_bugs: |
|
+ message = message.rstrip(b'\n') + b'\n' |
|
+ |
|
if self.plain_format: |
|
+ if 'bugs' in revobj.properties: |
|
+ # properties are a newline separated list of: bugurl action |
|
+ # http://bugs.launchpad.net/bug/XXXXX fixed |
|
+ for bugstatement in revobj.properties["bugs"].split("\n"): |
|
+ bugurl, comment = bugstatement.decode().split() |
|
+ if not bugurl.startswith("https://launchpad.net/bugs/"): |
|
+ sys.stderr.write("unknown bug url: %s\n" % bugurl) |
|
+ continue |
|
+ if comment == "fixed": |
|
+ n = bugurl.rpartition("/")[2] |
|
+ fixed_bugs.append(bugurl.rpartition("/")[2]) |
|
+ |
|
+ # append to the message with LP: #XXX[, #XXX] |
|
+ if fixed_bugs: |
|
+ fixed_bugs = sorted(set(fixed_bugs)) |
|
+ addlines.append( |
|
+ "LP: %s" % ', '.join(["#" + n for n in fixed_bugs])) |
|
+ |
|
+ if 'authors' in revobj.properties: |
|
+ authors = revobj.properties['authors'].split('\n') |
|
+ if len(authors) > 1: |
|
+ addlines.append("Original authors:") |
|
+ addlines.extend([" - " + author for author in authors]) |
|
+ |
|
+ revno = _compute_revno_str(self.branch, revobj.revision_id) |
|
+ if revno is not None: |
|
+ addlines.append("bzr-revno: %s" % revno) |
|
+ |
|
properties = None |
|
else: |
|
properties = revobj.properties |
|
@@ -435,9 +499,14 @@ |
|
except KeyError: |
|
pass |
|
|
|
+ if addlines: |
|
+ if message[-1] != b"\n": |
|
+ message += b"\n" |
|
+ message = '\n'.join( |
|
+ [message] + [a.encode("utf-8") for a in addlines]) |
|
# Build and return the result |
|
return commands.CommitCommand(git_ref, str(mark), author_info, |
|
- committer_info, revobj.message.encode("utf-8"), from_, merges, iter(file_cmds), |
|
+ committer_info, message, from_, merges, iter(file_cmds), |
|
more_authors=more_author_info, properties=properties) |
|
|
|
def _get_revision_trees(self, parent, revision_id): |
See also: my version of a bzr2git script (currently also a snap of the same name, but I'm willing to give it up if others want to maintain it). This supports iterative transitions, if you don't want a "flag day". But doesn't support bug metadata (or any bzr metadata, for that matter).