Last active
April 27, 2016 14:13
-
-
Save phraniiac/893c94099e476610f0d8e9e6e273b262 to your computer and use it in GitHub Desktop.
#7949 Ticket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def paged_diffs(self, commit_id, start=0, end=None): | |
result = {'added': [], 'removed': [], 'changed': [], 'copied': [], 'renamed': []} | |
cmd_args = ['--no-commit-id', | |
'--name-status', | |
'--no-abbrev', | |
'--root', | |
# show only the files that are changed in the repository.) | |
'-r', | |
'-z' # don't escape filenames and use \x00 as fields delimiter | |
] | |
if asbool(tg.config.get('scm.commit.git.detect_copies', True)): | |
cmd_args += ['-M', '-C'] | |
cmd_output = self._git.git.diff_tree(commit_id, *cmd_args).split('\x00')[:-1] # don't escape filenames and use \x00 as fields delimiter | |
''' cmd_output will be like: | |
[ | |
'A', | |
'filename', | |
'D', | |
'another filename', | |
'M', | |
'po', | |
'R100', # <-- These next three lines would only show up with 'detect_copies' enabled | |
'po/sr.po', | |
'po/sr_Latn.po', | |
] | |
''' | |
dr = {} | |
test_out = [] | |
x = 0 | |
while x < len(cmd_output): | |
status = cmd_output[x][0] | |
l = [] | |
l.append(cmd_output[x]) | |
x += 1 | |
l.append(cmd_output[x]) | |
x += 1 | |
if status in ('R', 'C'): | |
l.append(cmd_output[x]) | |
x += 1 | |
test_out.append(l) | |
test_out.sort(key=lambda x: x[-1][x[-1].rfind('/')+1], reverse = True) | |
x = 0 | |
files = [] | |
while x < len(test_out): | |
status = test_out[x][0][0] | |
if status in ('R', 'C'): | |
ratio = float(test_out[x][0][1:4]) / 100.0 | |
files.append((status, { | |
'new': h.really_unicode(test_out[x][2]), | |
'old': h.really_unicode(test_out[x][1]), | |
'ratio': ratio, | |
})) | |
else: | |
files.append((status, h.really_unicode(test_out[x][1]))) | |
x += 1 | |
for status, name in files[start:end]: | |
change_list = { | |
'R': result['renamed'], | |
'C': result['copied'], | |
'A': result['added'], | |
'D': result['removed'], | |
'M': result['changed'] | |
}[status] | |
change_list.append(name) | |
result['total'] = len(files) | |
return result | |
#------------------------------------------------------------------------------------- | |
class TestRootControllerUI(TestController): | |
def setUp(self): | |
super(TestRootControllerUI, self).setUp() | |
self.setup_with_tools() | |
@with_git | |
def setup_with_tools(self): | |
h.set_context('test', 'src-git', neighborhood='Projects') | |
repo_dir = pkg_resources.resource_filename( | |
'forgegit', 'tests/data/testui2') | |
c.app.repo.fs_path = repo_dir | |
c.app.repo.name = '.git' | |
c.app.repo.status = 'ready' | |
self.repo = c.app.repo | |
self.repo.refresh() | |
self.rev = self.repo.commit('HEAD') | |
ThreadLocalORMSession.flush_all() | |
ThreadLocalORMSession.close_all() | |
def test_status(self): | |
resp = self.app.get('/src-git/status') | |
d = json.loads(resp.body) | |
assert d == dict(status='ready') | |
def test_index(self): | |
resp = self.app.get('/src-git/').follow().follow() | |
assert '/p/test/src-git/ci/66de648279437f8762ffcc1c37387b7c055b05fc/' in resp | |
# /p/test/src-git/ci/66de648279437f8762ffcc1c37387b7c055b05fc/ | |
def test_commits(self): | |
resp = self.app.get('/p/test/src-git/ci/66de648279437f8762ffcc1c37387b7c055b05fc/') | |
assert '<a href="/p/test/src-git/ci/66de648279437f8762ffcc1c37387b7c055b05fc/tree/subdir1">subdir1</a>' not in resp | |
assert '<a href="/p/test/src-git/ci/66de648279437f8762ffcc1c37387b7c055b05fc/tree/subdir1/a">subdir1/a</a>' in resp | |
#------------------------------------------------------------------------------------------------ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment