changeset 812:256a232e689d

git_handler: add a way to get all heads that can be exported to Git This is a replacement for local_heads and code duplication around it. Centralizing all this logic also makes it much easier for extensions to define other sorts of refs.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 29 Oct 2014 11:56:31 -0700
parents 2806bcabd896
children 2e77e332f3b3
files hggit/git_handler.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1,4 +1,4 @@
-import os, math, urllib, urllib2, re
+import collections, itertools, os, math, urllib, urllib2, re
 import stat, posixpath, StringIO
 
 from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
@@ -1123,6 +1123,25 @@
                     return bm
             return [(_filter_bm(bm), bm) for bm in bms]
 
+    def get_exportable(self):
+        class heads_tags(object):
+            def __init__(self):
+                self.heads = set()
+                self.tags = set()
+            def __iter__(self):
+                return itertools.chain(self.heads, self.tags)
+            def __nonzero__(self):
+                return bool(self.heads) or bool(self.tags)
+
+        res = collections.defaultdict(heads_tags)
+
+        bms = self.repo._bookmarks
+        for filtered_bm, bm in self._filter_for_bookmarks(bms):
+            res[hex(bms[bm])].heads.add('refs/heads/' + filtered_bm)
+        for tag, sha in self.tags.iteritems():
+            res[sha].tags.add('refs/tags/' + tag)
+        return res
+
     def local_heads(self):
         bms = self.repo._bookmarks
         return dict((filtered_bm, ('refs/heads/' + filtered_bm, hex(bms[bm])))