def test_hide_private_info(): assert_equals(h.hide_private_info(None), None) assert_equals(h.hide_private_info(''), '') assert_equals(h.hide_private_info('foo bar [email protected]'), 'foo bar baz@...') assert_equals(h.hide_private_info('some <*****@*****.**>\nor [email protected]'), 'some <1@...>\nor asdf+asdf.f@...') with h.push_config(h.tg.config, hide_private_info=False): assert_equals(h.hide_private_info('foo bar [email protected]'), 'foo bar [email protected]')
def commit_browser_data(self, start=None, limit=None, **kw): log.debug('Start commit_browser_data') if limit is None: limit = int(tg.config.get('scm.view.commit_browser.limit', 500)) if start: head_ids = start.split(',') else: # master, and any other branches head_ids = [head.object_id for head in c.app.repo.get_heads()] log.debug('Got %s heads', len(head_ids)) # recent commits from any head heads_log = list(c.app.repo.log(head_ids, id_only=True, limit=int(limit))) log.debug('Did log lookup') commit_ids = [c.app.repo.rev_to_commit_id(r) for r in heads_log] # any we didn't get to will be attempted in next page of commits next_page_commits = list(set(head_ids) - set(commit_ids)) # and remove any heads that didn't come through from further processing head_ids = set(head_ids).intersection(set(commit_ids)) log.info('Grab %d commit objects by ID', len(commit_ids)) commits_by_id = { c_obj._id: c_obj for c_obj in M.repository.CommitDoc.m.find(dict(_id={'$in': commit_ids}))} log.info('... build graph') parents = {} children = defaultdict(list) dates = {} for row, (oid, ci) in enumerate(commits_by_id.iteritems()): parents[oid] = list(ci.parent_ids) dates[oid] = ci.committed.date for p_oid in ci.parent_ids: children[p_oid].append(oid) result = [] row = 0 for oid in topo_sort(children, parents, dates, head_ids): if oid not in commits_by_id: next_page_commits.append(oid) continue ci = commits_by_id[oid] url = c.app.repo.url_for_commit(Object(_id=oid)) msg_split = ci.message.splitlines() if msg_split: msg = h.hide_private_info(msg_split[0]) else: msg = "No commit message." result.append(dict( oid=oid, short_id=c.app.repo.shorthand_for_commit(oid), row=row, parents=ci.parent_ids, message=msg, url=url)) row += 1 built_tree = OrderedDict((ci_json['oid'], ci_json) for ci_json in result) log.info('...done') return dict( built_tree=built_tree, next_commit=','.join(next_page_commits), )
def commit_browser_data(self, start=None, limit=None, **kw): log.debug('Start commit_browser_data') if limit is None: limit = int(tg.config.get('scm.view.commit_browser.limit', 500)) if start: head_ids = start.split(',') else: # master, and any other branches head_ids = [head.object_id for head in c.app.repo.get_heads()] log.debug('Got %s heads', len(head_ids)) # recent commits from any head heads_log = list( c.app.repo.log(head_ids, id_only=True, limit=int(limit))) log.debug('Did log lookup') commit_ids = [c.app.repo.rev_to_commit_id(r) for r in heads_log] # any we didn't get to will be attempted in next page of commits next_page_commits = list(set(head_ids) - set(commit_ids)) # and remove any heads that didn't come through from further processing head_ids = set(head_ids).intersection(set(commit_ids)) log.info('Grab %d commit objects by ID', len(commit_ids)) commits_by_id = { c_obj._id: c_obj for c_obj in M.repository.CommitDoc.m.find( dict(_id={'$in': commit_ids})) } log.info('... build graph') parents = {} children = defaultdict(list) dates = {} for row, (oid, ci) in enumerate(commits_by_id.iteritems()): parents[oid] = list(ci.parent_ids) dates[oid] = ci.committed.date for p_oid in ci.parent_ids: children[p_oid].append(oid) result = [] row = 0 for oid in topo_sort(children, parents, dates, head_ids): if oid not in commits_by_id: next_page_commits.append(oid) continue ci = commits_by_id[oid] url = c.app.repo.url_for_commit(Object(_id=oid)) msg_split = ci.message.splitlines() if msg_split: msg = h.hide_private_info(msg_split[0]) else: msg = "No commit message." result.append( dict(oid=oid, short_id=c.app.repo.shorthand_for_commit(oid), row=row, parents=ci.parent_ids, message=msg, url=url)) row += 1 built_tree = OrderedDict( (ci_json['oid'], ci_json) for ci_json in result) log.info('...done') return dict( built_tree=built_tree, next_commit=','.join(next_page_commits), )