You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/08/29 21:27:44 UTC
[09/10] git commit: [#5775] ticket:404 fixed log implementation error
[#5775] ticket:404 fixed log implementation error
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/9a5ec88c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9a5ec88c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9a5ec88c
Branch: refs/heads/master
Commit: 9a5ec88c577d05b1cecd40a58e4fb4ce21e9f104
Parents: 2409375
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Tue Aug 6 17:26:42 2013 +0300
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Aug 29 19:00:45 2013 +0000
----------------------------------------------------------------------
Allura/allura/templates/widgets/repo/log.html | 6 +--
ForgeGit/forgegit/model/git_repo.py | 52 ++++++++++++++------
.../forgegit/tests/model/test_repository.py | 16 +++---
3 files changed, 48 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a5ec88c/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 c3ced6f..ec6b048 100644
--- a/Allura/allura/templates/widgets/repo/log.html
+++ b/Allura/allura/templates/widgets/repo/log.html
@@ -54,11 +54,11 @@
pushed by {{ user_link(commit.committed.email, commit.committed.name) }}
{% endif %}
{{g.markdown.convert(commit.message)}}
- {% if commit.renamed_from %}
+ {% if commit.rename_details %}
<div>
<b>renamed from</b>
- <a href={{commit.renamed_from['commit_url']}}log/?path={{ commit.renamed_from['path'] }}>
- {{ commit.renamed_from['path'] }}
+ <a href={{commit.rename_details['commit_url']}}log/?path={{ commit.rename_details['path'] }}>
+ {{ commit.rename_details['path'] }}
</a>
</div>
{% endif %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a5ec88c/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 1599fd2..7262efa 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -338,7 +338,7 @@ class GitImplementation(M.RepositoryImplementation):
'refs': refs,
'parents': [pci.hexsha for pci in ci.parents],
'size': size,
- 'renamed_from': rename_details,
+ 'rename_details': rename_details,
}
if rename_details:
# we do not need to show commits before rename
@@ -362,24 +362,46 @@ class GitImplementation(M.RepositoryImplementation):
of lazy-loading the commit data is probably fine. But if this
ends up being a bottleneck, that would be one possibile
optimization.
+
+ Renaming
+ Detection of renaming can be implemented using diff with parent
+ with create_path=True. But taking diffs is slow. That's why
+ --name-status is added to log.
+ Then log returns something like this:
+ <commit hash>x00 <refs>
+ \n # empty line
+ R100 <renamed from path> <renamed to path> # when rename happens
+ A\t<some path> # other cases
+ D\t<some path> # other cases
+ etc
"""
proc = self._git.git.log(*args, format='%H%x00%d', as_process=True, **kwargs)
stream = proc.stdout
+ commit_lines = []
while True:
- commit_lines = [stream.readline() for _ in xrange(3)]
- commit_line = '\x00'.join(
- [line.strip('\n ').replace('\t', ' ') for line in commit_lines if line.strip('\n\t ')]
- )
- if not commit_line:
- break
- hexsha, decoration, name_stat = commit_line.strip().split('\x00')
- refs = decoration.strip(' ()').split(', ') if decoration else []
- name_stat_parts = name_stat.split(' ')
- renamed = {}
- if name_stat_parts[0] == 'R100':
- renamed['from'] = name_stat_parts[1]
- renamed['to'] = name_stat_parts[2]
- yield (git.Commit(self._git, gitdb.util.hex_to_bin(hexsha)), refs, renamed)
+ line = stream.readline()
+ if '\x00' in line or not(len(line)):
+ # hash line read, need to yield previous commit
+ # first, cleaning lines a bit
+ commit_lines = [
+ ln.strip('\n\ ').replace('\t', ' ')
+ for ln in commit_lines if ln.strip('\n ')
+ ]
+ if commit_lines:
+ hexsha, decoration = commit_lines[0].split('\x00')
+ refs = decoration.strip(' ()').split(', ') if decoration else []
+ name_stat_parts = commit_lines[1].split(' ')
+ renamed = {}
+ if name_stat_parts[0] == 'R100':
+ renamed['from'] = name_stat_parts[1]
+ renamed['to'] = name_stat_parts[2]
+ yield (git.Commit(self._git, gitdb.util.hex_to_bin(hexsha)), refs, renamed)
+ if not(len(line)):
+ # if all lines have been read
+ break
+ commit_lines = [line]
+ else:
+ commit_lines.append(line)
def open_blob(self, blob):
return _OpenedGitBlob(
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a5ec88c/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index d116a10..e55fed7 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -241,7 +241,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': ['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
'refs': ['HEAD', 'foo', 'master'],
'size': None,
- 'renamed_from': {}},
+ 'rename_details': {}},
{'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
'email': u'rcopeland@geek.net',
'name': u'Rick Copeland'},
@@ -253,7 +253,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': ['6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
'refs': [],
'size': None,
- 'renamed_from': {}},
+ 'rename_details': {}},
{'authored': {'date': datetime.datetime(2010, 10, 7, 18, 43, 26),
'email': u'rcopeland@geek.net',
'name': u'Rick Copeland'},
@@ -265,7 +265,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': ['9a7df788cf800241e3bb5a849c8870f2f8259d98'],
'refs': [],
'size': None,
- 'renamed_from': {}},
+ 'rename_details': {}},
{'authored': {'date': datetime.datetime(2010, 10, 7, 18, 42, 54),
'email': u'rcopeland@geek.net',
'name': u'Rick Copeland'},
@@ -277,7 +277,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': [],
'refs': [],
'size': None,
- 'renamed_from': {}},
+ 'rename_details': {}},
])
def test_log_file(self):
@@ -294,7 +294,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': ['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
'refs': ['HEAD', 'foo', 'master'],
'size': 28,
- 'renamed_from': {}},
+ 'rename_details': {}},
{'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
'email': u'rcopeland@geek.net',
'name': u'Rick Copeland'},
@@ -306,7 +306,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'parents': ['6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
'refs': [],
'size': 15,
- 'renamed_from': {}},
+ 'rename_details': {}},
])
def test_commit(self):
@@ -570,8 +570,8 @@ class TestGitRename(unittest.TestCase):
commits = list(self.repo.log(id_only=False, path='/f2.txt'))
self.assertEqual(len(commits), 2)
rename_commit = commits[1]
- self.assertEqual(rename_commit['renamed_from']['path'], '/f.txt')
+ self.assertEqual(rename_commit['rename_details']['path'], '/f.txt')
self.assertEqual(
- rename_commit['renamed_from']['commit_url'],
+ rename_commit['rename_details']['commit_url'],
self.repo.url_for_commit(rename_commit['id'])
)