Mercurial > evolve
comparison hgext/evolve.py @ 1471:4140d680784e
evolve: (issue4386) cleanup, split, fold and bijection in `hg prune`
Before this patch, the prune command was splitting and folding implicitely
based on the number of successors and precursors. This patch makes the
two behavior explicit by requesting a flag to perform a split or a fold.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Thu, 25 Jun 2015 13:33:50 -0700 |
parents | fa1a27009c76 |
children | 9603aa1ecdfd |
comparison
equal
deleted
inserted
replaced
1470:c3f6e97c71b1 | 1471:4140d680784e |
---|---|
2135 [('n', 'new', [], _("successor changeset (DEPRECATED)")), | 2135 [('n', 'new', [], _("successor changeset (DEPRECATED)")), |
2136 ('s', 'succ', [], _("successor changeset")), | 2136 ('s', 'succ', [], _("successor changeset")), |
2137 ('r', 'rev', [], _("revisions to prune")), | 2137 ('r', 'rev', [], _("revisions to prune")), |
2138 ('k', 'keep', None, _("does not modify working copy during prune")), | 2138 ('k', 'keep', None, _("does not modify working copy during prune")), |
2139 ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")), | 2139 ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")), |
2140 ('', 'fold', False, _("record a fold (multiple precursors, one successors)")), | |
2141 ('', 'split', False, _("record a split (on precursor, multiple successors)")), | |
2140 ('B', 'bookmark', '', _("remove revs only reachable from given" | 2142 ('B', 'bookmark', '', _("remove revs only reachable from given" |
2141 " bookmark"))] + metadataopts, | 2143 " bookmark"))] + metadataopts, |
2142 _('[OPTION] [-r] REV...')) | 2144 _('[OPTION] [-r] REV...')) |
2143 # -U --noupdate option to prevent wc update and or bookmarks update ? | 2145 # -U --noupdate option to prevent wc update and or bookmarks update ? |
2144 def cmdprune(ui, repo, *revs, **opts): | 2146 def cmdprune(ui, repo, *revs, **opts): |
2157 | 2159 |
2158 You can use the ``--biject`` option to specify a 1-1 (bijection) between | 2160 You can use the ``--biject`` option to specify a 1-1 (bijection) between |
2159 revisions to prune and successor changesets. This option may be removed in | 2161 revisions to prune and successor changesets. This option may be removed in |
2160 a future release (with the functionality absorbed automatically). | 2162 a future release (with the functionality absorbed automatically). |
2161 | 2163 |
2164 If you specify multiple revisions in --succ, you are recording a "split" | |
2165 and have to acknowledge it by usng --split. The same logic apply when you | |
2166 prune multiple changesets with a single successors, this will record a | |
2167 "fold" requires a --fold flag. | |
2162 """ | 2168 """ |
2163 revs = scmutil.revrange(repo, list(revs) + opts.get('rev')) | 2169 revs = scmutil.revrange(repo, list(revs) + opts.get('rev')) |
2164 succs = opts['new'] + opts['succ'] | 2170 succs = opts['new'] + opts['succ'] |
2165 bookmark = opts.get('bookmark') | 2171 bookmark = opts.get('bookmark') |
2166 metadata = _getmetadata(**opts) | 2172 metadata = _getmetadata(**opts) |
2167 biject = opts.get('biject') | 2173 biject = opts.get('biject') |
2174 fold = opts.get('fold') | |
2175 split = opts.get('split') | |
2176 | |
2177 options = [o for o in ('biject', 'fold', 'split') if opts.get(o)] | |
2178 if 1 < len(options): | |
2179 raise util.Abort(_("can only specify one of %s") % ', '.join(options)) | |
2168 | 2180 |
2169 if bookmark: | 2181 if bookmark: |
2170 marks,revs = _reachablefrombookmark(repo, revs, bookmark) | 2182 marks,revs = _reachablefrombookmark(repo, revs, bookmark) |
2171 if not revs: | 2183 if not revs: |
2172 # no revisions to prune - delete bookmark immediately | 2184 # no revisions to prune - delete bookmark immediately |
2202 sucs.sort() | 2214 sucs.sort() |
2203 sucs = tuple(repo[n] for n in sucs) | 2215 sucs = tuple(repo[n] for n in sucs) |
2204 if not biject and len(sucs) > 1 and len(precs) > 1: | 2216 if not biject and len(sucs) > 1 and len(precs) > 1: |
2205 msg = "Can't use multiple successors for multiple precursors" | 2217 msg = "Can't use multiple successors for multiple precursors" |
2206 raise util.Abort(msg) | 2218 raise util.Abort(msg) |
2207 | 2219 elif biject and len(sucs) != len(precs): |
2208 if biject and len(sucs) != len(precs): | |
2209 msg = "Can't use %d successors for %d precursors" \ | 2220 msg = "Can't use %d successors for %d precursors" \ |
2210 % (len(sucs), len(precs)) | 2221 % (len(sucs), len(precs)) |
2211 raise util.Abort(msg) | 2222 raise util.Abort(msg) |
2212 | 2223 elif (len(precs) == 1 and len(sucs) > 1) and not split: |
2213 relations = [(p, sucs) for p in precs] | 2224 msg = "please add --split if you want to do a split" |
2214 if biject: | 2225 raise util.Abort(msg) |
2226 elif len(sucs) == 1 and len(precs) > 1 and not fold: | |
2227 msg = "please add --fold if you want to do a fold" | |
2228 raise util.Abort(msg) | |
2229 elif biject: | |
2215 relations = [(p, (s,)) for p, s in zip(precs, sucs)] | 2230 relations = [(p, (s,)) for p, s in zip(precs, sucs)] |
2231 else: | |
2232 relations = [(p, sucs) for p in precs] | |
2216 | 2233 |
2217 wdp = repo['.'] | 2234 wdp = repo['.'] |
2218 | 2235 |
2219 if len(sucs) == 1 and len(precs) == 1 and wdp in precs: | 2236 if len(sucs) == 1 and len(precs) == 1 and wdp in precs: |
2220 # '.' killed, so update to the successor | 2237 # '.' killed, so update to the successor |