Commit Graph

50 Commits

Author SHA1 Message Date
Frej Drejhammar
7224e420a7 Warn if one of the marks, mapping, or heads files are empty 2016-04-03 15:48:03 +02:00
Frej Drejhammar
b7cc6ab3bf verify_heads() needs to be aware of the branch renaming map
As all branches created on the git side are transformed by
sanitize_name(), this should be a safe backwards compatible change. If a
user is doing incremental imports and sanitize_name() now suddenly
modifies the branch name, verify_heads() would already have complained
on the first incremental run.

Thanks goes to Steve Tousignant<s.tousignant@gmail.com> for discovering
the problem.
2016-04-02 15:01:45 +02:00
Frej Drejhammar
6d8b4dbb11 Warn if opening a mapping file fails 2016-04-02 14:59:47 +02:00
Frej Drejhammar
832ee29bfa Refactor sanitize_name() to know about renaming map
Handle the lookup table for branch and tag renaming inside
sanitize_name().
2016-04-02 14:57:19 +02:00
Frej Drejhammar
46bf316a3c Explain why it is a bad idea to change sanitize_name()
This is a piece of code which frequently attracts pull requests which
are summarily rejected. As there is no "git blame" for rejected pull
requests, try to avoid misguided work by adding a comment at the
relevant place.
2016-04-02 12:28:03 +02:00
Frej Drejhammar
f75057e49a Make --hg-hash work in incremental mode
When an import is restarted the first new note commit must use
refs/notes/hg^0 as the parent. As refs/notes/hg is only updated at the
end of a session we cannot have it present in all note commits. Neither
can we generate new marks for note commits as that would require a new
mapping scheme from hg versions numbers to git marks. A new mapping
scheme would break existing incremental import setups.

We therefore restructure the code to do the notes at the end of an
import session, thus only requiring a refs/notes/hg^0 reference in the
first commit.
2016-01-10 14:00:02 +01:00
Han Sangjin
38e81367ec Add filename encoding option --fe
In some locales Mercurial uses different encodings for commit messages
and file names. The --fe option allows the filename encoding to be
overridden.
2015-11-13 11:39:47 +01:00
Frej Drejhammar
3c27c693e1 Allow branches and tags to be remapped
Branch and tag names can now be renamed using a mechanism similar to the
-A option for author names.

-B specifies a mapping file for branch names, and -T a mapping file for
tags.
2015-08-16 17:13:04 +02:00
Frej Drejhammar
a542b6aa97 refactor: Make author map loading more generic
This is the first step in adding mappings for branches and tags.
2015-08-16 13:09:51 +02:00
Frej Drejhammar
b9b6f2a57a Survive corrupt source repositories
Apparently a bug (http://bz.selenic.com/show_bug.cgi?id=3511) in
multiple released versions of Mercurial could produce commits where
files had absolute paths.

As a "healthy" repo should not contain any absolute paths, it should be
safe to always strip a leading '/' from the path and let the conversion
continue.
2015-08-15 20:26:02 +02:00
zed
d202200fd9 Make -e option apply to imported filenames
When the -e option is given, convert imported filenames just as we do
for metadata and author information.
2014-11-01 15:54:05 +01:00
zed
e87c9cb3b8 Add option for specifying the text encoding used by Mercurial
When a mercurial repository does not use utf-8 for encoding author
strings and commit messages the "-e <encoding>" command line option
can be used to force fast-export to convert incoming meta data from
<encoding> to utf-8.

When "-e <encoding>" is given, we use Python's string
decoding/encoding API to convert meta data on the fly when processing
commits.
2014-10-25 22:39:08 +02:00
Piotr Święcicki
1d85321bdb Annotate commits with the hg hash as git notes in the hg namespace
If the --hg-hash argument is given, the converted commits are
annotated with the original hg hash as a git note in the "hg"
namespace.

The notes can be shown by git log using the "--notes=hg" argument.
2014-05-02 16:57:03 +02:00
Kyle J. McKay
1be636db36 hg-fast-export.py: do not sort merge commit parents
In a merge commit, the first parent is always the same parent that
would be recorded if the commit were not a merge and the other
parent(s) record the commit(s) being merged in.

Preserving this order is important so that log --first-parent works
properly and also so that the merge history is not distorted by an
incorrect permutation of the DAG.

Remove the code that sorts the merge parents based on node id so
that the correct DAG order is preserved.
2014-03-28 16:17:12 +01:00
frej
7937dfaad5 Merge pull request #23 from ritcheyer/master
checking for - and converting - backslashes

Thank you for your contribution!
2014-03-16 16:05:47 +01:00
Kyle J. McKay
8822aa34e9 hg-fast-export.py: improve authors file compatibility
The authors file format accepted by git-svnimport and git-cvsimport
actually allows blank lines and comment lines that start with '#'.

Ignore blank lines and lines starting with '#' as the first
non-whitespace character to be compatible with the authors file
format accepted by the referenced tools.
2014-03-16 16:00:42 +01:00
Kyle J. McKay
5fad4e4b99 hg-fast-export: support new --hgtags option
Add support for a new --hgtags option.  When given, any .hgtags
files that may be present are exported.

Normally this is not desirable.  However, when attempting to mimic
the actions of other hg exporters that always export any .hgtags
files this option can help produce matching export data.
2014-03-16 16:00:42 +01:00
Kyle J. McKay
b1d1265330 hg-fast-export.py: do not lose file mode changes
If the file mode changes (for example from 10644 to 10755), but the
actual text of the file itself does not, then the change could be
missed since the hashes would remain the same.

If the hashes match, also compare the gitmode values before deciding
the file is unchanged.
2014-03-16 16:00:42 +01:00
Kyle J. McKay
4be2fa46ee hg-fast-export.py: support older hg versions
Do not use the closesbranch function as it was added in later
versions of hg.  Use its definition instead.
2014-03-16 16:00:42 +01:00
Kyle J. McKay
728716375b hg-fast-export.py: restore compatibility with older python
Since hg runs and supports older versions of python, hg-fast-export.py
should too.  Replace dictionary comprehension with equivalent code that
supports versions of python older than 2.7.
2014-03-16 16:00:42 +01:00
Eric Ritchey
7b4729ddc8 checking for - and converting - backslashes 2014-03-13 14:32:10 -07:00
Sergio Oliveira
a4b23c6713 Fixing for hg 2.9 2014-02-10 08:32:27 -02:00
Daniel Harding
7eaba68bc2 Make hg-fast-export (actually) work on Windows
Because on Windows sys.stdout is initially in text mode, any LF
characters written to it will be transformed to CRLF, which causes git
to blow up.  This change uses Windows platform-specific code to change
sys.stdout to binary mode.
2012-09-30 11:10:48 +01:00
frej
e63f780004 Merge pull request #6 from aried3r/master
Fix for Mercurial 2.3 compatibility
2012-08-10 09:10:44 -07:00
Anton Rieder
0dcbd3d195 Organized imports
After an update to Mercurial 2.3 the module 'repo' was removed and the
program crashed when trying to convert a repository. I checked the
imports with 'pyflakes' and removed all unused ones, repo (among
others) was never used.

http://www.selenic.com/repo/hg/rev/1ac628cd7113#l9.1
2012-08-07 01:35:09 +02:00
Daniel Harding
4ce8835d11 Make hg-fast-export work on Windows
* use sys.stdout.write instead of print to avoid end-of-line issues
* use os.devnull instead of hard-coding /dev/null
2012-05-28 18:57:30 +01:00
Anton Rieder
8f6adfd07c Applied rule #7 of git-check-ref-format
Rule #7 of git-check-ref-format states "7. They cannot end with a dot
'.'." which was not yet implemented in fast-export. This commit fixes
this.
2012-05-16 23:44:00 +02:00
Barry Wardell
e24fa42b87 Commits with no parent need a reset command.
This fixes a problem where a repository is imported incorrectly when there is a merge
between two branches with no common history.
2011-12-09 19:29:14 +01:00
David Wragg
c8a4584896 The "verifying branch" message is not very interesting
Particularly if the repo has hundreds of branches.
2010-09-29 02:02:32 +01:00
David Wragg
2b197f947f Simplify handling of parents of exported commit
The previous code did an awful lot of work to infer the parents of an
exported commit, incorporating information from many sources.  But
there were multiple bugs in this scheme, sometimes resulting in merge
commits with two parents pointing to the same commit object.

Instead, use a much more straightforward process of mapping the
parents stored in hg.
2010-09-29 02:02:22 +01:00
Matthias Urlichs
0306977b28 hg-fast-export: Compare HG revisions when merging
hg-fast-export uses hg's branch order (from the log) when merging,
this is a problem. Consider the case:

HG repo A  has revisions 1-10. Repository B is cloned from that.
Subsequently, A adds revision 11, and B adds a different change which
also has revision 11. If B now pulls from A, A's rev11 will have the
number 12; if A then pulls from B, the reverse also holds. So the logs
are different even though they contain the exact same changes.

hg-fast-export will thus create different git repositories for A and B,
even though the contents are identical for all practical purposes.
In particular, the repos would be identical if A and B had used git from
the beginning.

To fix that, compare HG revisions instead of log positions.
2009-02-23 18:38:26 +01:00
Rocco Rutte
688623f17e hg-fast-export: Support branches without parents
Previously we fed the full revision only for the first one and deltas
for all following including branches being forked off. This doesn't work
with branches that are forked from revision 0. In case such a branch is
found, we now also feed the full revision.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2009-01-27 15:34:46 +01:00
Frej Drejhammar
276f54c38f Merge branch 'from-jmcmullan' into develop
Conflicts:
	hg-fast-export.py
2008-12-20 19:57:39 +01:00
Fabrizio Chiarello
a984e233c2 hg-fast-export: add option to track remote branches under a custom namespace
Add -o, --origin <name> to allow user to set a namespace used
when importing remote branches.

Signed-off-by: Fabrizio Chiarello <ponch@autistici.org>
2008-12-20 19:51:02 +01:00
Jason S. McMullan
b4833029a4 hg export: Support tag movement
HG tag movement is now supported with this patch.

This patch creates a .git/hg2git-mapping file, which maps
HG revision numbers to HG hashes. Combined with the
.git/hg2git-marks file, which maps HG revisions to GIT hashes,
we can now reprocess all tags at the end of each hg export
operation.
2008-12-11 09:05:05 -05:00
Rocco Rutte
fdbb1decaa hg2git: Update copyrights and maintainership information.
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2008-11-25 11:25:22 +01:00
Fabrizio Chiarello
1ab60e492b hg-fast-export: Make default branch customizable
Add -M, --default-branch <branch_name> to allow user to set
the default branch where to pull into

Signed-off-by: Fabrizio Chiarello <ponch@autistici.org>
2008-09-19 08:03:44 +02:00
Rocco Rutte
02bc08886f hg-fast-export: Catch up with mercurial crew API changes
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2008-09-19 08:01:53 +02:00
Peter Colberg
e8ba36aa3f hg-fast-export.py: Use appropriate file mode for symlinks. 2008-09-19 07:55:45 +02:00
Jonathan Nieder
6e3872b6a0 hg-fast-export.py: sanitize tildes (~) in branch names
In git-check-ref-format (1), there is the following rule for refnames:

	3. It cannot have ASCII control character (i.e. bytes
	   whose values are lower than \040, or \177 DEL), space,
	   tilde ~, caret ^, colon :, question-mark ?, asterisk *,
	   or open bracket [ anywhere;

and indeed, this rule is enforced by "git fast-import". hg-fast-export
already checked for all of the visible characters listed except for ~
and converted them to underscores. For some reason the tilde was
forgotten. This patch makes good on the omission.

Note that control characters are still left alone.

Signed-off-by: Jonathan Nieder <jrnieder@uchicago.edu>
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2008-06-03 08:49:57 +02:00
Rocco Rutte
bc98d2c088 hg-fast-export.py: Cache possibly sanitized branch names
...instead of doing it for every single commit.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-10-26 17:11:57 +02:00
Rocco Rutte
4cc930807d hg-fast-import.py: Sanitize ref names
At least the opensolaris hg repo has tag names containing '*',
so sanitize all branch and tag names roughly according to the
specs for git-check-ref-format(1).

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-10-26 16:06:40 +02:00
Rocco Rutte
431c32de6b hg-fast-export.py: Don't attempt to dump revs beyond tip with -m
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-10-25 15:23:17 +02:00
Rocco Rutte
ec1be3d05f hg-fast-export.py: Minor tweaks/cleanup
Remove some unused variables, generalize dictionary-splitting and make
sure we don't sort filename lists twice (repo.status returns files
sorted already).

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-10-25 15:21:46 +02:00
Rocco Rutte
ee510bb022 hg-fast-export.py: Rewrite merge logic
Merges were completely broken as they ended up with twice the same
parent in git. Still everything besides gitk seemed to work.

This because of 1) the incorrect assumption that a commit's parent is
the commit exported right before it and 2) some confusion with markes
being saved/loaded/used since git-fast-import doesn't allow for a ":0"
mark to map hg revision 1:1 to marks.

The merge "algorithm" now works like this:

1) If the commit's higher parent (highest hg rev), is not the last
commit exported for a particular branch, we issue a "from" command to
place it on top of it.

2) If the commit's lower parent exists, we issue a "merge" for it.

This is much simpler and seems to produce correct merges in git. And
while I'm at it, make output less confusing by prepending the target
branch name to each line.

The "twice the same parent" bug was discovered by Michele Ballabio on
the git list.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-10-22 10:06:58 +02:00
Rocco Rutte
5cc155e367 hg-reset.py: Print details for changed branches only
It doesn't make sense to suggest resetting branch HEADs to their current
value.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-03-19 09:27:37 +00:00
Rocco Rutte
f1397c068b hg-fast-export.py: Fix option presence checking
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-03-19 09:05:51 +00:00
Rocco Rutte
7044bdd4d1 Add hg2git.py with library routines
Unfortunately, I can't do 'import hg-fast-export' from python itself, so
we need to move some common methods into 'hg2git.py' which is to be used
as a library for common hg->git routines.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-03-19 08:45:42 +00:00
Rocco Rutte
30ce6693ed hg-fast-export.py: Kill stale usage() and __doc__
Both are obsolete since using the option parser.

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-03-14 10:32:33 +00:00
Rocco Rutte
c84790da82 Use MIT license, adjust hg2git script names to match fast-export repo style
Signed-off-by: Rocco Rutte <pdmef@gmx.net>
2007-03-14 10:29:24 +00:00