Update head2branch plugin to accept hg commit hash

The revision number isn't a unique identifier of commits across
repository clones and forks, while the hg hash is guaranteed to be stable.
This commit is contained in:
Ondrej Stanek
2020-07-31 10:38:24 +02:00
parent 9c6dea9fd4
commit a7955bc49b
2 changed files with 9 additions and 7 deletions

View File

@@ -2,11 +2,12 @@
`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.
the first divergent commit for that head.
Note: the hg hash must be in the full form, 40 hexadecimal characters.
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>`.
To use the plugin, add the command line flag `--plugin head2branch=name,<hg_hash>`.
The flag can be given multiple times to name more than one head.

View File

@@ -7,17 +7,18 @@ class Filter:
def __init__(self, args):
args = args.split(',')
self.branch_name = args[0]
self.starting_commit = int(args[1])
self.branch_name = args[0].encode('ascii', 'replace')
self.starting_commit_hash = args[1].encode('ascii', 'strict')
self.branch_parents = set()
def commit_message_filter(self, commit_data):
hg_hash = commit_data['hg_hash']
rev = commit_data['revision']
rev_parents = commit_data['parents']
if (rev == self.starting_commit
if (hg_hash == self.starting_commit_hash
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')
commit_data['branch'] = self.branch_name
sys.stderr.write('\nchanging r%s to branch %r\n' % (rev, self.branch_name))
sys.stderr.flush()