comparison hggit/git_handler.py @ 819:2c5e41d670b5

git_handler: return filtered refs as an OrderedDict This actually has no direct impact here, but it allows extensions to customize the list of filtered refs and be sure of the order in which they'll be processed.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 31 Oct 2014 10:40:58 -0700
parents bfe8c8e0d29c
children 826296785e8b
comparison
equal deleted inserted replaced
818:bfe8c8e0d29c 819:2c5e41d670b5
1045 def filter_refs(self, refs, heads): 1045 def filter_refs(self, refs, heads):
1046 '''For a dictionary of refs: shas, if heads is None then return refs 1046 '''For a dictionary of refs: shas, if heads is None then return refs
1047 that match the heads. Otherwise, return refs that are heads or tags. 1047 that match the heads. Otherwise, return refs that are heads or tags.
1048 1048
1049 ''' 1049 '''
1050 filteredrefs = {} 1050 filteredrefs = []
1051 if heads is not None: 1051 if heads is not None:
1052 # contains pairs of ('refs/(heads|tags|...)/foo', 'foo') 1052 # contains pairs of ('refs/(heads|tags|...)/foo', 'foo')
1053 # if ref is just '<foo>', then we get ('foo', 'foo') 1053 # if ref is just '<foo>', then we get ('foo', 'foo')
1054 stripped_refs = [ 1054 stripped_refs = [
1055 (r, r[r.find('/', r.find('/')+1)+1:]) 1055 (r, r[r.find('/', r.find('/')+1)+1:])
1057 for h in heads: 1057 for h in heads:
1058 r = [pair[0] for pair in stripped_refs if pair[1] == h] 1058 r = [pair[0] for pair in stripped_refs if pair[1] == h]
1059 if not r: 1059 if not r:
1060 raise hgutil.Abort("ref %s not found on remote server" % h) 1060 raise hgutil.Abort("ref %s not found on remote server" % h)
1061 elif len(r) == 1: 1061 elif len(r) == 1:
1062 filteredrefs[r[0]] = refs[r[0]] 1062 filteredrefs.append(r[0])
1063 else: 1063 else:
1064 raise hgutil.Abort("ambiguous reference %s: %r" % (h, r)) 1064 raise hgutil.Abort("ambiguous reference %s: %r" % (h, r))
1065 else: 1065 else:
1066 for ref, sha in refs.iteritems(): 1066 for ref, sha in refs.iteritems():
1067 if (not ref.endswith('^{}') 1067 if (not ref.endswith('^{}')
1068 and (ref.startswith('refs/heads/') 1068 and (ref.startswith('refs/heads/')
1069 or ref.startswith('refs/tags/'))): 1069 or ref.startswith('refs/tags/'))):
1070 filteredrefs[ref] = sha 1070 filteredrefs.append(ref)
1071 return filteredrefs 1071
1072 # the choice of OrderedDict vs plain dict has no impact on stock hg-git,
1073 # but allows extensions to customize the order in which refs are
1074 # returned
1075 return util.OrderedDict((r, refs[r]) for r in filteredrefs)
1072 1076
1073 def update_references(self): 1077 def update_references(self):
1074 exportable = self.get_exportable() 1078 exportable = self.get_exportable()
1075 1079
1076 # Create a local Git branch name for each 1080 # Create a local Git branch name for each