Commit Graph

118 Commits

Author SHA1 Message Date
Dave Townsend
ff1c885305 Ignore obsolete changesets in the source repository
Obsolete changesets are, for example, create by the Evolve
extension. This patch switches to an unfiltered repository (the
filtered one throws on an attempt to access obsolete revisions) and
then filters out the obsolete revisions when it comes across them.

Fixes #173
2019-10-20 19:45:42 +02:00
Frej Drejhammar
0096085b6f Tag maps should use the same syntax as branch and author maps
When version v171002 introduced a new mapping file format for branches
and authors, that change never made it to the remapping of tags
although the README documents it.

Fixes #172.
2019-10-12 21:09:14 +02:00
Frej Drejhammar
1181a0af47 Allow name sanitizer to be disabled with --no-auto-sanitize
Make it possible to completely disable the name sanitizer by the
--no-auto-sanitize flag. Previously the sanitizer was run on user
remapped names. As the sanitizer rewrites perfectly legal git
names (such as __.*) this is probably not what the user wants.

Closes #155.
2019-09-13 14:56:32 +02:00
MokhamedDakhraui
581b1b3d17 Remove git submodules if .hgsubstate file was removed or emptied 2019-08-18 05:46:46 +03:00
MokhamedDakhraui
7df01ac323 Refactor refresh_gitmodules()
Use the change context substate field instead of manually parsing the `.hgsubstate` file.
2019-08-16 02:42:03 +03:00
MokhamedDakhraui
914f5a0dbe Replaced several lambdas by one loop 2019-08-16 02:41:54 +03:00
MokhamedDakhraui
8779cb5e95 Extract operations with submodules to separated methods 2019-08-16 02:40:44 +03:00
Johannes Carlsson
47d330de83 Add support for mercurial subrepos
This adds a new command line option (--subrepo-map) that will
map mercurial subrepos to git submodules.

The --subrepo-map takes a mapping file as an argument that will
be used to map a subrepo folder to a git submodule.

For more information see the README-SUBMODULES.md.

This commit is inspired by the changes made by daolis in PR#38
that was never merged.

Closes: #51
Closes: #147
2019-01-07 18:41:19 +01:00
Johan Henkens
cadcfcbe90 Move filter_contents to plugin system 2018-12-05 13:25:48 -08:00
Johan Henkens
e895ce087f Add plugin system 2018-12-05 13:25:47 -08:00
Frej Drejhammar
ac60034ba3 Adhere to PEP 394
From PEP 394 [1]:

* python2 will refer to some version of Python 2.x.

* end users should be aware that python refers to python3 on at least
  Arch Linux (that change is what prompted the creation of this PEP),
  so python should be used in the shebang line only for scripts that
  are source compatible with both Python 2 and 3.

So to make sure that we run correctly on a system where python refers
to python3 and avoid problems like issue #11 we change the shebangs.

[1] https://www.python.org/dev/peps/pep-0394/
2018-08-11 15:07:19 +02:00
Anton Tykhyy
89db1d93cf Add --filter-contents 2018-06-17 21:09:59 +03:00
Frej Drejhammar
e200cec39f Adapt to changes in Mercurial 4.6
Starting with Mercurial 4.6 repo.lookup() no longer accepts raw hashes
for lookups.
2018-06-10 15:51:09 +02:00
Frej Drejhammar
50dc10770b Warn contributors from doing work that will no be merged
From time to time contributors spend time doing work that will not be
accepted as it duplicates functionality that is already provided with
the mapping files. Try to dissuade them from doing that by explaining
the reasons in the comment.
2018-02-01 07:03:03 +01:00
Frej Drejhammar
cc8fefe008 Change syntax of mapping files
This is done to allow escape sequences in the key and value strings.
2017-10-02 13:05:14 +02:00
Frej Drejhammar
e174c2a0b7 Refactor load_mapping() to move line parsing to inner function
This is done in preparation to allowing mappings to contain quoted
characters.
2017-09-29 18:50:41 +02:00
Frej Drejhammar
4bb50bb3fb Fix crash when a branch name starts with '/'
If a branch name starts with '/' it will be split into ['', ...] and
then mapped over with dot(), only dot() does not handle the empty
string. Teach dot() to handle the empty string.

This fixes the underlying problem in issue #91.
2017-05-14 14:32:59 +02:00
Frej Drejhammar
c614ae776b Fix "Branch ... modified outside hg-fast-export..." for sanitized branch names
The heads cache contains sanitized names, but we try to look up
unsanitized names, this is wrong. Switch to looking up the sanitized
name.
2016-04-15 15:46:47 +02:00
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