hg2git: in _init_dirs, store keys without leading '/' (issue103)

Previously, whenever a tree that wasn't the root ('') was stored, we'd prepend
a '/' to it. Then, when we'd try retrieving the entry, we'd do so without the
leading '/'. This caused data loss because existing tree entries were dropped
on the floor. Fix that by only adding '/' if we're adding to a non-empty
initial path.

This wasn't detected in tests because most of them deal only with files in the
root and not ones in subdirectories.
This commit is contained in:
Siddharth Agarwal 2014-03-25 11:11:04 -07:00
parent f84c69b6c1
commit c188adb4b9
2 changed files with 53 additions and 1 deletions

View File

@ -91,7 +91,11 @@ class IncrementalChangesetExporter(object):
self._dirs[path] = tree
for entry in tree.iteritems():
if entry.mode == dirkind:
todo.append((path + '/' + entry.path, store[entry.sha]))
if path == '':
newpath = entry.path
else:
newpath = path + '/' + entry.path
todo.append((newpath, store[entry.sha]))
@property
def root_tree_sha(self):

View File

@ -116,8 +116,56 @@ issue3228 was fixed in 2.1
no changes found
[1]
hg-git issue103 -- directories can lose information at hg-git export time
$ hg up master
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ mkdir dir1
$ echo alpha > dir1/alpha
$ hg add dir1/alpha
$ fn_hg_commit -m 'add dir1/alpha'
$ hg push -r master
pushing to $TESTTMP/gitrepo
searching for changes
adding objects
added 1 commits with 2 trees and 0 blobs
updating reference refs/heads/master
$ echo beta > dir1/beta
$ hg add dir1/beta
$ fn_hg_commit -m 'add dir1/beta'
$ hg push -r master
pushing to $TESTTMP/gitrepo
searching for changes
adding objects
added 1 commits with 2 trees and 0 blobs
updating reference refs/heads/master
$ hg log -r master
changeset: 5:fff64abfde07
bookmark: master
tag: default/master
tag: tip
user: test
date: Mon Jan 01 00:00:15 2007 +0000
summary: add dir1/beta
$ cd ..
$ hg clone gitrepo hgrepo-test
importing git objects into hg
updating to branch default
5 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg -R hgrepo-test log -r master
changeset: 4:fff64abfde07
bookmark: master
tag: default/master
tag: tip
user: test
date: Mon Jan 01 00:00:15 2007 +0000
summary: add dir1/beta
Push empty Hg repo to empty Git repo (issue #58)
Since there aren't any changes, exit code 1 is expected in modern Mercurial.
However, since it varies between supported Mercurial versions, we need to