changeset 773:03e1e9929dea

hgrepo: move remote ref loading to git_handler The writing out is in the git handler, so the loading should be too.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 03 Sep 2014 19:46:42 +0200
parents 7e6cea0fe257
children 55887ce9fb98
files hggit/git_handler.py hggit/hgrepo.py
diffstat 2 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -114,6 +114,7 @@
         self._map_git_real = None
         self._map_hg_real = None
         self.load_tags()
+        self._remote_refs = None
 
     @property
     def _map_git(self):
@@ -127,6 +128,12 @@
         self.load_map()
       return self._map_hg_real
 
+    @property
+    def remote_refs(self):
+        if self._remote_refs is None:
+            self.load_remote_refs()
+        return self._remote_refs
+
     @hgutil.propertycache
     def git(self):
         # make the git data directory
@@ -190,6 +197,15 @@
         # If this complains, atomictempfile no longer has close
         file.close()
 
+    def load_remote_refs(self):
+        self._remote_refs = {}
+        tagfile = self.repo.join(self.remote_refs_file)
+        if os.path.exists(tagfile):
+            tf = open(tagfile, 'rb')
+            tagdata = tf.read().split('\n')
+            td = [line.split(' ', 1) for line in tagdata if line]
+            self._remote_refs.update([(name, bin(sha)) for sha, name in td])
+
     ## END FILE LOAD AND SAVE METHODS
 
     ## COMMANDS METHODS
@@ -1242,7 +1258,7 @@
 
     def update_remote_branches(self, remote_name, refs):
         tagfile = self.repo.join(self.remote_refs_file)
-        tags = self.repo.gitrefs()
+        tags = self.remote_refs
         # since we re-write all refs for this remote each time, prune
         # all entries matching this remote from our tags list now so
         # that we avoid any stale refs hanging around forever
--- a/hggit/hgrepo.py
+++ b/hggit/hgrepo.py
@@ -50,7 +50,7 @@
                 tags[tag] = bin(rev)
                 tagtypes[tag] = 'git'
 
-            tags.update(self.gitrefs())
+            tags.update(self.githandler.remote_refs)
             return (tags, tagtypes)
 
         @util.propertycache
@@ -61,19 +61,10 @@
             '''
             return GitHandler(self, self.ui)
 
-        def gitrefs(self):
-            tagfile = self.join(GitHandler.remote_refs_file)
-            if os.path.exists(tagfile):
-                tf = open(tagfile, 'rb')
-                tagdata = tf.read().split('\n')
-                td = [line.split(' ', 1) for line in tagdata if line]
-                return dict([(name, bin(sha)) for sha, name in td])
-            return {}
-
         def tags(self):
             # TODO consider using self._tagscache
             tagscache = super(hgrepo, self).tags()
-            tagscache.update(self.gitrefs())
+            tagscache.update(self.githandler.remote_refs)
             for tag, rev in self.githandler.tags.iteritems():
                 if tag in tagscache:
                     continue