[PATCH 12/20] remote-bzr: split marks file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This way all the remotes can share the same git objects, and the same
marks. The information we want to store per remote is very small.

The code transparently converts from one organization of marks, to the
other. It's rather smooth and there shouldn't be any issues.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 contrib/remote-helpers/git-remote-bzr | 58 ++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 9fe830e..fcd8e41 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -52,22 +52,42 @@ def gittz(tz):
 
 class Marks:
 
-    def __init__(self, path):
-        self.path = path
+    def __init__(self, gitdir, dirname):
+        self.marks_path = os.path.join(gitdir, 'bzr', '.marks-bzr')
+        self.remote_path = os.path.join(dirname, '.marks-bzr')
+        old_path = os.path.join(dirname, 'marks-int')
+
         self.tips = {}
         self.marks = {}
         self.rev_marks = {}
         self.last_mark = 0
-        self.load()
+
+        if not os.path.exists(old_path):
+            self.load()
+        else:
+            self.old_load(old_path)
+            os.remove(old_path)
 
     def load(self):
-        if not os.path.exists(self.path):
-            return
 
-        tmp = json.load(open(self.path))
+        if os.path.exists(self.marks_path):
+            tmp = json.load(open(self.marks_path))
+            self.marks = tmp['marks']
+            self.last_mark = tmp['last-mark']
+
+            for rev, mark in self.marks.iteritems():
+                self.rev_marks[mark] = rev
+
+        if os.path.exists(self.remote_path):
+            tmp = json.load(open(self.remote_path))
+            self.tips = tmp['tips']
+
+    def old_load(self, path):
+
+        tmp = json.load(open(path))
         self.tips = tmp['tips']
-        self.marks = tmp['marks']
-        self.last_mark = tmp['last-mark']
+        self.marks = tmp['marks'] # TODO remove
+        self.last_mark = tmp['last-mark'] # TODO remove
 
         for rev, mark in self.marks.iteritems():
             self.rev_marks[mark] = rev
@@ -76,7 +96,10 @@ class Marks:
         return { 'tips': self.tips, 'marks': self.marks, 'last-mark' : self.last_mark }
 
     def store(self):
-        json.dump(self.dict(), open(self.path, 'w'))
+        d = { 'marks': self.marks, 'last-mark' : self.last_mark }
+        json.dump(d, open(self.marks_path, 'w'))
+        d = { 'tips': self.tips }
+        json.dump(d, open(self.remote_path, 'w'))
 
     def __str__(self):
         return str(self.dict())
@@ -348,10 +371,10 @@ def export_tag(repo, name):
     print
 
 def do_import(parser):
-    global dirname
+    global gitdir
 
     repo = parser.repo
-    path = os.path.join(dirname, 'marks-git')
+    path = os.path.join(gitdir, 'bzr', '.marks-git')
 
     print "feature done"
     if os.path.exists(path):
@@ -678,14 +701,14 @@ def do_export(parser):
     print
 
 def do_capabilities(parser):
-    global dirname
+    global gitdir
 
     print "import"
     print "export"
     print "refspec refs/heads/*:%s/heads/*" % prefix
     print "refspec refs/tags/*:%s/tags/*" % prefix
 
-    path = os.path.join(dirname, 'marks-git')
+    path = os.path.join(gitdir, 'bzr', '.marks-git')
 
     if os.path.exists(path):
         print "*import-marks %s" % path
@@ -848,8 +871,13 @@ def main(args):
 
     repo = get_repo(url, alias)
 
-    marks_path = os.path.join(dirname, 'marks-int')
-    marks = Marks(marks_path)
+    marks = Marks(gitdir, dirname)
+
+    # move old marks
+    old_gitmarks = os.path.join(dirname, 'marks-git')
+    new_gitmarks = os.path.join(gitdir, 'bzr', '.marks-git')
+    if os.path.exists(old_gitmarks):
+        os.rename(old_gitmarks, new_gitmarks)
 
     parser = Parser(repo)
     for line in parser:
-- 
1.8.2.1.884.g3532a8d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]