Show More
@@ -105,10 +105,9 b' class RepoCommitsView(RepoAppView):' | |||
|
105 | 105 | |
|
106 | 106 | c.commit_ranges = commits |
|
107 | 107 | if not c.commit_ranges: |
|
108 | raise RepositoryError( | |
|
109 | 'The commit range returned an empty result') | |
|
110 | except CommitDoesNotExistError: | |
|
111 | msg = _('No such commit exists for this repository') | |
|
108 | raise RepositoryError('The commit range returned an empty result') | |
|
109 | except CommitDoesNotExistError as e: | |
|
110 | msg = _('No such commit exists. Org exception: `{}`').format(e) | |
|
112 | 111 | h.flash(msg, category='error') |
|
113 | 112 | raise HTTPNotFound() |
|
114 | 113 | except Exception: |
@@ -94,8 +94,9 b' class GitInMemoryCommit(base.BaseInMemor' | |||
|
94 | 94 | commit_data, branch, commit_tree, updated, removed) |
|
95 | 95 | |
|
96 | 96 | # Update vcs repository object |
|
97 |
self.repository.commit_ids |
|
|
98 | self.repository._rebuild_cache(self.repository.commit_ids) | |
|
97 | if commit_id not in self.repository.commit_ids: | |
|
98 | self.repository.commit_ids.append(commit_id) | |
|
99 | self.repository._rebuild_cache(self.repository.commit_ids) | |
|
99 | 100 | |
|
100 | 101 | # invalidate parsed refs after commit |
|
101 | 102 | self.repository._refs = self.repository._get_refs() |
@@ -222,13 +222,10 b' class GitRepository(BaseRepository):' | |||
|
222 | 222 | return [] |
|
223 | 223 | return output.splitlines() |
|
224 | 224 | |
|
225 |
def _ |
|
|
225 | def _lookup_commit(self, commit_id_or_idx, translate_tag=True): | |
|
226 | 226 | def is_null(value): |
|
227 | 227 | return len(value) == commit_id_or_idx.count('0') |
|
228 | 228 | |
|
229 | if self.is_empty(): | |
|
230 | raise EmptyRepositoryError("There are no commits yet") | |
|
231 | ||
|
232 | 229 | if commit_id_or_idx in (None, '', 'tip', 'HEAD', 'head', -1): |
|
233 | 230 | return self.commit_ids[-1] |
|
234 | 231 | |
@@ -238,8 +235,7 b' class GitRepository(BaseRepository):' | |||
|
238 | 235 | try: |
|
239 | 236 | commit_id_or_idx = self.commit_ids[int(commit_id_or_idx)] |
|
240 | 237 | except Exception: |
|
241 | msg = "Commit %s does not exist for %s" % ( | |
|
242 | commit_id_or_idx, self) | |
|
238 | msg = "Commit %s does not exist for %s" % (commit_id_or_idx, self.name) | |
|
243 | 239 | raise CommitDoesNotExistError(msg) |
|
244 | 240 | |
|
245 | 241 | elif is_bstr: |
@@ -261,8 +257,7 b' class GitRepository(BaseRepository):' | |||
|
261 | 257 | |
|
262 | 258 | if (not SHA_PATTERN.match(commit_id_or_idx) or |
|
263 | 259 | commit_id_or_idx not in self.commit_ids): |
|
264 | msg = "Commit %s does not exist for %s" % ( | |
|
265 | commit_id_or_idx, self) | |
|
260 | msg = "Commit %s does not exist for %s" % (commit_id_or_idx, self.name) | |
|
266 | 261 | raise CommitDoesNotExistError(msg) |
|
267 | 262 | |
|
268 | 263 | # Ensure we return full id |
@@ -431,19 +426,42 b' class GitRepository(BaseRepository):' | |||
|
431 | 426 | Returns `GitCommit` object representing commit from git repository |
|
432 | 427 | at the given `commit_id` or head (most recent commit) if None given. |
|
433 | 428 | """ |
|
429 | if self.is_empty(): | |
|
430 | raise EmptyRepositoryError("There are no commits yet") | |
|
431 | ||
|
434 | 432 | if commit_id is not None: |
|
435 | 433 | self._validate_commit_id(commit_id) |
|
434 | try: | |
|
435 | # we have cached idx, use it without contacting the remote | |
|
436 | idx = self._commit_ids[commit_id] | |
|
437 | return GitCommit(self, commit_id, idx, pre_load=pre_load) | |
|
438 | except KeyError: | |
|
439 | pass | |
|
440 | ||
|
436 | 441 | elif commit_idx is not None: |
|
437 | 442 | self._validate_commit_idx(commit_idx) |
|
438 | commit_id = commit_idx | |
|
439 |
commit_id = self. |
|
|
443 | try: | |
|
444 | _commit_id = self.commit_ids[commit_idx] | |
|
445 | if commit_idx < 0: | |
|
446 | commit_idx = self.commit_ids.index(_commit_id) | |
|
447 | return GitCommit(self, _commit_id, commit_idx, pre_load=pre_load) | |
|
448 | except IndexError: | |
|
449 | commit_id = commit_idx | |
|
450 | else: | |
|
451 | commit_id = "tip" | |
|
452 | ||
|
453 | commit_id = self._lookup_commit(commit_id) | |
|
454 | remote_idx = None | |
|
455 | if translate_tag: | |
|
456 | # Need to call remote to translate id for tagging scenario | |
|
457 | remote_data = self._remote.get_object(commit_id) | |
|
458 | commit_id = remote_data["commit_id"] | |
|
459 | remote_idx = remote_data["idx"] | |
|
460 | ||
|
440 | 461 | try: |
|
441 | if translate_tag: | |
|
442 | # Need to call remote to translate id for tagging scenario | |
|
443 | commit_id = self._remote.get_object(commit_id)["commit_id"] | |
|
444 | 462 | idx = self._commit_ids[commit_id] |
|
445 | 463 | except KeyError: |
|
446 | raise RepositoryError("Cannot get object with id %s" % commit_id) | |
|
464 | idx = remote_idx or 0 | |
|
447 | 465 | |
|
448 | 466 | return GitCommit(self, commit_id, idx, pre_load=pre_load) |
|
449 | 467 | |
@@ -472,6 +490,7 b' class GitRepository(BaseRepository):' | |||
|
472 | 490 | """ |
|
473 | 491 | if self.is_empty(): |
|
474 | 492 | raise EmptyRepositoryError("There are no commits yet") |
|
493 | ||
|
475 | 494 | self._validate_branch_name(branch_name) |
|
476 | 495 | |
|
477 | 496 | if start_id is not None: |
@@ -479,9 +498,9 b' class GitRepository(BaseRepository):' | |||
|
479 | 498 | if end_id is not None: |
|
480 | 499 | self._validate_commit_id(end_id) |
|
481 | 500 | |
|
482 |
start_raw_id = self._ |
|
|
501 | start_raw_id = self._lookup_commit(start_id) | |
|
483 | 502 | start_pos = self._commit_ids[start_raw_id] if start_id else None |
|
484 |
end_raw_id = self._ |
|
|
503 | end_raw_id = self._lookup_commit(end_id) | |
|
485 | 504 | end_pos = max(0, self._commit_ids[end_raw_id]) if end_id else None |
|
486 | 505 | |
|
487 | 506 | if None not in [start_id, end_id] and start_pos > end_pos: |
@@ -83,14 +83,15 b' class MercurialInMemoryCommit(BaseInMemo' | |||
|
83 | 83 | |
|
84 | 84 | date, tz = date_to_timestamp_plus_offset(date) |
|
85 | 85 | |
|
86 |
|
|
|
86 | commit_id = self.repository._remote.commitctx( | |
|
87 | 87 | message=message, parents=parent_ids, |
|
88 | 88 | commit_time=date, commit_timezone=tz, user=author, |
|
89 | 89 | files=self.get_paths(), extra=kwargs, removed=removed, |
|
90 | 90 | updated=updated) |
|
91 | if commit_id not in self.repository.commit_ids: | |
|
92 | self.repository.commit_ids.append(commit_id) | |
|
93 | self.repository._rebuild_cache(self.repository.commit_ids) | |
|
91 | 94 | |
|
92 | self.repository.commit_ids.append(new_id) | |
|
93 | self.repository._rebuild_cache(self.repository.commit_ids) | |
|
94 | 95 | self.repository.branches = self.repository._get_branches() |
|
95 | 96 | tip = self.repository.get_commit() |
|
96 | 97 | self.reset() |
@@ -425,18 +425,20 b' class MercurialRepository(BaseRepository' | |||
|
425 | 425 | if commit_id is not None: |
|
426 | 426 | self._validate_commit_id(commit_id) |
|
427 | 427 | try: |
|
428 | # we have cached idx, use it without contacting the remote | |
|
428 | 429 | idx = self._commit_ids[commit_id] |
|
429 | 430 | return MercurialCommit(self, commit_id, idx, pre_load=pre_load) |
|
430 | 431 | except KeyError: |
|
431 | 432 | pass |
|
433 | ||
|
432 | 434 | elif commit_idx is not None: |
|
433 | 435 | self._validate_commit_idx(commit_idx) |
|
434 | 436 | try: |
|
435 |
|
|
|
437 | _commit_id = self.commit_ids[commit_idx] | |
|
436 | 438 | if commit_idx < 0: |
|
437 |
commit_idx |
|
|
438 | return MercurialCommit( | |
|
439 |
|
|
|
439 | commit_idx = self.commit_ids.index(_commit_id) | |
|
440 | ||
|
441 | return MercurialCommit(self, _commit_id, commit_idx, pre_load=pre_load) | |
|
440 | 442 | except IndexError: |
|
441 | 443 | commit_id = commit_idx |
|
442 | 444 | else: |
@@ -448,8 +450,7 b' class MercurialRepository(BaseRepository' | |||
|
448 | 450 | try: |
|
449 | 451 | raw_id, idx = self._remote.lookup(commit_id, both=True) |
|
450 | 452 | except CommitDoesNotExistError: |
|
451 | msg = "Commit %s does not exist for %s" % ( | |
|
452 | commit_id, self) | |
|
453 | msg = "Commit %s does not exist for %s" % (commit_id, self.name) | |
|
453 | 454 | raise CommitDoesNotExistError(msg) |
|
454 | 455 | |
|
455 | 456 | return MercurialCommit(self, raw_id, idx, pre_load=pre_load) |
@@ -2437,6 +2437,7 b' class Repository(Base, BaseModel):' | |||
|
2437 | 2437 | # control over cache behaviour |
|
2438 | 2438 | if cache is None and full_cache and not config: |
|
2439 | 2439 | return self._get_instance_cached() |
|
2440 | # cache here is sent to the "vcs server" | |
|
2440 | 2441 | return self._get_instance(cache=bool(cache), config=config) |
|
2441 | 2442 | |
|
2442 | 2443 | def _get_instance_cached(self): |
@@ -2479,7 +2480,8 b' class Repository(Base, BaseModel):' | |||
|
2479 | 2480 | with_wire=custom_wire, |
|
2480 | 2481 | create=False, |
|
2481 | 2482 | _vcs_alias=self.repo_type) |
|
2482 | ||
|
2483 | if repo is not None: | |
|
2484 | repo.count() # cache rebuild | |
|
2483 | 2485 | return repo |
|
2484 | 2486 | |
|
2485 | 2487 | def __json__(self): |
@@ -4433,9 +4435,9 b' class Gist(Base, BaseModel):' | |||
|
4433 | 4435 | |
|
4434 | 4436 | def scm_instance(self, **kwargs): |
|
4435 | 4437 | """ |
|
4436 | Get explicit Mercurial repository used | |
|
4438 | Get an instance of VCS Repository | |
|
4439 | ||
|
4437 | 4440 | :param kwargs: |
|
4438 | :return: | |
|
4439 | 4441 | """ |
|
4440 | 4442 | from rhodecode.model.gist import GistModel |
|
4441 | 4443 | full_repo_path = os.path.join(self.base_path(), self.gist_access_id) |
@@ -683,7 +683,6 b' class PullRequestModel(BaseModel):' | |||
|
683 | 683 | |
|
684 | 684 | # source repo |
|
685 | 685 | source_repo = pull_request.source_repo.scm_instance() |
|
686 | source_repo.count() # cache rebuild | |
|
687 | 686 | |
|
688 | 687 | try: |
|
689 | 688 | source_commit = source_repo.get_commit(commit_id=source_ref_name) |
@@ -698,7 +697,6 b' class PullRequestModel(BaseModel):' | |||
|
698 | 697 | |
|
699 | 698 | # target repo |
|
700 | 699 | target_repo = pull_request.target_repo.scm_instance() |
|
701 | target_repo.count() # cache rebuild | |
|
702 | 700 | |
|
703 | 701 | try: |
|
704 | 702 | target_commit = target_repo.get_commit(commit_id=target_ref_name) |
@@ -1342,7 +1340,6 b' class PullRequestModel(BaseModel):' | |||
|
1342 | 1340 | else: |
|
1343 | 1341 | name_or_id = reference.commit_id |
|
1344 | 1342 | |
|
1345 | vcs_repository.count() # cache rebuild | |
|
1346 | 1343 | refreshed_commit = vcs_repository.get_commit(name_or_id) |
|
1347 | 1344 | refreshed_reference = Reference( |
|
1348 | 1345 | reference.type, reference.name, refreshed_commit.raw_id) |
@@ -129,20 +129,19 b' def test_strip_with_single_heads(backend' | |||
|
129 | 129 | assert commit_ids['b'] not in rest_commit_ids |
|
130 | 130 | |
|
131 | 131 | |
|
132 |
def test_get_nodes_returns_unicode_flat(backend |
|
|
133 |
repo = backend |
|
|
134 | directories, files = scm.ScmModel().get_nodes( | |
|
135 | repo.repo_name, repo.get_commit(commit_idx=0).raw_id, | |
|
136 | flat=True) | |
|
132 | def test_get_nodes_returns_unicode_flat(backend): | |
|
133 | repo = backend.repo | |
|
134 | commit_id = repo.get_commit(commit_idx=0).raw_id | |
|
135 | directories, files = scm.ScmModel().get_nodes(repo.repo_name, commit_id, flat=True) | |
|
137 | 136 | assert_contains_only_unicode(directories) |
|
138 | 137 | assert_contains_only_unicode(files) |
|
139 | 138 | |
|
140 | 139 | |
|
141 |
def test_get_nodes_returns_unicode_non_flat(backend |
|
|
142 |
repo = backend |
|
|
143 | directories, files = scm.ScmModel().get_nodes( | |
|
144 | repo.repo_name, repo.get_commit(commit_idx=0).raw_id, | |
|
145 | flat=False) | |
|
140 | def test_get_nodes_returns_unicode_non_flat(backend): | |
|
141 | repo = backend.repo | |
|
142 | commit_id = repo.get_commit(commit_idx=0).raw_id | |
|
143 | ||
|
144 | directories, files = scm.ScmModel().get_nodes(repo.repo_name, commit_id, flat=False) | |
|
146 | 145 | # johbo: Checking only the names for now, since that is the critical |
|
147 | 146 | # part. |
|
148 | 147 | assert_contains_only_unicode([d['name'] for d in directories]) |
@@ -148,7 +148,6 b' def _add_commits_to_repo(repo, commits):' | |||
|
148 | 148 | author=unicode(commit['author']), |
|
149 | 149 | date=commit['date'], |
|
150 | 150 | branch=commit.get('branch')) |
|
151 | ||
|
152 | 151 | return tip |
|
153 | 152 | |
|
154 | 153 |
@@ -159,8 +159,7 b' class TestCommitsInNonEmptyRepo(BackendT' | |||
|
159 | 159 | parents=[initial], |
|
160 | 160 | branch=DEFAULT_BRANCH,) |
|
161 | 161 | |
|
162 | default_branch_commits = self.repo.get_commits( | |
|
163 | branch_name=DEFAULT_BRANCH) | |
|
162 | default_branch_commits = self.repo.get_commits(branch_name=DEFAULT_BRANCH) | |
|
164 | 163 | assert docs_branch_commit1 not in list(default_branch_commits) |
|
165 | 164 | assert docs_branch_commit2 not in list(default_branch_commits) |
|
166 | 165 |
@@ -1091,23 +1091,23 b' class TestGitSpecificWithRepo(BackendTes' | |||
|
1091 | 1091 | self.repo.get_diff(self.repo[0], self.repo[1]) |
|
1092 | 1092 | self.repo.run_git_command.assert_called_once_with( |
|
1093 | 1093 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', |
|
1094 |
'--abbrev=40', self.repo._ |
|
|
1095 |
self.repo._ |
|
|
1094 | '--abbrev=40', self.repo._lookup_commit(0), | |
|
1095 | self.repo._lookup_commit(1)]) | |
|
1096 | 1096 | |
|
1097 | 1097 | def test_get_diff_runs_git_command_with_str_hashes(self): |
|
1098 | 1098 | self.repo.run_git_command = mock.Mock(return_value=['', '']) |
|
1099 | 1099 | self.repo.get_diff(self.repo.EMPTY_COMMIT, self.repo[1]) |
|
1100 | 1100 | self.repo.run_git_command.assert_called_once_with( |
|
1101 | 1101 | ['show', '-U3', '--full-index', '--binary', '-p', '-M', |
|
1102 |
'--abbrev=40', self.repo._ |
|
|
1102 | '--abbrev=40', self.repo._lookup_commit(1)]) | |
|
1103 | 1103 | |
|
1104 | 1104 | def test_get_diff_runs_git_command_with_path_if_its_given(self): |
|
1105 | 1105 | self.repo.run_git_command = mock.Mock(return_value=['', '']) |
|
1106 | 1106 | self.repo.get_diff(self.repo[0], self.repo[1], 'foo') |
|
1107 | 1107 | self.repo.run_git_command.assert_called_once_with( |
|
1108 | 1108 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', |
|
1109 |
'--abbrev=40', self.repo._ |
|
|
1110 |
self.repo._ |
|
|
1109 | '--abbrev=40', self.repo._lookup_commit(0), | |
|
1110 | self.repo._lookup_commit(1), '--', 'foo']) | |
|
1111 | 1111 | |
|
1112 | 1112 | |
|
1113 | 1113 | @pytest.mark.usefixtures("vcs_repository_support") |
General Comments 0
You need to be logged in to leave comments.
Login now