mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
fix a bug when a directory is replaced with a file
also use ObjectStore.tree_changes from dulwich instead of our own func (the change to test octopus is legitimate, there were some duplicate entries)
This commit is contained in:
parent
8adb077176
commit
91561c5a2e
@ -404,8 +404,6 @@ class GitHandler(object):
|
||||
|
||||
def import_git_commit(self, commit):
|
||||
self.ui.debug(_("importing: %s\n") % commit.id)
|
||||
# TODO: Do something less coarse-grained than try/except on the
|
||||
# get_file call for removed files
|
||||
|
||||
(strip_message, hg_renames, hg_branch, extra) = self.extract_hg_metadata(commit.message)
|
||||
|
||||
@ -450,15 +448,14 @@ class GitHandler(object):
|
||||
oldenc = self.swap_out_encoding()
|
||||
|
||||
def getfilectx(repo, memctx, f):
|
||||
try:
|
||||
(mode, sha, data) = self.get_file(commit, f)
|
||||
e = self.convert_git_int_mode(mode)
|
||||
except (TypeError, KeyError):
|
||||
raise IOError()
|
||||
if f in hg_renames:
|
||||
copied_path = hg_renames[f]
|
||||
else:
|
||||
copied_path = None
|
||||
delete, mode, sha = files[f]
|
||||
if delete:
|
||||
raise IOError
|
||||
|
||||
data = self.git[sha].data
|
||||
copied_path = hg_renames.get(f)
|
||||
e = self.convert_git_int_mode(mode)
|
||||
|
||||
return context.memfilectx(f, data, 'l' in e, 'x' in e, copied_path)
|
||||
|
||||
gparents = map(self.map_hg_get, commit.parents)
|
||||
@ -468,7 +465,7 @@ class GitHandler(object):
|
||||
if len(gparents) > 1:
|
||||
# merge, possibly octopus
|
||||
def commit_octopus(p1, p2):
|
||||
ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
|
||||
ctx = context.memctx(self.repo, (p1, p2), text, list(files), getfilectx,
|
||||
author, date, {'hg-git': 'octopus'})
|
||||
return hex(self.repo.commitctx(ctx))
|
||||
|
||||
@ -482,8 +479,6 @@ class GitHandler(object):
|
||||
if gparents:
|
||||
p1 = gparents.pop()
|
||||
|
||||
files = list(set(files))
|
||||
|
||||
pa = None
|
||||
if not (p2 == nullid):
|
||||
node1 = self.repo.changectx(p1)
|
||||
@ -509,7 +504,7 @@ class GitHandler(object):
|
||||
if octopus:
|
||||
extra['hg-git'] ='octopus-done'
|
||||
|
||||
ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
|
||||
ctx = context.memctx(self.repo, (p1, p2), text, list(files), getfilectx,
|
||||
author, date, extra)
|
||||
|
||||
node = self.repo.commitctx(ctx)
|
||||
@ -754,57 +749,25 @@ class GitHandler(object):
|
||||
otree = obj
|
||||
|
||||
def get_files_changed(self, commit):
|
||||
def filenames(basetree, comptree, prefix):
|
||||
basefiles = set()
|
||||
changes = list()
|
||||
csha = None
|
||||
cmode = None
|
||||
if basetree is not None:
|
||||
for (bmode, bname, bsha) in basetree.entries():
|
||||
if bmode == 0160000: # TODO: properly handle submodules
|
||||
continue
|
||||
basefiles.add(bname)
|
||||
bobj = self.git.get_object(bsha)
|
||||
if comptree is not None:
|
||||
if bname in comptree:
|
||||
(cmode, csha) = comptree[bname]
|
||||
else:
|
||||
(cmode, csha) = (None, None)
|
||||
if not ((csha == bsha) and (cmode == bmode)):
|
||||
if isinstance (bobj, Blob):
|
||||
changes.append (prefix + bname)
|
||||
elif isinstance(bobj, Tree):
|
||||
ctree = None
|
||||
if csha:
|
||||
ctree = self.git.get_object(csha)
|
||||
changes.extend(filenames(bobj,
|
||||
ctree,
|
||||
prefix + bname + '/'))
|
||||
tree = commit.tree
|
||||
btree = None
|
||||
|
||||
# handle removals
|
||||
if comptree is not None:
|
||||
for (bmode, bname, bsha) in comptree.entries():
|
||||
if bmode == 0160000: # TODO: handle submodles
|
||||
continue
|
||||
if bname not in basefiles:
|
||||
bobj = self.git.get_object(bsha)
|
||||
if isinstance(bobj, Blob):
|
||||
changes.append(prefix + bname)
|
||||
elif isinstance(bobj, Tree):
|
||||
changes.extend(filenames(None, bobj,
|
||||
prefix + bname + '/'))
|
||||
return changes
|
||||
if commit.parents:
|
||||
btree = self.git[commit.parents[0]].tree
|
||||
|
||||
all_changes = list()
|
||||
otree = self.git.tree(commit.tree)
|
||||
if len(commit.parents) == 0:
|
||||
all_changes = filenames(otree, None, '')
|
||||
for parent in commit.parents:
|
||||
pcommit = self.git.commit(parent)
|
||||
ptree = self.git.tree(pcommit.tree)
|
||||
all_changes.extend(filenames(otree, ptree, ''))
|
||||
changes = self.git.object_store.tree_changes(btree, tree)
|
||||
files = {}
|
||||
for (oldfile, newfile), (oldmode, newmode), (oldsha, newsha) in changes:
|
||||
if newfile is None:
|
||||
file = oldfile
|
||||
delete = True
|
||||
else:
|
||||
file = newfile
|
||||
delete = False
|
||||
|
||||
return all_changes
|
||||
files[file] = (delete, newmode, newsha)
|
||||
|
||||
return files
|
||||
|
||||
def remote_name(self, remote):
|
||||
names = [name for name, path in self.paths if path == remote]
|
||||
|
@ -20,17 +20,17 @@ Total 14 (delta 3), reused 0 (delta 0)
|
||||
importing Git objects into Hg
|
||||
at: 0/5
|
||||
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||
@ changeset: 5:7acfed59bdde
|
||||
@ changeset: 5:6523aa9f4775
|
||||
|\ tag: master
|
||||
| | tag: default/master
|
||||
| | tag: tip
|
||||
| | parent: 1:1436150b86c2
|
||||
| | parent: 4:6e0acfc91939
|
||||
| | parent: 4:7f6c791a169f
|
||||
| | user: test <test@example.org>
|
||||
| | date: Mon Jan 01 00:00:13 2007 +0000
|
||||
| | summary: Merge branches 'branch1' and 'branch2'
|
||||
| |
|
||||
| o changeset: 4:6e0acfc91939
|
||||
| o changeset: 4:7f6c791a169f
|
||||
| |\ parent: 2:7bcd915dc873
|
||||
| | | parent: 3:37c124f2d0a0
|
||||
| | | user: test <test@example.org>
|
||||
|
@ -34,7 +34,8 @@ cd gitrepo
|
||||
git init | python -c "import sys; print sys.stdin.read().replace('$(dirname $(pwd))/', '')"
|
||||
|
||||
mkdir d1
|
||||
touch d1/f1 d1/f2
|
||||
echo a > d1/f1
|
||||
echo b > d1/f2
|
||||
git add d1/f1 d1/f2
|
||||
commit -m initial
|
||||
|
||||
@ -42,6 +43,12 @@ mkdir d2
|
||||
git mv d1/f2 d2/f2
|
||||
commit -m 'rename'
|
||||
|
||||
rm -r d1
|
||||
echo c > d1
|
||||
git add d1
|
||||
commit -m 'replace a dir with a file'
|
||||
|
||||
|
||||
cd ..
|
||||
mkdir gitrepo2
|
||||
cd gitrepo2
|
||||
@ -58,7 +65,7 @@ git daemon --base-path="$(pwd)"\
|
||||
|
||||
hg clone git://localhost/gitrepo hgrepo | grep -v '^updating'
|
||||
cd hgrepo
|
||||
hg log -r tip --template 'adds: {file_adds}\ndels: {file_dels}\n'
|
||||
hg log --template 'adds: {file_adds}\ndels: {file_dels}\n'
|
||||
|
||||
hg gclear
|
||||
hg push git://localhost/gitrepo2
|
||||
|
@ -3,26 +3,36 @@ Initialized empty Git repository in gitrepo/.git/
|
||||
Initialized empty Git repository in gitrepo2/.git/
|
||||
|
||||
importing Hg objects into Git
|
||||
Counting objects: 8, done.
|
||||
Compressing objects: 25% (1/4)
Compressing objects: 50% (2/4)
Compressing objects: 75% (3/4)
Compressing objects: 100% (4/4)
Compressing objects: 100% (4/4), done.
|
||||
Total 8 (delta 0), reused 0 (delta 0)
|
||||
Counting objects: 12, done.
|
||||
Compressing objects: 16% (1/6)
Compressing objects: 33% (2/6)
Compressing objects: 50% (3/6)
Compressing objects: 66% (4/6)
Compressing objects: 83% (5/6)
Compressing objects: 100% (6/6)
Compressing objects: 100% (6/6), done.
|
||||
Total 12 (delta 0), reused 0 (delta 0)
|
||||
importing Git objects into Hg
|
||||
at: 0/2
|
||||
at: 0/3
|
||||
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||
adds: d1
|
||||
dels: d1/f1
|
||||
adds: d2/f2
|
||||
dels: d1/f2
|
||||
adds: d1/f1 d1/f2
|
||||
dels:
|
||||
clearing out the git cache data
|
||||
pushing to git://localhost/gitrepo2
|
||||
importing Hg objects into Git
|
||||
at: 0/2
|
||||
at: 0/3
|
||||
creating and sending data
|
||||
commit 7d84da95f2caf7a65833ae580fe5a08a0c3cb6b2
|
||||
commit 6e0dbd8cd92ed4823c69cb48d8a2b81f904e6e69
|
||||
Author: test <test@example.org>
|
||||
Date: Mon Jan 1 00:00:12 2007 +0000
|
||||
|
||||
replace a dir with a file
|
||||
|
||||
commit a1874d5cd0b1549ed729e36f0da4a93ed36259ee
|
||||
Author: test <test@example.org>
|
||||
Date: Mon Jan 1 00:00:11 2007 +0000
|
||||
|
||||
rename
|
||||
|
||||
commit 48e6424b6487f2a16e901f72fe52168b40278f5b
|
||||
commit 102c17a5deda49db3f10ec5573f9378867098b7c
|
||||
Author: test <test@example.org>
|
||||
Date: Mon Jan 1 00:00:10 2007 +0000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user