Add head2branch plugin

Support converting unnamed heads to named branches during mercurial
conversions.

Co-Authored-By:	ostan89@gmail.com
This commit is contained in:
Ethan Furman
2019-11-13 16:19:19 -08:00
committed by Ondrej Stanek
parent 5c1cbf82b0
commit 21827a53f7
3 changed files with 37 additions and 0 deletions

View File

@@ -201,6 +201,8 @@ exactly one head each. Otherwise commits to the tip of these heads
within the branch will get flattened into merge commits. Chris J
Billington's [hg-export-tool] can help you to handle branches with
duplicate heads.
Alternatively, you can use the [head2branch plugin](./plugins/head2branch)
to create a new named branch from an unnamed head.
hg-fast-export will ignore any files or directories tracked by mercurial
called `.git`, and will print a warning if it encounters one. Git cannot

View File

@@ -0,0 +1,12 @@
## Convert Head to Branch
`fast-export` can only handle one head per branch. This plugin makes it possible
to create a new branch from a head by specifying the new branch name and
the first divergent commit for that head. The revision number for the commit
should be in decimal form.
Note: you must run `fast-export` with `--ignore-unnamed-heads` option,
otherwise, the conversion will fail.
To use the plugin, add the command line flag `--plugin head2branch=name,<rev>`.
The flag can be given multiple times to name more than one head.

View File

@@ -0,0 +1,23 @@
import sys
def build_filter(args):
return Filter(args)
class Filter:
def __init__(self, args):
args = args.split(',')
self.branch_name = args[0]
self.starting_commit = int(args[1])
self.branch_parents = set()
def commit_message_filter(self, commit_data):
rev = commit_data['revision']
rev_parents = commit_data['parents']
if (rev == self.starting_commit
or any(rp in self.branch_parents for rp in rev_parents)
):
self.branch_parents.add(rev)
commit_data['branch'] = self.branch_name.encode('ascii', 'replace')
sys.stderr.write('\nchanging r%s to branch %r\n' % (rev, self.branch_name))
sys.stderr.flush()