Mercurial > kallithea
comparison rhodecode/controllers/compare.py @ 3811:3591b33e0c94 beta
hg: use 'revset injection safe' repo.revs for revsets
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 08 Apr 2013 21:59:09 +0200 |
parents | f533c054fb19 |
children | 4324d6899e55 |
comparison
equal
deleted
inserted
replaced
3810:13b7e04af99b | 3811:3591b33e0c94 |
---|---|
103 'book': 'bookmark', | 103 'book': 'bookmark', |
104 'tag': 'tag', | 104 'tag': 'tag', |
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 |
119 if org_repo != other_repo: | 117 if org_repo != other_repo: |
120 hgrepo = unionrepo.unionrepository(other_repo.baseui, | 118 hgrepo = unionrepo.unionrepository(other_repo.baseui, |
126 #no remote compare do it on the same repository | 124 #no remote compare do it on the same repository |
127 else: | 125 else: |
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: |
149 raise Exception('Comparing of different GIT repositories is not' | 145 raise Exception('Comparing of different GIT repositories is not' |
150 'allowed. Got %s != %s' % (org_repo, other_repo)) | 146 'allowed. Got %s != %s' % (org_repo, other_repo)) |