mirror of
https://github.com/frej/fast-export.git
synced 2026-01-19 12:42:04 +01:00
Add head2branch plugin
Support converting unnamed heads to named branches during mercurial conversions. Co-Authored-By: ostan89@gmail.com
This commit is contained in:
committed by
Ondrej Stanek
parent
5c1cbf82b0
commit
21827a53f7
@@ -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
|
||||
|
||||
12
plugins/head2branch/README.md
Normal file
12
plugins/head2branch/README.md
Normal 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.
|
||||
23
plugins/head2branch/__init__.py
Normal file
23
plugins/head2branch/__init__.py
Normal 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()
|
||||
Reference in New Issue
Block a user