Skip to content

Commit f38dfc4

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 715d64f commit f38dfc4

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

contrib/remote-helpers/git-remote-bzr

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class CustomTree():
393393
tree = repo.repository.revision_tree(revid)
394394
try:
395395
for path, entry in tree.iter_entries_by_dir():
396-
files[path] = entry.file_id
396+
files[path] = [entry.file_id, None]
397397
finally:
398398
repo.unlock()
399399
return files
@@ -408,12 +408,18 @@ class CustomTree():
408408
self.base_files = copy_tree(self.base_id)
409409

410410
self.files = files_cache[revid] = self.base_files.copy()
411+
self.rev_files = {}
412+
413+
for path, data in self.files.iteritems():
414+
fid, mark = data
415+
self.rev_files[fid] = [path, mark]
411416

412417
for path, f in files.iteritems():
413-
fid = self.files.get(path, None)
418+
fid, mark = self.files.get(path, [None, None])
414419
if not fid:
415420
fid = bzrlib.generate_ids.gen_file_id(path)
416421
f['path'] = path
422+
self.rev_files[fid] = [path, mark]
417423
self.updates[fid] = f
418424

419425
def last_revision(self):
@@ -423,10 +429,10 @@ class CustomTree():
423429
changes = []
424430

425431
def get_parent(dirname, basename):
426-
parent_fid = self.base_files.get(dirname, None)
432+
parent_fid, mark = self.base_files.get(dirname, [None, None])
427433
if parent_fid:
428434
return parent_fid
429-
parent_fid = self.files.get(dirname, None)
435+
parent_fid, mark = self.files.get(dirname, [None, None])
430436
if parent_fid:
431437
return parent_fid
432438
if basename == '':
@@ -453,7 +459,7 @@ class CustomTree():
453459
(None, basename),
454460
(None, kind),
455461
(None, executable))
456-
self.files[path] = change[0]
462+
self.files[path] = [change[0], None]
457463
changes.append(change)
458464

459465
def update_entry(fid, path, kind, mode = None):
@@ -474,7 +480,7 @@ class CustomTree():
474480
(None, basename),
475481
(None, kind),
476482
(None, executable))
477-
self.files[path] = change[0]
483+
self.files[path] = [change[0], None]
478484
changes.append(change)
479485

480486
def remove_entry(fid, path, kind):
@@ -503,16 +509,23 @@ class CustomTree():
503509
else:
504510
add_entry(fid, path, 'file', f['mode'])
505511

512+
self.files[path][1] = f['mark']
513+
self.rev_files[fid][1] = f['mark']
514+
506515
return changes
507516

508517
def get_file_with_stat(self, file_id, path=None):
509-
mark = self.updates[file_id]['mark']
518+
path, mark = self.rev_files[file_id]
510519
return (StringIO.StringIO(blob_marks[mark]), None)
511520

512521
def get_symlink_target(self, file_id):
513-
mark = self.updates[file_id]['mark']
522+
path, mark = self.rev_files[file_id]
514523
return blob_marks[mark]
515524

525+
def id2path(self, file_id):
526+
path, mark = self.rev_files[file_id]
527+
return path
528+
516529
def c_style_unescape(string):
517530
if string[0] == string[-1] == '"':
518531
return string.decode('string-escape')[1:-1]

contrib/remote-helpers/test-bzr.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,40 @@ test_expect_success 'push utf-8 filenames' '
228228
test_cmp expected actual
229229
'
230230

231+
test_expect_success 'pushing a merge' '
232+
mkdir -p tmp && cd tmp &&
233+
test_when_finished "cd .. && rm -rf tmp" &&
234+
235+
(
236+
bzr init bzrrepo &&
237+
cd bzrrepo &&
238+
echo one > content &&
239+
bzr add content &&
240+
bzr commit -m one
241+
) &&
242+
243+
git clone "bzr::$PWD/bzrrepo" gitrepo &&
244+
245+
(
246+
cd bzrrepo &&
247+
echo two > content &&
248+
bzr commit -m two
249+
) &&
250+
251+
(
252+
cd gitrepo &&
253+
echo three > content &&
254+
git commit -a -m three &&
255+
git fetch &&
256+
git merge origin/master || true &&
257+
echo three > content &&
258+
git commit -a --no-edit &&
259+
git push
260+
) &&
261+
262+
echo three > expected &&
263+
cat bzrrepo/content > actual &&
264+
test_cmp expected actual
265+
'
266+
231267
test_done

0 commit comments

Comments
 (0)