You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/09/05 20:20:46 UTC

[21/50] git commit: [5775] ticket:404 added renaming tracking for file history in git

[5775] ticket:404 added renaming tracking for file history in git


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/dd57c984
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/dd57c984
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/dd57c984

Branch: refs/heads/cj/6596
Commit: dd57c984cdcd581abe665fbb571ad8080839184a
Parents: 839e624
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Thu Aug 1 13:36:45 2013 +0300
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Aug 29 19:00:44 2013 +0000

----------------------------------------------------------------------
 Allura/allura/templates/widgets/repo/log.html |  8 +++++
 ForgeGit/forgegit/model/git_repo.py           | 35 +++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/dd57c984/Allura/allura/templates/widgets/repo/log.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/repo/log.html b/Allura/allura/templates/widgets/repo/log.html
index 69d7129..b54685f 100644
--- a/Allura/allura/templates/widgets/repo/log.html
+++ b/Allura/allura/templates/widgets/repo/log.html
@@ -54,6 +54,14 @@
                 pushed by {{ user_link(commit.committed.email, commit.committed.name) }}
                 {% endif %}
                 {{g.markdown.convert(commit.message)}}
+                {% if commit.renamed_from %}
+                    <div>
+                      <b>renamed from</b>&nbsp
+                      <a href={{commit.renamed_from['commit_url']}}log/?path={{ commit.renamed_from['path'] }}>
+                        {{ commit.renamed_from['path'] }}
+                      </a>
+                    </div>
+                {% endif %}
             </div>
           </td>
           <td style="vertical-align: text-top">

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/dd57c984/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index e0e47b8..f400d56 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -302,12 +302,40 @@ class GitImplementation(M.RepositoryImplementation):
         if exclude is not None:
             revs.extend(['^%s' % e for e in exclude])
 
-        for ci, refs in self._iter_commits_with_refs(revs, '--', path):
+        for ci, refs in self._iter_commits_with_refs(revs, '--follow', '--', path):
             if id_only:
                 yield ci.hexsha
             else:
                 size = None
+                renamed_from = {}
                 if path:
+                    # checking for renaming in this commit
+                    # log is called with follow, so there should be all commits
+                    # even before renaming
+                    diffs_with_parent = ci.diff(ci.parents[0])
+                    deleted_file_diffs = []
+                    renamed = False
+                    for diff in diffs_with_parent:
+                        if not diff.b_mode and not diff.b_blob:
+                            #new file was created
+                            if diff.a_blob.name == os.path.basename(path):
+                                renamed = True
+                        if not diff.a_mode and not diff.a_blob:
+                            #file was deleted
+                            deleted_file_diffs.append(diff)
+                    if renamed:
+                        if len(deleted_file_diffs) > 1:
+                            log.info('Couldn\'t find if file was renamed: too many deletions')
+                        elif len(deleted_file_diffs) == 1:
+                            deleted_diff = deleted_file_diffs[0]
+                            renamed_from['path'] = '{}/{}'.format(
+                                os.path.dirname(path),
+                                deleted_diff.b_blob.name,
+                            )
+                            renamed_from['commit_id'] = ci.hexsha
+                            renamed_from['commit_url'] = self._repo.url_for_commit(
+                                ci.hexsha
+                            )
                     try:
                         node = ci.tree/path
                         size = node.size if node.type == 'blob' else None
@@ -329,7 +357,12 @@ class GitImplementation(M.RepositoryImplementation):
                         'refs': refs,
                         'parents': [pci.hexsha for pci in ci.parents],
                         'size': size,
+                        'renamed_from': renamed_from,
                     }
+                if renamed_from:
+                    # if file was renamed, do not yield commits
+                    # before renaming
+                    break
 
     def _iter_commits_with_refs(self, *args, **kwargs):
         """