remote-bzr: add support to push merges
In order to do that, we need to store the marks of every file, so that they can be fetched when needed. Unfortunately we can't tell bazaar that nothing changed, we need to send the data so that it can figure it out by itself. And since it will be requesting a bunch of information by the file_id, it's better to have a helper dict (rev_files), so that we can fetch it quickly. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
715d64fe99
commit
f38dfc4c32
@ -393,7 +393,7 @@ class CustomTree():
|
|||||||
tree = repo.repository.revision_tree(revid)
|
tree = repo.repository.revision_tree(revid)
|
||||||
try:
|
try:
|
||||||
for path, entry in tree.iter_entries_by_dir():
|
for path, entry in tree.iter_entries_by_dir():
|
||||||
files[path] = entry.file_id
|
files[path] = [entry.file_id, None]
|
||||||
finally:
|
finally:
|
||||||
repo.unlock()
|
repo.unlock()
|
||||||
return files
|
return files
|
||||||
@ -408,12 +408,18 @@ class CustomTree():
|
|||||||
self.base_files = copy_tree(self.base_id)
|
self.base_files = copy_tree(self.base_id)
|
||||||
|
|
||||||
self.files = files_cache[revid] = self.base_files.copy()
|
self.files = files_cache[revid] = self.base_files.copy()
|
||||||
|
self.rev_files = {}
|
||||||
|
|
||||||
|
for path, data in self.files.iteritems():
|
||||||
|
fid, mark = data
|
||||||
|
self.rev_files[fid] = [path, mark]
|
||||||
|
|
||||||
for path, f in files.iteritems():
|
for path, f in files.iteritems():
|
||||||
fid = self.files.get(path, None)
|
fid, mark = self.files.get(path, [None, None])
|
||||||
if not fid:
|
if not fid:
|
||||||
fid = bzrlib.generate_ids.gen_file_id(path)
|
fid = bzrlib.generate_ids.gen_file_id(path)
|
||||||
f['path'] = path
|
f['path'] = path
|
||||||
|
self.rev_files[fid] = [path, mark]
|
||||||
self.updates[fid] = f
|
self.updates[fid] = f
|
||||||
|
|
||||||
def last_revision(self):
|
def last_revision(self):
|
||||||
@ -423,10 +429,10 @@ class CustomTree():
|
|||||||
changes = []
|
changes = []
|
||||||
|
|
||||||
def get_parent(dirname, basename):
|
def get_parent(dirname, basename):
|
||||||
parent_fid = self.base_files.get(dirname, None)
|
parent_fid, mark = self.base_files.get(dirname, [None, None])
|
||||||
if parent_fid:
|
if parent_fid:
|
||||||
return parent_fid
|
return parent_fid
|
||||||
parent_fid = self.files.get(dirname, None)
|
parent_fid, mark = self.files.get(dirname, [None, None])
|
||||||
if parent_fid:
|
if parent_fid:
|
||||||
return parent_fid
|
return parent_fid
|
||||||
if basename == '':
|
if basename == '':
|
||||||
@ -453,7 +459,7 @@ class CustomTree():
|
|||||||
(None, basename),
|
(None, basename),
|
||||||
(None, kind),
|
(None, kind),
|
||||||
(None, executable))
|
(None, executable))
|
||||||
self.files[path] = change[0]
|
self.files[path] = [change[0], None]
|
||||||
changes.append(change)
|
changes.append(change)
|
||||||
|
|
||||||
def update_entry(fid, path, kind, mode = None):
|
def update_entry(fid, path, kind, mode = None):
|
||||||
@ -474,7 +480,7 @@ class CustomTree():
|
|||||||
(None, basename),
|
(None, basename),
|
||||||
(None, kind),
|
(None, kind),
|
||||||
(None, executable))
|
(None, executable))
|
||||||
self.files[path] = change[0]
|
self.files[path] = [change[0], None]
|
||||||
changes.append(change)
|
changes.append(change)
|
||||||
|
|
||||||
def remove_entry(fid, path, kind):
|
def remove_entry(fid, path, kind):
|
||||||
@ -503,16 +509,23 @@ class CustomTree():
|
|||||||
else:
|
else:
|
||||||
add_entry(fid, path, 'file', f['mode'])
|
add_entry(fid, path, 'file', f['mode'])
|
||||||
|
|
||||||
|
self.files[path][1] = f['mark']
|
||||||
|
self.rev_files[fid][1] = f['mark']
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
def get_file_with_stat(self, file_id, path=None):
|
def get_file_with_stat(self, file_id, path=None):
|
||||||
mark = self.updates[file_id]['mark']
|
path, mark = self.rev_files[file_id]
|
||||||
return (StringIO.StringIO(blob_marks[mark]), None)
|
return (StringIO.StringIO(blob_marks[mark]), None)
|
||||||
|
|
||||||
def get_symlink_target(self, file_id):
|
def get_symlink_target(self, file_id):
|
||||||
mark = self.updates[file_id]['mark']
|
path, mark = self.rev_files[file_id]
|
||||||
return blob_marks[mark]
|
return blob_marks[mark]
|
||||||
|
|
||||||
|
def id2path(self, file_id):
|
||||||
|
path, mark = self.rev_files[file_id]
|
||||||
|
return path
|
||||||
|
|
||||||
def c_style_unescape(string):
|
def c_style_unescape(string):
|
||||||
if string[0] == string[-1] == '"':
|
if string[0] == string[-1] == '"':
|
||||||
return string.decode('string-escape')[1:-1]
|
return string.decode('string-escape')[1:-1]
|
||||||
|
@ -228,4 +228,40 @@ test_expect_success 'push utf-8 filenames' '
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'pushing a merge' '
|
||||||
|
mkdir -p tmp && cd tmp &&
|
||||||
|
test_when_finished "cd .. && rm -rf tmp" &&
|
||||||
|
|
||||||
|
(
|
||||||
|
bzr init bzrrepo &&
|
||||||
|
cd bzrrepo &&
|
||||||
|
echo one > content &&
|
||||||
|
bzr add content &&
|
||||||
|
bzr commit -m one
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git clone "bzr::$PWD/bzrrepo" gitrepo &&
|
||||||
|
|
||||||
|
(
|
||||||
|
cd bzrrepo &&
|
||||||
|
echo two > content &&
|
||||||
|
bzr commit -m two
|
||||||
|
) &&
|
||||||
|
|
||||||
|
(
|
||||||
|
cd gitrepo &&
|
||||||
|
echo three > content &&
|
||||||
|
git commit -a -m three &&
|
||||||
|
git fetch &&
|
||||||
|
git merge origin/master || true &&
|
||||||
|
echo three > content &&
|
||||||
|
git commit -a --no-edit &&
|
||||||
|
git push
|
||||||
|
) &&
|
||||||
|
|
||||||
|
echo three > expected &&
|
||||||
|
cat bzrrepo/content > actual &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user