comparison rhodecode/controllers/compare.py @ 3015:16af24982e30 beta

Multiple changes for compare system - count number of changed lines and files - add combined compare button into the old per changeset compare - fixed some logic for remote & bundle compare system - added few tests for git compare
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 18 Nov 2012 23:17:02 +0100
parents 25d77aef2729
children c2a206162062
comparison
equal deleted inserted replaced
3014:02bbd574fa14 3015:16af24982e30
86 86
87 org_repo = c.rhodecode_db_repo.repo_name 87 org_repo = c.rhodecode_db_repo.repo_name
88 org_ref = (org_ref_type, org_ref) 88 org_ref = (org_ref_type, org_ref)
89 other_ref = (other_ref_type, other_ref) 89 other_ref = (other_ref_type, other_ref)
90 other_repo = request.GET.get('repo', org_repo) 90 other_repo = request.GET.get('repo', org_repo)
91 bundle_compare = str2bool(request.GET.get('bundle', True)) 91 remote_compare = str2bool(request.GET.get('bundle', True))
92 c.fulldiff = fulldiff = request.GET.get('fulldiff') 92 c.fulldiff = fulldiff = request.GET.get('fulldiff')
93 93
94 c.swap_url = h.url('compare_url', repo_name=other_repo, 94 c.swap_url = h.url('compare_url', repo_name=other_repo,
95 org_ref_type=other_ref[0], org_ref=other_ref[1], 95 org_ref_type=other_ref[0], org_ref=other_ref[1],
96 other_ref_type=org_ref[0], other_ref=org_ref[1], 96 other_ref_type=org_ref[0], other_ref=org_ref[1],
97 repo=org_repo, as_form=request.GET.get('as_form'), 97 repo=org_repo, as_form=request.GET.get('as_form'),
98 bundle=bundle_compare) 98 bundle=remote_compare)
99 99
100 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo) 100 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
101 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo) 101 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
102 102
103 if c.org_repo is None or c.other_repo is None: 103 if c.org_repo is None or c.other_repo is None:
126 # defines that we need hidden inputs with changesets 126 # defines that we need hidden inputs with changesets
127 c.as_form = request.GET.get('as_form', False) 127 c.as_form = request.GET.get('as_form', False)
128 if partial: 128 if partial:
129 return render('compare/compare_cs.html') 129 return render('compare/compare_cs.html')
130 130
131 if not bundle_compare and c.cs_ranges: 131 c.org_ref = org_ref[1]
132 c.other_ref = other_ref[1]
133
134 if not remote_compare and c.cs_ranges:
132 # case we want a simple diff without incoming changesets, just 135 # case we want a simple diff without incoming changesets, just
133 # for review purposes. Make the diff on the forked repo, with 136 # for review purposes. Make the diff on the forked repo, with
134 # revision that is common ancestor 137 # revision that is common ancestor
135 other_ref = ('rev', c.cs_ranges[-1].parents[0].raw_id) 138 other_ref = ('rev', c.cs_ranges[-1].parents[0].raw_id)
136 other_repo = org_repo 139 other_repo = org_repo
137 140
138 c.org_ref = org_ref[1] 141 diff_limit = self.cut_off_limit if not fulldiff else None
139 c.other_ref = other_ref[1] 142 _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref,
143 discovery_data, remote_compare=remote_compare)
140 144
141 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref, 145 diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
142 discovery_data, bundle_compare=bundle_compare)
143 diff_limit = self.cut_off_limit if not fulldiff else None
144 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff',
145 diff_limit=diff_limit) 146 diff_limit=diff_limit)
146 _parsed = diff_processor.prepare() 147 _parsed = diff_processor.prepare()
147 148
148 c.limited_diff = False 149 c.limited_diff = False
149 if isinstance(_parsed, LimitedDiffContainer): 150 if isinstance(_parsed, LimitedDiffContainer):
150 c.limited_diff = True 151 c.limited_diff = True
151 152
152 c.files = [] 153 c.files = []
153 c.changes = {} 154 c.changes = {}
154 155 c.lines_added = 0
156 c.lines_deleted = 0
155 for f in _parsed: 157 for f in _parsed:
158 st = f['stats']
159 if st[0] != 'b':
160 c.lines_added += st[0]
161 c.lines_deleted += st[1]
156 fid = h.FID('', f['filename']) 162 fid = h.FID('', f['filename'])
157 c.files.append([fid, f['operation'], f['filename'], f['stats']]) 163 c.files.append([fid, f['operation'], f['filename'], f['stats']])
158 diff = diff_processor.as_html(enable_comments=False, parsed_lines=[f]) 164 diff = diff_processor.as_html(enable_comments=False, parsed_lines=[f])
159 c.changes[fid] = [f['operation'], f['filename'], diff] 165 c.changes[fid] = [f['operation'], f['filename'], diff]
160 166