git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 05/18] remote-bzr: add support to push merges

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 1, 2013, 01:09 UTC
Message-ID
<1367370610-14250-6-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1367370610-14250-1-git-send-email-felipe.contreras@gmail.com>

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>
---
 contrib/remote-helpers/git-remote-bzr | 29 ++++++++++++++++++++--------
 contrib/remote-helpers/test-bzr.sh    | 36 +++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index eb91d28..6a7f836 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -393,7 +393,7 @@ class CustomTree():
             tree = repo.repository.revision_tree(revid)
             try:
                 for path, entry in tree.iter_entries_by_dir():
-                    files[path] = entry.file_id
+                    files[path] = [entry.file_id, None]
             finally:
                 repo.unlock()
             return files
@@ -408,12 +408,18 @@ class CustomTree():
                 self.base_files = copy_tree(self.base_id)
 
         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():
-            fid = self.files.get(path, None)
+            fid, mark = self.files.get(path, [None, None])
             if not fid:
                 fid = bzrlib.generate_ids.gen_file_id(path)
             f['path'] = path
+            self.rev_files[fid] = [path, mark]
             self.updates[fid] = f
 
     def last_revision(self):
@@ -423,10 +429,10 @@ class CustomTree():
         changes = []
 
         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:
                 return parent_fid
-            parent_fid = self.files.get(dirname, None)
+            parent_fid, mark = self.files.get(dirname, [None, None])
             if parent_fid:
                 return parent_fid
             if basename == '':
@@ -453,7 +459,7 @@ class CustomTree():
                     (None, basename),
                     (None, kind),
                     (None, executable))
-            self.files[path] = change[0]
+            self.files[path] = [change[0], None]
             changes.append(change)
 
         def update_entry(fid, path, kind, mode = None):
@@ -474,7 +480,7 @@ class CustomTree():
                     (None, basename),
                     (None, kind),
                     (None, executable))
-            self.files[path] = change[0]
+            self.files[path] = [change[0], None]
             changes.append(change)
 
         def remove_entry(fid, path, kind):
@@ -503,16 +509,23 @@ class CustomTree():
             else:
                 add_entry(fid, path, 'file', f['mode'])
 
+            self.files[path][1] = f['mark']
+            self.rev_files[fid][1] = f['mark']
+
         return changes
 
     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)
 
     def get_symlink_target(self, file_id):
-        mark = self.updates[file_id]['mark']
+        path, mark = self.rev_files[file_id]
         return blob_marks[mark]
 
+    def id2path(self, file_id):
+        path, mark = self.rev_files[file_id]
+        return path
+
 def c_style_unescape(string):
     if string[0] == string[-1] == '"':
         return string.decode('string-escape')[1:-1]
diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh
index 34666e1..eca3476 100755
--- a/contrib/remote-helpers/test-bzr.sh
+++ b/contrib/remote-helpers/test-bzr.sh
@@ -228,4 +228,40 @@ test_expect_success 'push utf-8 filenames' '
   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
-- 
1.8.3.rc0.399.gc96a135
Previous: Felipe ContrerasNext: Felipe Contreras
Message 6 of 25 in “remote-bzr: massive changes”
  1. 00/18 remote-bzr: massive changesFelipe Contreras, May 1, 2013
  2. 01/18 remote-bzr: cleanup CustomTreeFelipe Contreras, May 1, 2013
  3. 02/18 remote-bzr: delay blob fetching until the very endFelipe Contreras, May 1, 2013
  4. 03/18 remote-bzr: fix order of locking in CustomTreeFelipe Contreras, May 1, 2013
  5. 04/18 remote-bzr: always try to update the worktreeFelipe Contreras, May 1, 2013
  6. 05/18 remote-bzr: add support to push mergesFelipe Contreras, May 1, 2013
  7. 06/18 remote-bzr: fixes for branch divergeFelipe Contreras, May 1, 2013
  8. 07/18 remote-bzr: fix partially pushed mergeFelipe Contreras, May 1, 2013
  9. 08/18 remote-bzr: use branch variable when appropriateFelipe Contreras, May 1, 2013
  10. 09/18 remote-bzr: add support for bzr reposFelipe Contreras, May 1, 2013
  11. 10/18 remote-bzr: fix branch namesFelipe Contreras, May 1, 2013
  12. 11/18 remote-bzr: add support for shared repoFelipe Contreras, May 1, 2013
  13. 12/18 remote-bzr: improve author sanitazionFelipe Contreras, May 1, 2013
  14. 13/18 remote-bzr: add custom method to find branchesFelipe Contreras, May 1, 2013
  15. 14/18 remote-bzr: add option to specify branchesFelipe Contreras, May 1, 2013
  16. 15/18 remote-bzr: improve progress reportingFelipe Contreras, May 1, 2013
  17. 16/18 remote-bzr: iterate revisions properlyFelipe Contreras, May 1, 2013
  18. 17/18 remote-bzr: delay peer branch usageFelipe Contreras, May 1, 2013
  19. 18/18 remote-bzr: access branches only when neededFelipe Contreras, May 1, 2013
  20. Junio C HamanoMay 1, 2013
  21. Felipe ContrerasMay 1, 2013
  22. Junio C HamanoMay 1, 2013
  23. Felipe ContrerasMay 1, 2013
  24. Junio C HamanoMay 1, 2013
  25. Ted ZlatanovJan 3, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.