##// END OF EJS Templates
vcs: change way refs are retrieved for git so same name branch/tags...
dan -
r784:2cdc0863 default
parent child Browse files
Show More
@@ -98,7 +98,7 b' class GitInMemoryCommit(base.BaseInMemor'
98 98 self.repository._rebuild_cache(self.repository.commit_ids)
99 99
100 100 # invalidate parsed refs after commit
101 self.repository._parsed_refs = self.repository._get_parsed_refs()
101 self.repository._refs = self.repository._get_refs()
102 102 self.repository.branches = self.repository._get_branches()
103 103 tip = self.repository.get_commit()
104 104 self.reset()
@@ -205,12 +205,6 b' class GitRepository(BaseRepository):'
205 205 return []
206 206 return output.splitlines()
207 207
208 def _get_all_commit_ids2(self):
209 # alternate implementation
210 includes = [x[1][0] for x in self._parsed_refs.iteritems()
211 if x[1][1] != 'T']
212 return [c.commit.id for c in self._remote.get_walker(include=includes)]
213
214 208 def _get_commit_id(self, commit_id_or_idx):
215 209 def is_null(value):
216 210 return len(value) == commit_id_or_idx.count('0')
@@ -232,17 +226,23 b' class GitRepository(BaseRepository):'
232 226 raise CommitDoesNotExistError(msg)
233 227
234 228 elif is_bstr:
235 # get by branch/tag name
236 ref_id = self._parsed_refs.get(commit_id_or_idx)
237 if ref_id: # and ref_id[1] in ['H', 'RH', 'T']:
238 return ref_id[0]
229 # check full path ref, eg. refs/heads/master
230 ref_id = self._refs.get(commit_id_or_idx)
231 if ref_id:
232 return ref_id
239 233
240 tag_ids = self.tags.values()
241 # maybe it's a tag ? we don't have them in self.commit_ids
242 if commit_id_or_idx in tag_ids:
243 return commit_id_or_idx
234 # check branch name
235 branch_ids = self.branches.values()
236 ref_id = self._refs.get('refs/heads/%s' % commit_id_or_idx)
237 if ref_id:
238 return ref_id
244 239
245 elif (not SHA_PATTERN.match(commit_id_or_idx) or
240 # check tag name
241 ref_id = self._refs.get('refs/tags/%s' % commit_id_or_idx)
242 if ref_id:
243 return ref_id
244
245 if (not SHA_PATTERN.match(commit_id_or_idx) or
246 246 commit_id_or_idx not in self.commit_ids):
247 247 msg = "Commit %s does not exist for %s" % (
248 248 commit_id_or_idx, self)
@@ -289,20 +289,25 b' class GitRepository(BaseRepository):'
289 289 description = self._remote.get_description()
290 290 return safe_unicode(description or self.DEFAULT_DESCRIPTION)
291 291
292 def _get_refs_entry(self, value, reverse):
292 def _get_refs_entries(self, prefix='', reverse=False, strip_prefix=True):
293 293 if self.is_empty():
294 return {}
294 return OrderedDict()
295 295
296 def get_name(ctx):
297 return ctx[0]
296 result = []
297 for ref, sha in self._refs.iteritems():
298 if ref.startswith(prefix):
299 ref_name = ref
300 if strip_prefix:
301 ref_name = ref[len(prefix):]
302 result.append((safe_unicode(ref_name), sha))
298 303
299 _branches = [
300 (safe_unicode(x[0]), x[1][0])
301 for x in self._parsed_refs.iteritems() if x[1][1] == value]
302 return OrderedDict(sorted(_branches, key=get_name, reverse=reverse))
304 def get_name(entry):
305 return entry[0]
306
307 return OrderedDict(sorted(result, key=get_name, reverse=reverse))
303 308
304 309 def _get_branches(self):
305 return self._get_refs_entry('H', False)
310 return self._get_refs_entries(prefix='refs/heads/', strip_prefix=True)
306 311
307 312 @LazyProperty
308 313 def branches(self):
@@ -324,10 +329,12 b' class GitRepository(BaseRepository):'
324 329 return self._get_tags()
325 330
326 331 def _get_tags(self):
327 return self._get_refs_entry('T', True)
332 return self._get_refs_entries(
333 prefix='refs/tags/', strip_prefix=True, reverse=True)
328 334
329 335 def tag(self, name, user, commit_id=None, message=None, date=None,
330 336 **kwargs):
337 # TODO: fix this method to apply annotated tags correct with message
331 338 """
332 339 Creates and returns a tag for the given ``commit_id``.
333 340
@@ -346,7 +353,7 b' class GitRepository(BaseRepository):'
346 353 name, commit.raw_id)
347 354 self._remote.set_refs('refs/tags/%s' % name, commit._commit['id'])
348 355
349 self._parsed_refs = self._get_parsed_refs()
356 self._refs = self._get_refs()
350 357 self.tags = self._get_tags()
351 358 return commit
352 359
@@ -367,24 +374,28 b' class GitRepository(BaseRepository):'
367 374 self._remote.get_refs_path(), 'refs', 'tags', name)
368 375 try:
369 376 os.remove(tagpath)
370 self._parsed_refs = self._get_parsed_refs()
377 self._refs = self._get_refs()
371 378 self.tags = self._get_tags()
372 379 except OSError as e:
373 380 raise RepositoryError(e.strerror)
374 381
382 def _get_refs(self):
383 return self._remote.get_refs()
384
375 385 @LazyProperty
376 def _parsed_refs(self):
377 return self._get_parsed_refs()
386 def _refs(self):
387 return self._get_refs()
378 388
379 def _get_parsed_refs(self):
380 # TODO: (oliver) who needs RH; branches?
381 # Remote Heads were commented out, as they may overwrite local branches
382 # See the TODO note in rhodecode.lib.vcs.remote.git:get_refs for more
383 # details.
384 keys = [('refs/heads/', 'H'),
385 #('refs/remotes/origin/', 'RH'),
386 ('refs/tags/', 'T')]
387 return self._remote.get_refs(keys=keys)
389 @property
390 def _ref_tree(self):
391 node = tree = {}
392 for ref, sha in self._refs.iteritems():
393 path = ref.split('/')
394 for bit in path[:-1]:
395 node = node.setdefault(bit, {})
396 node[path[-1]] = sha
397 node = tree
398 return tree
388 399
389 400 def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
390 401 """
@@ -934,20 +934,34 b' class TestGitCommit(object):'
934 934 'vcs/nodes.py']
935 935 assert set(changed) == set([f.path for f in commit.changed])
936 936
937 def test_unicode_refs(self):
937 def test_unicode_branch_refs(self):
938 938 unicode_branches = {
939 'unicode': ['6c0ce52b229aa978889e91b38777f800e85f330b', 'H'],
940 u'uniçö∂e': ['ürl', 'H']
939 'refs/heads/unicode': '6c0ce52b229aa978889e91b38777f800e85f330b',
940 u'refs/heads/uniçö∂e': 'ürl',
941 941 }
942 942 with mock.patch(
943 943 ("rhodecode.lib.vcs.backends.git.repository"
944 ".GitRepository._parsed_refs"),
944 ".GitRepository._refs"),
945 945 unicode_branches):
946 946 branches = self.repo.branches
947 947
948 948 assert 'unicode' in branches
949 949 assert u'uniçö∂e' in branches
950 950
951 def test_unicode_tag_refs(self):
952 unicode_tags = {
953 'refs/tags/unicode': '6c0ce52b229aa978889e91b38777f800e85f330b',
954 u'refs/tags/uniçö∂e': '6c0ce52b229aa978889e91b38777f800e85f330b',
955 }
956 with mock.patch(
957 ("rhodecode.lib.vcs.backends.git.repository"
958 ".GitRepository._refs"),
959 unicode_tags):
960 tags = self.repo.tags
961
962 assert 'unicode' in tags
963 assert u'uniçö∂e' in tags
964
951 965 def test_commit_message_is_unicode(self):
952 966 for commit in self.repo:
953 967 assert type(commit.message) == unicode
General Comments 0
You need to be logged in to leave comments. Login now