diff --git a/rhodecode/apps/repository/views/repo_changelog.py b/rhodecode/apps/repository/views/repo_changelog.py --- a/rhodecode/apps/repository/views/repo_changelog.py +++ b/rhodecode/apps/repository/views/repo_changelog.py @@ -211,7 +211,7 @@ class RepoChangelogView(RepoAppView): base_commit = self.rhodecode_vcs_repo.get_commit(commit_id) try: - collection = base_commit.get_file_history( + collection = base_commit.get_path_history( f_path, limit=hist_limit, pre_load=pre_load) if collection and partial_xhr: # for ajax call we remove first one since we're looking @@ -221,7 +221,7 @@ class RepoChangelogView(RepoAppView): # this node is not present at tip! try: commit = self._get_commit_or_redirect(commit_id) - collection = commit.get_file_history(f_path) + collection = commit.get_path_history(f_path) except RepositoryError as e: h.flash(safe_str(e), category='warning') redirect_url = h.route_path( @@ -315,7 +315,7 @@ class RepoChangelogView(RepoAppView): raise HTTPFound( h.route_path('repo_changelog', repo_name=self.db_repo_name)) - collection = base_commit.get_file_history( + collection = base_commit.get_path_history( f_path, limit=hist_limit, pre_load=pre_load) collection = list(reversed(collection)) else: diff --git a/rhodecode/apps/repository/views/repo_files.py b/rhodecode/apps/repository/views/repo_files.py --- a/rhodecode/apps/repository/views/repo_files.py +++ b/rhodecode/apps/repository/views/repo_files.py @@ -663,7 +663,7 @@ class RepoFilesView(RepoAppView): pass if is_file: - history = commit.get_file_history(f_path) + history = commit.get_path_history(f_path) prev_commit_id = history[1].raw_id \ if len(history) > 1 else prev_commit_id prev_url = h.route_path( @@ -897,10 +897,10 @@ class RepoFilesView(RepoAppView): if commits is None: pre_load = ["author", "branch"] try: - commits = tip.get_file_history(f_path, pre_load=pre_load) + commits = tip.get_path_history(f_path, pre_load=pre_load) except (NodeDoesNotExistError, CommitError): # this node is not present at tip! - commits = commit_obj.get_file_history(f_path, pre_load=pre_load) + commits = commit_obj.get_path_history(f_path, pre_load=pre_load) history = [] commits_group = ([], _("Changesets")) diff --git a/rhodecode/lib/vcs/backends/base.py b/rhodecode/lib/vcs/backends/base.py --- a/rhodecode/lib/vcs/backends/base.py +++ b/rhodecode/lib/vcs/backends/base.py @@ -942,13 +942,13 @@ class BaseCommit(object): """ raise NotImplementedError - def get_file_commit(self, path, pre_load=None): + def get_path_commit(self, path, pre_load=None): """ Returns last commit of the file at the given `path`. :param pre_load: Optional. List of commit attributes to load. """ - commits = self.get_file_history(path, limit=1, pre_load=pre_load) + commits = self.get_path_history(path, limit=1, pre_load=pre_load) if not commits: raise RepositoryError( 'Failed to fetch history for path {}. ' @@ -956,7 +956,7 @@ class BaseCommit(object): path)) return commits[0] - def get_file_history(self, path, limit=None, pre_load=None): + def get_path_history(self, path, limit=None, pre_load=None): """ Returns history of file as reversed list of :class:`BaseCommit` objects for which file at given `path` has been modified. @@ -1194,8 +1194,8 @@ class BaseCommit(object): self.idx = value def get_file_changeset(self, path): - warnings.warn("Use get_file_commit instead", DeprecationWarning) - return self.get_file_commit(path) + warnings.warn("Use get_path_commit instead", DeprecationWarning) + return self.get_path_commit(path) class BaseChangesetClass(type): @@ -1502,7 +1502,7 @@ class EmptyCommit(BaseCommit): def id(self): return self.raw_id - def get_file_commit(self, path): + def get_path_commit(self, path): return self def get_file_content(self, path): diff --git a/rhodecode/lib/vcs/backends/git/commit.py b/rhodecode/lib/vcs/backends/git/commit.py --- a/rhodecode/lib/vcs/backends/git/commit.py +++ b/rhodecode/lib/vcs/backends/git/commit.py @@ -298,7 +298,7 @@ class GitCommit(base.BaseCommit): id_, _ = self._get_id_for_path(path) return self._remote.blob_raw_length(id_) - def get_file_history(self, path, limit=None, pre_load=None): + def get_path_history(self, path, limit=None, pre_load=None): """ Returns history of file as reversed list of `GitCommit` objects for which file at given `path` has been modified. @@ -321,21 +321,6 @@ class GitCommit(base.BaseCommit): self.repository.get_commit(commit_id=commit_id, pre_load=pre_load) for commit_id in commit_ids] - # TODO: unused for now potential replacement for subprocess - def get_file_history_2(self, path, limit=None, pre_load=None): - """ - Returns history of file as reversed list of `Commit` objects for - which file at given `path` has been modified. - """ - self._get_filectx(path) - f_path = safe_str(path) - - commit_ids = self._remote.get_file_history(f_path, self.id, limit) - - return [ - self.repository.get_commit(commit_id=commit_id, pre_load=pre_load) - for commit_id in commit_ids] - def get_file_annotate(self, path, pre_load=None): """ Returns a generator of four element tuples with diff --git a/rhodecode/lib/vcs/backends/hg/commit.py b/rhodecode/lib/vcs/backends/hg/commit.py --- a/rhodecode/lib/vcs/backends/hg/commit.py +++ b/rhodecode/lib/vcs/backends/hg/commit.py @@ -252,13 +252,13 @@ class MercurialCommit(base.BaseCommit): path = self._get_filectx(path) return self._remote.fctx_size(self.idx, path) - def get_file_history(self, path, limit=None, pre_load=None): + def get_path_history(self, path, limit=None, pre_load=None): """ Returns history of file as reversed list of `MercurialCommit` objects for which file at given ``path`` has been modified. """ path = self._get_filectx(path) - hist = self._remote.file_history(self.idx, path, limit) + hist = self._remote.node_history(self.idx, path, limit) return [ self.repository.get_commit(commit_id=commit_id, pre_load=pre_load) for commit_id in hist] diff --git a/rhodecode/lib/vcs/backends/svn/commit.py b/rhodecode/lib/vcs/backends/svn/commit.py --- a/rhodecode/lib/vcs/backends/svn/commit.py +++ b/rhodecode/lib/vcs/backends/svn/commit.py @@ -121,7 +121,7 @@ class SubversionCommit(base.BaseCommit): path = self._fix_path(path) return self._remote.get_file_size(safe_str(path), self._svn_rev) - def get_file_history(self, path, limit=None, pre_load=None): + def get_path_history(self, path, limit=None, pre_load=None): path = safe_str(self._fix_path(path)) history = self._remote.node_history(path, self._svn_rev, limit) return [ diff --git a/rhodecode/lib/vcs/nodes.py b/rhodecode/lib/vcs/nodes.py --- a/rhodecode/lib/vcs/nodes.py +++ b/rhodecode/lib/vcs/nodes.py @@ -404,7 +404,7 @@ class FileNode(Node): def last_commit(self): if self.commit: pre_load = ["author", "date", "message"] - return self.commit.get_file_commit(self.path, pre_load=pre_load) + return self.commit.get_path_commit(self.path, pre_load=pre_load) raise NodeError( "Cannot retrieve last commit of the file without " "related commit attribute") @@ -510,7 +510,7 @@ class FileNode(Node): """ if self.commit is None: raise NodeError('Unable to get commit for this FileNode') - return self.commit.get_file_history(self.path) + return self.commit.get_path_history(self.path) @LazyProperty def annotate(self): @@ -724,6 +724,15 @@ class DirNode(Node): return size + @LazyProperty + def last_commit(self): + if self.commit: + pre_load = ["author", "date", "message"] + return self.commit.get_path_commit(self.path, pre_load=pre_load) + raise NodeError( + "Cannot retrieve last commit of the file without " + "related commit attribute") + def __repr__(self): return '<%s %r @ %s>' % (self.__class__.__name__, self.path, getattr(self.commit, 'short_id', '')) diff --git a/rhodecode/tests/vcs/test_commits.py b/rhodecode/tests/vcs/test_commits.py --- a/rhodecode/tests/vcs/test_commits.py +++ b/rhodecode/tests/vcs/test_commits.py @@ -310,9 +310,9 @@ class TestCommits(BackendTestMixin): with pytest.raises(CommitDoesNotExistError): commit.next() - def test_get_file_commit(self): + def test_get_path_commit(self): commit = self.repo.get_commit() - commit.get_file_commit('file_4.txt') + commit.get_path_commit('file_4.txt') assert commit.message == 'Commit 4' def test_get_filenodes_generator(self): @@ -571,19 +571,19 @@ class TestCommitsChanges(BackendTestMixi assert FILEMODE_DEFAULT == commit.get_file_mode('foo/bał') assert FILEMODE_DEFAULT == commit.get_file_mode(u'foo/bał') - def test_get_file_history(self): + def test_get_path_history(self): commit = self.repo.get_commit() - history = commit.get_file_history('foo/bar') + history = commit.get_path_history('foo/bar') assert len(history) == 2 - def test_get_file_history_with_limit(self): + def test_get_path_history_with_limit(self): commit = self.repo.get_commit() - history = commit.get_file_history('foo/bar', limit=1) + history = commit.get_path_history('foo/bar', limit=1) assert len(history) == 1 - def test_get_file_history_first_commit(self): + def test_get_path_history_first_commit(self): commit = self.repo[0] - history = commit.get_file_history('foo/bar') + history = commit.get_path_history('foo/bar') assert len(history) == 1