##// END OF EJS Templates
hg: use 'revset injection safe' repo.revs for revsets
Mads Kiilerich -
r3811:3591b33e beta
parent child Browse files
Show More
@@ -105,14 +105,12 b' class CompareController(BaseRepoControll'
105 'rev': 'id',
105 'rev': 'id',
106 }
106 }
107
107
108 org_rev_spec = "max(%s('%s'))" % (_revset_predicates[org_ref[0]],
108 org_rev_spec = "max(%s(%%s))" % _revset_predicates[org_ref[0]]
109 safe_str(org_ref[1]))
109 org_revs = org_repo._repo.revs(org_rev_spec, safe_str(org_ref[1]))
110 org_revs = scmutil.revrange(org_repo._repo, [org_rev_spec])
111 org_rev = org_repo._repo[org_revs[-1] if org_revs else -1].hex()
110 org_rev = org_repo._repo[org_revs[-1] if org_revs else -1].hex()
112
111
113 other_rev_spec = "max(%s('%s'))" % (_revset_predicates[other_ref[0]],
112 other_revs_spec = "max(%s(%%s))" % _revset_predicates[other_ref[0]]
114 safe_str(other_ref[1]))
113 other_revs = other_repo._repo.revs(other_revs_spec, safe_str(other_ref[1]))
115 other_revs = scmutil.revrange(other_repo._repo, [other_rev_spec])
116 other_rev = other_repo._repo[other_revs[-1] if other_revs else -1].hex()
114 other_rev = other_repo._repo[other_revs[-1] if other_revs else -1].hex()
117
115
118 #case two independent repos
116 #case two independent repos
@@ -128,21 +126,19 b' class CompareController(BaseRepoControll'
128 hgrepo = other_repo._repo
126 hgrepo = other_repo._repo
129
127
130 if merge:
128 if merge:
131 revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" %
129 revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
132 (other_rev, org_rev, org_rev)]
130 other_rev, org_rev, org_rev)
133
131
134 ancestors = scmutil.revrange(hgrepo,
132 ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev, other_rev)
135 ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
136 if ancestors:
133 if ancestors:
137 # pick arbitrary ancestor - but there is usually only one
134 # pick arbitrary ancestor - but there is usually only one
138 ancestor = hgrepo[ancestors[0]].hex()
135 ancestor = hgrepo[ancestors[0]].hex()
139 else:
136 else:
140 # TODO: have both + and - changesets
137 # TODO: have both + and - changesets
141 revs = ["id('%s') :: id('%s') - id('%s')" %
138 revs = hgrepo.revs("id(%s) :: id(%s) - id(%s)",
142 (org_rev, other_rev, org_rev)]
139 org_rev, other_rev, org_rev)
143
140
144 changesets = [other_repo.get_changeset(cs)
141 changesets = [other_repo.get_changeset(rev) for rev in revs]
145 for cs in scmutil.revrange(hgrepo, revs)]
146
142
147 elif alias == 'git':
143 elif alias == 'git':
148 if org_repo != other_repo:
144 if org_repo != other_repo:
@@ -70,7 +70,10 b' class PullrequestsController(BaseRepoCon'
70
70
71 def _get_repo_refs(self, repo, rev=None, branch_rev=None):
71 def _get_repo_refs(self, repo, rev=None, branch_rev=None):
72 """return a structure with repo's interesting changesets, suitable for
72 """return a structure with repo's interesting changesets, suitable for
73 the selectors in pullrequest.html"""
73 the selectors in pullrequest.html
74
75 rev: a revision that must be in the list and selected by default
76 branch_rev: a revision of which peers should be preferred and available."""
74 # list named branches that has been merged to this named branch - it should probably merge back
77 # list named branches that has been merged to this named branch - it should probably merge back
75 peers = []
78 peers = []
76
79
@@ -81,29 +84,32 b' class PullrequestsController(BaseRepoCon'
81 branch_rev = safe_str(branch_rev)
84 branch_rev = safe_str(branch_rev)
82 # not restricting to merge() would also get branch point and be better
85 # not restricting to merge() would also get branch point and be better
83 # (especially because it would get the branch point) ... but is currently too expensive
86 # (especially because it would get the branch point) ... but is currently too expensive
84 revs = ["sort(parents(branch(id('%s')) and merge()) - branch(id('%s')))" %
85 (branch_rev, branch_rev)]
86 otherbranches = {}
87 otherbranches = {}
87 for i in scmutil.revrange(repo._repo, revs):
88 for i in repo._repo.revs(
89 "sort(parents(branch(id(%s)) and merge()) - branch(id(%s)))",
90 branch_rev, branch_rev):
88 cs = repo.get_changeset(i)
91 cs = repo.get_changeset(i)
89 otherbranches[cs.branch] = cs.raw_id
92 otherbranches[cs.branch] = cs.raw_id
90 for branch, node in otherbranches.iteritems():
93 for abranch, node in otherbranches.iteritems():
91 selected = 'branch:%s:%s' % (branch, node)
94 selected = 'branch:%s:%s' % (abranch, node)
92 peers.append((selected, branch))
95 peers.append((selected, abranch))
93
96
94 selected = None
97 selected = None
98
95 branches = []
99 branches = []
96 for branch, branchrev in repo.branches.iteritems():
100 for abranch, branchrev in repo.branches.iteritems():
97 n = 'branch:%s:%s' % (branch, branchrev)
101 n = 'branch:%s:%s' % (abranch, branchrev)
98 branches.append((n, branch))
102 branches.append((n, abranch))
99 if rev == branchrev:
103 if rev == branchrev:
100 selected = n
104 selected = n
105
101 bookmarks = []
106 bookmarks = []
102 for bookmark, bookmarkrev in repo.bookmarks.iteritems():
107 for bookmark, bookmarkrev in repo.bookmarks.iteritems():
103 n = 'book:%s:%s' % (bookmark, bookmarkrev)
108 n = 'book:%s:%s' % (bookmark, bookmarkrev)
104 bookmarks.append((n, bookmark))
109 bookmarks.append((n, bookmark))
105 if rev == bookmarkrev:
110 if rev == bookmarkrev:
106 selected = n
111 selected = n
112
107 tags = []
113 tags = []
108 for tag, tagrev in repo.tags.iteritems():
114 for tag, tagrev in repo.tags.iteritems():
109 n = 'tag:%s:%s' % (tag, tagrev)
115 n = 'tag:%s:%s' % (tag, tagrev)
General Comments 0
You need to be logged in to leave comments. Login now