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