Conversion is incorrect due to the default core.ignorecase #87

Closed
emilianbold opened this Issue Dec 30, 2016 · 5 comments

Projects

None yet

2 participants

@emilianbold
Contributor

I have some changesets that just change the case of a file name (eg. from HTMLLexer.java to HtmlLexer.java).

hg-fast-export seems to produce an invalid git commit, because I am running conversion on macOS, where git init creates a repository with core.ignorecase=true.

I don't believe there is any way to fix this other than re-running the conversion (is it?).

If I run git config core.ignorecase false before executing hg-fast-export the conversion is correct.

How to reproduce the issue:

$ mkdir case-bug
$ cd case-bug/
$ mkdir m
$ cd m/
$ hg init .
$ echo 'a' > A
$ hg add A 
$ hg commit -m "Added A"
$ mv A a
$ ls
a
$ hg mv A a
$ hg st
A a
R A
$ hg commit -m 'Renaming A -> a'
$ hg st
$ hg log -p 
changeset:   1:b68723268fab
tag:         tip
user:        Emilian Bold <emilian.bold at gmail.com>
date:        Fri Dec 30 14:41:40 2016 +0200
summary:     Renaming A -> a

diff -r 5cffc220b750 -r b68723268fab A
--- a/A	Fri Dec 30 14:41:26 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-a
diff -r 5cffc220b750 -r b68723268fab a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/a	Fri Dec 30 14:41:40 2016 +0200
@@ -0,0 +1,1 @@
+a

changeset:   0:5cffc220b750
user:        Emilian Bold <emilian.bold at gmail.com>
date:        Fri Dec 30 14:41:26 2016 +0200
summary:     Added A

diff -r 000000000000 -r 5cffc220b750 A
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/A	Fri Dec 30 14:41:26 2016 +0200
@@ -0,0 +1,1 @@
+a

$ cd ..
$ mkdir g
$ cd g/
$ git init .
Initialized empty Git repository in /Users/apache/work/case-bug/g/.git/
$ ~/work/fast-export/hg-fast-export.sh -r ../m/
master: Exporting full revision 1/2 with 1/0/0 added/changed/removed files
master: Exporting simple delta revision 2/2 with 1/0/1 added/changed/removed files
Issued 2 commands
Unpacking objects: 100% (4/4), done.
git-fast-import statistics:
---------------------------------------------------------------------
Alloc\'d objects:       5000
Total objects:            4 (         2 duplicates                  )
      blobs  :            1 (         1 duplicates          0 deltas of          0 attempts)
      trees  :            1 (         1 duplicates          0 deltas of          1 attempts)
      commits:            2 (         0 duplicates          0 deltas of          0 attempts)
      tags   :            0 (         0 duplicates          0 deltas of          0 attempts)
Total branches:           1 (         1 loads     )
      marks:           1024 (         2 unique    )
      atoms:              1
Memory total:          2344 KiB
       pools:          2110 KiB
     objects:           234 KiB
---------------------------------------------------------------------
pack_report: getpagesize()            =       4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit      = 8589934592
pack_report: pack_used_ctr            =          0
pack_report: pack_mmap_calls          =          0
pack_report: pack_open_windows        =          0 /          0
pack_report: pack_mapped              =          0 /          0
---------------------------------------------------------------------

$ cd ..
$ git clone g g-work
Cloning into 'g-work'...
done.
$ cd g-work/
$ ls
A
$ git log -p -r
commit 0641070dea5994d86fe59547130467cf0e50152e
Author: Emilian Bold <emilian.bold at gmail.com>
Date:   Fri Dec 30 14:41:40 2016 +0200

    Renaming A -> a

commit 895726cb47653df10167fc71892328fa124e2787
Author: Emilian Bold <emilian.bold at gmail.com>
Date:   Fri Dec 30 14:41:26 2016 +0200

    Added A

diff --git a/A b/A
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/A
@@ -0,0 +1 @@
+a

With git config core.ignorecase false:

g2-work apache$ git log -p -r
commit 8774dea085bd099c38904d48dacc557147fcb201
Author: Emilian Bold <emilian.bold@gmail.com>
Date:   Fri Dec 30 14:41:40 2016 +0200

    Renaming A -> a

diff --git a/A b/a
similarity index 100%
rename from A
rename to a

commit 895726cb47653df10167fc71892328fa124e2787
Author: Emilian Bold <emilian.bold@gmail.com>
Date:   Fri Dec 30 14:41:26 2016 +0200

    Added A

diff --git a/A b/A
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/A
@@ -0,0 +1 @@
+a
@frej
Owner
frej commented Dec 30, 2016

Dealing with broken file systems is outside the scope of fast-export. If you want the conversion to be usable for people using a case sensitive FS, run git with core.ignorecase=false (as you have already discovered).

I'm not sure I'd say that the commit is invalid in the first case. A checked out commit will give you the same tree as if you checked out the corresponding hg commit using the same file system.

@frej frej added the won't-fix label Dec 30, 2016
@emilianbold
Contributor

Checking out with hg produces the correct filename. It's only the git repo that's broken.

I was expecting that hg-fast-export just massages the patch file and imports it into git. It's a bit worrisome that it depends on unknown git flags whose defaults depend on the OS running git at the time. hg-fast-export should produce the same output all the time.

The least I suggest patching hg-fast-export to flat out refuse to run if core.ignorecase=true unless some flag is set (perhaps --force or some new flag) because it is almost certain to produce a bad conversion on any reasonably large repository where such case sensitive renames are bound to happen.

Also, I know Apple's filesystem is a joke for being case insensitive by default but a lot of people use macOS, this flag is non-obvious and hg-fast-export might produce git repositories that are silently corrupt (for example, by being correct in the current version but incorrect in older versions).

@frej
Owner
frej commented Dec 30, 2016
@emilianbold
Contributor

Send me a patch!

See pull request #88

@frej
Owner
frej commented Jan 1, 2017

Patch merged

@frej frej closed this Jan 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment