mirror of
https://github.com/frej/fast-export.git
synced 2026-05-07 04:37:40 +02:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
667404e836 | ||
|
|
38e236962d | ||
|
|
dbb8158527 | ||
|
|
bb0bcda7ba | ||
|
|
838b654614 | ||
|
|
f179afce65 | ||
|
|
5b7ca5aaec | ||
|
|
4227621eed | ||
|
|
bdfc0c08c7 | ||
|
|
001749e69d | ||
|
|
20c22a3110 | ||
|
|
f741bf39f2 | ||
|
|
427663c766 | ||
|
|
056756f193 | ||
|
|
588e03bb23 | ||
|
|
89da4ad8af |
28
.github/contributing.md
vendored
Normal file
28
.github/contributing.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
When submitting a patch make sure the commits in your pull request:
|
||||||
|
|
||||||
|
* Have good commit messages
|
||||||
|
|
||||||
|
Please read Chris Beams' blog post [How to Write a Git Commit
|
||||||
|
Message](https://chris.beams.io/posts/git-commit/) on how to write a
|
||||||
|
good commit message. Although the article recommends at most 50
|
||||||
|
characters for the subject, up to 72 characters are frequently
|
||||||
|
accepted for fast-export.
|
||||||
|
|
||||||
|
* Adhere to good [commit
|
||||||
|
hygiene](http://www.ericbmerritt.com/2011/09/21/commit-hygiene-and-git.html)
|
||||||
|
|
||||||
|
When developing a pull request for hg-fast-export, base your work on
|
||||||
|
the current `master` branch and rebase your work if it no longer can
|
||||||
|
be merged into the current `master` without conflicts. Never merge
|
||||||
|
`master` into your development branch, rebase if your work needs
|
||||||
|
updates from `master`.
|
||||||
|
|
||||||
|
When a pull request is modified due to review feedback, please
|
||||||
|
incorporate the changes into the proper commit. A good reference on
|
||||||
|
how to modify history is in the [Pro Git book, Section
|
||||||
|
7.6](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History).
|
||||||
|
|
||||||
|
Please do not submit a pull request if you are not willing to spend
|
||||||
|
the time required to address review comments or revise the patch until
|
||||||
|
it follows the guidelines above. A _take it or leave it_ approach to
|
||||||
|
contributing wastes both your and the maintainer's time.
|
||||||
@@ -27,10 +27,10 @@ command line option.
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Example mercurial repo folder structure (~/mercurial):
|
Example mercurial repo folder structure (~/mercurial) containing two subrepos:
|
||||||
src/...
|
src/...
|
||||||
subrepo/subrepo1
|
subrepos/subrepo1
|
||||||
subrepo/subrepo2
|
subrepos/subrepo2
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
Create an empty new folder where all the converted git modules will be imported:
|
Create an empty new folder where all the converted git modules will be imported:
|
||||||
@@ -41,18 +41,18 @@ Create an empty new folder where all the converted git modules will be imported:
|
|||||||
mkdir submodule1
|
mkdir submodule1
|
||||||
cd submodule1
|
cd submodule1
|
||||||
git init
|
git init
|
||||||
hg-fast-export.sh -r ~/mercurial/subrepo1
|
hg-fast-export.sh -r ~/mercurial/subrepos/subrepo1
|
||||||
cd ..
|
cd ..
|
||||||
mkdir submodule2
|
mkdir submodule2
|
||||||
cd submodule2
|
cd submodule2
|
||||||
git init
|
git init
|
||||||
hg-fast-export.sh -r ~/mercurial/subrepo2
|
hg-fast-export.sh -r ~/mercurial/subrepos/subrepo2
|
||||||
|
|
||||||
### Create mapping file
|
### Create mapping file
|
||||||
cd ~/imported-gits
|
cd ~/imported-gits
|
||||||
cat > submodule-mappings << EOF
|
cat > submodule-mappings << EOF
|
||||||
"subrepo/subrepo1"="../submodule1"
|
"subrepos/subrepo1"="../submodule1"
|
||||||
"subrepo/subrepo2"="../submodule2"
|
"subrepos/subrepo2"="../submodule2"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
### Convert main repository
|
### Convert main repository
|
||||||
@@ -60,16 +60,16 @@ Create an empty new folder where all the converted git modules will be imported:
|
|||||||
mkdir git-main-repo
|
mkdir git-main-repo
|
||||||
cd git-main-repo
|
cd git-main-repo
|
||||||
git init
|
git init
|
||||||
hg-fast-export.sh -r ~/mercurial --subrepo-map=../submodule-mappings
|
hg-fast-export.sh -r ~/mercurial --subrepo-map=~/imported-gits/submodule-mappings
|
||||||
|
|
||||||
### Result
|
### Result
|
||||||
The resulting repository will now contain the subrepo/subrepo1 and
|
The resulting repository will now contain the submodules at the paths
|
||||||
subrepo/subrepo1 submodules. The created .gitmodules file will look
|
`subrepos/subrepo1` and `subrepos/subrepo2`. The created .gitmodules
|
||||||
like:
|
file will look like:
|
||||||
|
|
||||||
[submodule "subrepo/subrepo1"]
|
[submodule "subrepos/subrepo1"]
|
||||||
path = subrepo/subrepo1
|
path = subrepos/subrepo1
|
||||||
url = ../submodule1
|
url = ../submodule1
|
||||||
[submodule "subrepo/subrepo2"]
|
[submodule "subrepos/subrepo2"]
|
||||||
path = subrepo/subrepo2
|
path = subrepos/subrepo2
|
||||||
url = ../submodule2
|
url = ../submodule2
|
||||||
|
|||||||
38
README.md
38
README.md
@@ -1,4 +1,4 @@
|
|||||||
hg-fast-export.(sh|py) - mercurial to git converter using git-fast-import
|
hg-fast-export.sh - mercurial to git converter using git-fast-import
|
||||||
=========================================================================
|
=========================================================================
|
||||||
|
|
||||||
Legal
|
Legal
|
||||||
@@ -133,7 +133,10 @@ is to convert line endings in text files from CRLF to git's preferred LF:
|
|||||||
# $2 = Mercurial's hash of the file
|
# $2 = Mercurial's hash of the file
|
||||||
# $3 = "1" if Mercurial reports the file as binary, otherwise "0"
|
# $3 = "1" if Mercurial reports the file as binary, otherwise "0"
|
||||||
|
|
||||||
if [ "$3" == "1" ]; then cat; else dos2unix; fi
|
if [ "$3" == "1" ]; then cat; else dos2unix -q; fi
|
||||||
|
# -q option in call to dos2unix allows to avoid returning an
|
||||||
|
# error code when handling non-ascii based text files (like UTF-16
|
||||||
|
# encoded text files)
|
||||||
-- End of crlf-filter.sh --
|
-- End of crlf-filter.sh --
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ defined filter methods in the [dos2unix](./plugins/dos2unix) and
|
|||||||
[branch_name_in_commit](./plugins/branch_name_in_commit) plugins.
|
[branch_name_in_commit](./plugins/branch_name_in_commit) plugins.
|
||||||
|
|
||||||
```
|
```
|
||||||
commit_data = {'branch': branch, 'parents': parents, 'author': author, 'desc': desc, 'revision': revision, 'hg_hash': hg_hash, 'committer': 'committer'}
|
commit_data = {'branch': branch, 'parents': parents, 'author': author, 'desc': desc, 'revision': revision, 'hg_hash': hg_hash, 'committer': 'committer', 'extra': extra}
|
||||||
|
|
||||||
def commit_message_filter(self,commit_data):
|
def commit_message_filter(self,commit_data):
|
||||||
```
|
```
|
||||||
@@ -198,11 +201,15 @@ Notes/Limitations
|
|||||||
|
|
||||||
hg-fast-export supports multiple branches but only named branches with
|
hg-fast-export supports multiple branches but only named branches with
|
||||||
exactly one head each. Otherwise commits to the tip of these heads
|
exactly one head each. Otherwise commits to the tip of these heads
|
||||||
within the branch will get flattened into merge commits. Chris J
|
within the branch will get flattened into merge commits. There are a
|
||||||
Billington's [hg-export-tool] can help you to handle branches with
|
few options to deal with this:
|
||||||
duplicate heads.
|
1. Chris J Billington's [hg-export-tool] can help you to handle branches with
|
||||||
Alternatively, you can use the [head2branch plugin](./plugins/head2branch)
|
duplicate heads.
|
||||||
to create a new named branch from an unnamed head.
|
2. Use the [head2branch plugin](./plugins/head2branch) to create a new named
|
||||||
|
branch from an unnamed head.
|
||||||
|
3. You can ignore unnamed heads with the `-ignore-unnamed-heads` option, which
|
||||||
|
is appropriate in situations such as the extra heads being close commits
|
||||||
|
(abandoned, unmerged changes).
|
||||||
|
|
||||||
hg-fast-export will ignore any files or directories tracked by mercurial
|
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
|
called `.git`, and will print a warning if it encounters one. Git cannot
|
||||||
@@ -221,8 +228,8 @@ possible to use hg-fast-export on remote repositories
|
|||||||
Design
|
Design
|
||||||
------
|
------
|
||||||
|
|
||||||
hg-fast-export.py was designed in a way that doesn't require a 2-pass
|
hg-fast-export was designed in a way that doesn't require a 2-pass
|
||||||
mechanism or any prior repository analysis: if just feeds what it
|
mechanism or any prior repository analysis: it just feeds what it
|
||||||
finds into git-fast-import. This also implies that it heavily relies
|
finds into git-fast-import. This also implies that it heavily relies
|
||||||
on strictly linear ordering of changesets from hg, i.e. its
|
on strictly linear ordering of changesets from hg, i.e. its
|
||||||
append-only storage model so that changesets hg-fast-export already
|
append-only storage model so that changesets hg-fast-export already
|
||||||
@@ -258,6 +265,10 @@ hygiene](http://www.ericbmerritt.com/2011/09/21/commit-hygiene-and-git.html)
|
|||||||
how to modify history is in the [Pro Git book, Section
|
how to modify history is in the [Pro Git book, Section
|
||||||
7.6](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History).
|
7.6](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History).
|
||||||
|
|
||||||
|
Please do not submit a pull request if you are not willing to spend
|
||||||
|
the time required to address review comments or revise the patch until
|
||||||
|
it follows the guidelines above. A _take it or leave it_ approach to
|
||||||
|
contributing wastes both your and the maintainer's time.
|
||||||
|
|
||||||
Frequent Problems
|
Frequent Problems
|
||||||
=================
|
=================
|
||||||
@@ -301,4 +312,11 @@ Frequent Problems
|
|||||||
git it looks like you have deleted all files, when in fact they have
|
git it looks like you have deleted all files, when in fact they have
|
||||||
never been checked out. Just do a checkout of the branch you want.
|
never been checked out. Just do a checkout of the branch you want.
|
||||||
|
|
||||||
|
* `Error: repository has at least one unnamed head: hg r<N>`
|
||||||
|
|
||||||
|
By design, hg-fast-export cannot deal with extra heads on a branch.
|
||||||
|
There are a few options depending on whether the extra heads are
|
||||||
|
in-use/open or normally closed. See [Notes/Limitations](#noteslimitations)
|
||||||
|
section for more details.
|
||||||
|
|
||||||
[hg-export-tool]: https://github.com/chrisjbillington/hg-export-tool
|
[hg-export-tool]: https://github.com/chrisjbillington/hg-export-tool
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ def sanitize_name(name,what="branch", mapping={}):
|
|||||||
if not auto_sanitize:
|
if not auto_sanitize:
|
||||||
return mapping.get(name,name)
|
return mapping.get(name,name)
|
||||||
n=mapping.get(name,name)
|
n=mapping.get(name,name)
|
||||||
p=re.compile(b'([[ ~^:?\\\\*]|\.\.)')
|
p=re.compile(b'([\\[ ~^:?\\\\*]|\.\.)')
|
||||||
n=p.sub(b'_', n)
|
n=p.sub(b'_', n)
|
||||||
if n[-1:] in (b'/', b'.'): n=n[:-1]+b'_'
|
if n[-1:] in (b'/', b'.'): n=n[:-1]+b'_'
|
||||||
n=b'/'.join([dot(s) for s in n.split(b'/')])
|
n=b'/'.join([dot(s) for s in n.split(b'/')])
|
||||||
@@ -294,7 +294,7 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors,
|
|||||||
brmap[name]=n
|
brmap[name]=n
|
||||||
return n
|
return n
|
||||||
|
|
||||||
(revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors,encoding)
|
(revnode,_,user,(time,timezone),files,desc,branch,extra)=get_changeset(ui,repo,revision,authors,encoding)
|
||||||
if repo[revnode].hidden():
|
if repo[revnode].hidden():
|
||||||
return count
|
return count
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors,
|
|||||||
commit_data = {'branch': branch, 'parents': parents,
|
commit_data = {'branch': branch, 'parents': parents,
|
||||||
'author': author, 'desc': desc,
|
'author': author, 'desc': desc,
|
||||||
'revision': revision, 'hg_hash': hg_hash,
|
'revision': revision, 'hg_hash': hg_hash,
|
||||||
'committer': user}
|
'committer': user, 'extra': extra}
|
||||||
for filter in plugins['commit_message_filters']:
|
for filter in plugins['commit_message_filters']:
|
||||||
filter(commit_data)
|
filter(commit_data)
|
||||||
branch = commit_data['branch']
|
branch = commit_data['branch']
|
||||||
@@ -493,7 +493,12 @@ def verify_heads(ui,repo,cache,force,ignore_unnamed_heads,branchesmap):
|
|||||||
sanitized_name=sanitize_name(b,"branch",branchesmap)
|
sanitized_name=sanitize_name(b,"branch",branchesmap)
|
||||||
sha1=get_git_sha1(sanitized_name)
|
sha1=get_git_sha1(sanitized_name)
|
||||||
c=cache.get(sanitized_name)
|
c=cache.get(sanitized_name)
|
||||||
if sha1!=c:
|
if not c and sha1:
|
||||||
|
stderr_buffer.write(
|
||||||
|
b'Error: Branch [%s] already exists and was not created by hg-fast-export, '
|
||||||
|
b'export would overwrite unrelated branch\n' % b)
|
||||||
|
if not force: return False
|
||||||
|
elif sha1!=c:
|
||||||
stderr_buffer.write(
|
stderr_buffer.write(
|
||||||
b'Error: Branch [%s] modified outside hg-fast-export:'
|
b'Error: Branch [%s] modified outside hg-fast-export:'
|
||||||
b'\n%s (repo) != %s (cache)\n' % (b, b'<None>' if sha1 is None else sha1, c)
|
b'\n%s (repo) != %s (cache)\n' % (b, b'<None>' if sha1 is None else sha1, c)
|
||||||
@@ -547,7 +552,7 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
tip=len(repo)
|
tip=len(repo)
|
||||||
|
|
||||||
min=int(state_cache.get('tip',0))
|
min=int(state_cache.get(b'tip',0))
|
||||||
max=_max
|
max=_max
|
||||||
if _max<0 or max>tip:
|
if _max<0 or max>tip:
|
||||||
max=tip
|
max=tip
|
||||||
@@ -580,8 +585,8 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
|
|||||||
for rev in range(min,max):
|
for rev in range(min,max):
|
||||||
c=export_note(ui,repo,rev,c,authors, encoding, rev == min and min != 0)
|
c=export_note(ui,repo,rev,c,authors, encoding, rev == min and min != 0)
|
||||||
|
|
||||||
state_cache['tip']=max
|
state_cache[b'tip']=max
|
||||||
state_cache['repo']=repourl
|
state_cache[b'repo']=repourl
|
||||||
save_cache(tipfile,state_cache)
|
save_cache(tipfile,state_cache)
|
||||||
save_cache(mappingfile,mapping_cache)
|
save_cache(mappingfile,mapping_cache)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user