From a7955bc49b710c48789e3a52e566da895454d8ed Mon Sep 17 00:00:00 2001 From: Ondrej Stanek Date: Fri, 31 Jul 2020 10:38:24 +0200 Subject: [PATCH] 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. --- plugins/head2branch/README.md | 7 ++++--- plugins/head2branch/__init__.py | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/head2branch/README.md b/plugins/head2branch/README.md index 495166f..932d98d 100644 --- a/plugins/head2branch/README.md +++ b/plugins/head2branch/README.md @@ -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,`. +To use the plugin, add the command line flag `--plugin head2branch=name,`. The flag can be given multiple times to name more than one head. diff --git a/plugins/head2branch/__init__.py b/plugins/head2branch/__init__.py index 54e6785..3ee9f40 100644 --- a/plugins/head2branch/__init__.py +++ b/plugins/head2branch/__init__.py @@ -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()