##// END OF EJS Templates
vcs: introduce 'branches' attribute on changesets, making it possible for Git to show multiple branches for a changeset...
Mads Kiilerich -
r7067:3dbb625d default
parent child Browse files
Show More
@@ -63,8 +63,8 b' class FeedController(BaseRepoController)'
63 desc_msg = [(_('%s committed on %s')
63 desc_msg = [(_('%s committed on %s')
64 % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>']
64 % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>']
65 # branches, tags, bookmarks
65 # branches, tags, bookmarks
66 if cs.branch:
66 for branch in cs.branches:
67 desc_msg.append('branch: %s<br/>' % cs.branch)
67 desc_msg.append('branch: %s<br/>' % branch)
68 for book in cs.bookmarks:
68 for book in cs.bookmarks:
69 desc_msg.append('bookmark: %s<br/>' % book)
69 desc_msg.append('bookmark: %s<br/>' % book)
70 for tag in cs.tags:
70 for tag in cs.tags:
@@ -189,7 +189,7 b' class FilesController(BaseRepoController'
189
189
190 # TODO: tags and bookmarks?
190 # TODO: tags and bookmarks?
191 c.revision_options = [(c.changeset.raw_id,
191 c.revision_options = [(c.changeset.raw_id,
192 _('%s at %s') % (c.changeset.branch, h.short_id(c.changeset.raw_id)))] + \
192 _('%s at %s') % (b, h.short_id(c.changeset.raw_id))) for b in c.changeset.branches] + \
193 [(n, b) for b, n in c.db_repo_scm_instance.branches.items()]
193 [(n, b) for b, n in c.db_repo_scm_instance.branches.items()]
194 if c.db_repo_scm_instance.closed_branches:
194 if c.db_repo_scm_instance.closed_branches:
195 prefix = _('(closed)') + ' '
195 prefix = _('(closed)') + ' '
@@ -755,7 +755,7 b' class FilesController(BaseRepoController'
755 branches_group = ([], _("Branches"))
755 branches_group = ([], _("Branches"))
756 tags_group = ([], _("Tags"))
756 tags_group = ([], _("Tags"))
757 for chs in changesets:
757 for chs in changesets:
758 #_branch = '(%s)' % chs.branch if (cs.repository.alias == 'hg') else ''
758 # TODO: loop over chs.branches ... but that will not give all the bogus None branches for Git ...
759 _branch = chs.branch
759 _branch = chs.branch
760 n_desc = '%s (%s)' % (h.show_id(chs), _branch)
760 n_desc = '%s (%s)' % (h.show_id(chs), _branch)
761 changesets_group[0].append((chs.raw_id, n_desc,))
761 changesets_group[0].append((chs.raw_id, n_desc,))
@@ -102,11 +102,11 b' class PullrequestsController(BaseRepoCon'
102 for i in repo._repo.revs(
102 for i in repo._repo.revs(
103 "sort(parents(branch(id(%s)) and merge()) - branch(id(%s)), -rev)",
103 "sort(parents(branch(id(%s)) and merge()) - branch(id(%s)), -rev)",
104 branch_rev, branch_rev):
104 branch_rev, branch_rev):
105 abranch = repo.get_changeset(i).branch
105 for abranch in repo.get_changeset(i).branches:
106 if abranch not in peerbranches:
106 if abranch not in peerbranches:
107 n = 'branch:%s:%s' % (abranch, repo.get_changeset(abranch).raw_id)
107 n = 'branch:%s:%s' % (abranch, repo.get_changeset(abranch).raw_id)
108 peers.append((n, abranch))
108 peers.append((n, abranch))
109 peerbranches.add(abranch)
109 peerbranches.add(abranch)
110
110
111 selected = None
111 selected = None
112 tiprev = repo.tags.get('tip')
112 tiprev = repo.tags.get('tip')
@@ -1038,6 +1038,11 b' class EmptyChangeset(BaseChangeset):'
1038 return get_backend(self.alias).DEFAULT_BRANCH_NAME
1038 return get_backend(self.alias).DEFAULT_BRANCH_NAME
1039
1039
1040 @LazyProperty
1040 @LazyProperty
1041 def branches(self):
1042 from kallithea.lib.vcs.backends import get_backend
1043 return [get_backend(self.alias).DEFAULT_BRANCH_NAME]
1044
1045 @LazyProperty
1041 def short_id(self):
1046 def short_id(self):
1042 return self.raw_id[:12]
1047 return self.raw_id[:12]
1043
1048
@@ -91,13 +91,19 b' class GitChangeset(BaseChangeset):'
91
91
92 @LazyProperty
92 @LazyProperty
93 def branch(self):
93 def branch(self):
94
94 # Note: This function will return one branch name for the changeset -
95 # that might not make sense in Git where branches() is a better match
96 # for the basic model
95 heads = self.repository._heads(reverse=False)
97 heads = self.repository._heads(reverse=False)
96
97 ref = heads.get(self.raw_id)
98 ref = heads.get(self.raw_id)
98 if ref:
99 if ref:
99 return safe_unicode(ref)
100 return safe_unicode(ref)
100
101
102 @LazyProperty
103 def branches(self):
104 heads = self.repository._heads(reverse=True)
105 return [b for b in heads if heads[b] == self.raw_id] # FIXME: Inefficient ... and returning None!
106
101 def _fix_path(self, path):
107 def _fix_path(self, path):
102 """
108 """
103 Paths are stored without trailing slash so we need to get rid off it if
109 Paths are stored without trailing slash so we need to get rid off it if
@@ -41,6 +41,10 b' class MercurialChangeset(BaseChangeset):'
41 return safe_unicode(self._ctx.branch())
41 return safe_unicode(self._ctx.branch())
42
42
43 @LazyProperty
43 @LazyProperty
44 def branches(self):
45 return [safe_unicode(self._ctx.branch())]
46
47 @LazyProperty
44 def closesbranch(self):
48 def closesbranch(self):
45 return self._ctx.closesbranch()
49 return self._ctx.closesbranch()
46
50
@@ -97,8 +97,10 b''
97 %if cs.phase:
97 %if cs.phase:
98 <span class="label label-phase" title="Phase">${cs.phase}</span>
98 <span class="label label-phase" title="Phase">${cs.phase}</span>
99 %endif
99 %endif
100 %if show_branch and cs.branch:
100 %if show_branch:
101 <span class="label label-branch" title="${_('Branch %s' % cs.branch)}">${h.link_to(cs.branch,h.url('changelog_home',repo_name=repo_name,branch=cs.branch))}</span>
101 %for branch in cs.branches:
102 <span class="label label-branch" title="${_('Branch %s' % branch)}">${h.link_to(branch,h.url('changelog_home',repo_name=repo_name,branch=branch))}</span>
103 %endfor
102 %endif
104 %endif
103 </div>
105 </div>
104 </div>
106 </div>
@@ -68,9 +68,9 b''
68 <span class="label label-tag" title="${_('Tag %s') % tag}">${h.link_to(tag,h.url('changeset_home',repo_name=c.repo_name,revision=c.changeset.raw_id))}</span>
68 <span class="label label-tag" title="${_('Tag %s') % tag}">${h.link_to(tag,h.url('changeset_home',repo_name=c.repo_name,revision=c.changeset.raw_id))}</span>
69 %endfor
69 %endfor
70
70
71 %if c.changeset.branch:
71 %for branch in c.changeset.branches:
72 <span class="label label-branch" title="${_('Branch %s') % c.changeset.branch}">${h.link_to(c.changeset.branch,h.url('changelog_home',repo_name=c.repo_name,branch=c.changeset.branch))}</span>
72 <span class="label label-branch" title="${_('Branch %s') % branch}">${h.link_to(branch,h.url('changelog_home',repo_name=c.repo_name,branch=branch))}</span>
73 %endif
73 %endfor
74 </span>
74 </span>
75
75
76 <div class="changes">
76 <div class="changes">
@@ -90,11 +90,11 b''
90 <span class="label label-tag" title="${_('Tag %s') % tag}">
90 <span class="label label-tag" title="${_('Tag %s') % tag}">
91 ${h.link_to(tag,h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}</span>
91 ${h.link_to(tag,h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}</span>
92 %endfor
92 %endfor
93 %if cs.branch:
93 %for branch in cs.branches:
94 <span class="label label-branch" title="${_('Branch %s') % cs.branch}">
94 <span class="label label-branch" title="${_('Branch %s') % branch}">
95 ${h.link_to(cs.branch,h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}
95 ${h.link_to(branch,h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}
96 </span>
96 </span>
97 %endif
97 %endfor
98 </span>
98 </span>
99 </div>
99 </div>
100 </div>
100 </div>
@@ -53,6 +53,7 b' class BranchesTestCaseMixin(_BackendTest'
53 )
53 )
54 assert 'foobar' in self.repo.branches
54 assert 'foobar' in self.repo.branches
55 assert foobar_tip.branch == 'foobar'
55 assert foobar_tip.branch == 'foobar'
56 assert foobar_tip.branches == ['foobar']
56
57
57 def test_new_head(self):
58 def test_new_head(self):
58 tip = self.repo.get_changeset()
59 tip = self.repo.get_changeset()
@@ -81,6 +82,7 b' class BranchesTestCaseMixin(_BackendTest'
81 )
82 )
82
83
83 assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
84 assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
85 assert newest_tip.branches == [self.backend_class.DEFAULT_BRANCH_NAME]
84
86
85 def test_branch_with_slash_in_name(self):
87 def test_branch_with_slash_in_name(self):
86 self.imc.add(vcs.nodes.FileNode('extrafile', content='Some data\n'))
88 self.imc.add(vcs.nodes.FileNode('extrafile', content='Some data\n'))
@@ -78,6 +78,7 b' class _ChangesetsWithCommitsTestCaseixin'
78 )
78 )
79 assert 'foobar' in self.repo.branches
79 assert 'foobar' in self.repo.branches
80 assert foobar_tip.branch == 'foobar'
80 assert foobar_tip.branch == 'foobar'
81 assert foobar_tip.branches == ['foobar']
81 # 'foobar' should be the only branch that contains the new commit
82 # 'foobar' should be the only branch that contains the new commit
82 branch_tips = self.repo.branches.values()
83 branch_tips = self.repo.branches.values()
83 assert branch_tips.count(str(foobar_tip.raw_id)) == 1
84 assert branch_tips.count(str(foobar_tip.raw_id)) == 1
@@ -109,6 +110,7 b' class _ChangesetsWithCommitsTestCaseixin'
109 )
110 )
110
111
111 assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
112 assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME
113 assert newest_tip.branches == [self.backend_class.DEFAULT_BRANCH_NAME]
112
114
113 def test_get_changesets_respects_branch_name(self):
115 def test_get_changesets_respects_branch_name(self):
114 tip = self.repo.get_changeset()
116 tip = self.repo.get_changeset()
@@ -309,16 +309,19 b' class TestGitChangeset(object):'
309 rev0 = self.repo.revisions[0]
309 rev0 = self.repo.revisions[0]
310 chset0 = self.repo.get_changeset(rev0)
310 chset0 = self.repo.get_changeset(rev0)
311 assert chset0.branch is None # should be 'master'?
311 assert chset0.branch is None # should be 'master'?
312 assert chset0.branches == [] # should be 'master'?
312 assert chset0.tags == []
313 assert chset0.tags == []
313
314
314 rev10 = self.repo.revisions[10]
315 rev10 = self.repo.revisions[10]
315 chset10 = self.repo.get_changeset(rev10)
316 chset10 = self.repo.get_changeset(rev10)
316 assert chset10.branch is None # should be 'master'?
317 assert chset10.branch is None # should be 'master'?
318 assert chset10.branches == [] # should be 'master'?
317 assert chset10.tags == []
319 assert chset10.tags == []
318
320
319 rev44 = self.repo.revisions[44]
321 rev44 = self.repo.revisions[44]
320 chset44 = self.repo.get_changeset(rev44)
322 chset44 = self.repo.get_changeset(rev44)
321 assert chset44.branch is None # should be 'web-branch'?
323 assert chset44.branch is None # should be 'web-branch'?
324 assert chset44.branches == [] # should be 'web-branch'?
322
325
323 tip = self.repo.get_changeset('tip')
326 tip = self.repo.get_changeset('tip')
324 assert 'tip' not in tip.tags # it should be?
327 assert 'tip' not in tip.tags # it should be?
@@ -320,14 +320,17 b' class TestMercurialChangeset(object):'
320 def test_branch_and_tags(self):
320 def test_branch_and_tags(self):
321 chset0 = self.repo.get_changeset(0)
321 chset0 = self.repo.get_changeset(0)
322 assert chset0.branch == 'default'
322 assert chset0.branch == 'default'
323 assert chset0.branches == ['default']
323 assert chset0.tags == []
324 assert chset0.tags == []
324
325
325 chset10 = self.repo.get_changeset(10)
326 chset10 = self.repo.get_changeset(10)
326 assert chset10.branch == 'default'
327 assert chset10.branch == 'default'
328 assert chset10.branches == ['default']
327 assert chset10.tags == []
329 assert chset10.tags == []
328
330
329 chset44 = self.repo.get_changeset(44)
331 chset44 = self.repo.get_changeset(44)
330 assert chset44.branch == 'web'
332 assert chset44.branch == 'web'
333 assert chset44.branches == ['web']
331
334
332 tip = self.repo.get_changeset('tip')
335 tip = self.repo.get_changeset('tip')
333 assert 'tip' in tip.tags
336 assert 'tip' in tip.tags
General Comments 0
You need to be logged in to leave comments. Login now