Mercurial > evolve
comparison hgext/evolve.py @ 715:070bbbb0e6f2 stable
prune: add strip-like bookmark
This prune changesets pointed by the specified bookmark only (and removes the
bookmarks)
author | Levi Bard <levi@unity3d.com> |
---|---|
date | Mon, 11 Feb 2013 09:21:11 +0000 |
parents | 3867f7b1fe6e |
children | 4c0f6d555032 |
comparison
equal
deleted
inserted
replaced
714:3867f7b1fe6e | 715:070bbbb0e6f2 |
---|---|
1240 for c in children: | 1240 for c in children: |
1241 displayer.show(c) | 1241 displayer.show(c) |
1242 ui.warn(_('Multiple non-obsolete children, explicitly update to one\n')) | 1242 ui.warn(_('Multiple non-obsolete children, explicitly update to one\n')) |
1243 return 1 | 1243 return 1 |
1244 | 1244 |
1245 def _reachablefrombookmark(repo, revs, mark): | |
1246 """filter revisions and bookmarks reachable from the given bookmark | |
1247 yoinked from mq.py | |
1248 """ | |
1249 marks = repo._bookmarks | |
1250 if mark not in marks: | |
1251 raise util.Abort(_("bookmark '%s' not found") % mark) | |
1252 | |
1253 # If the requested bookmark is not the only one pointing to a | |
1254 # a revision we have to only delete the bookmark and not strip | |
1255 # anything. revsets cannot detect that case. | |
1256 uniquebm = True | |
1257 for m, n in marks.iteritems(): | |
1258 if m != mark and n == repo[mark].node(): | |
1259 uniquebm = False | |
1260 break | |
1261 if uniquebm: | |
1262 rsrevs = repo.revs("ancestors(bookmark(%s)) - " | |
1263 "ancestors(head() and not bookmark(%s)) - " | |
1264 "ancestors(bookmark() and not bookmark(%s)) - " | |
1265 "obsolete()", | |
1266 mark, mark, mark) | |
1267 revs.update(set(rsrevs)) | |
1268 return marks,revs | |
1269 | |
1270 def _deletebookmark(ui, marks, mark): | |
1271 del marks[mark] | |
1272 marks.write() | |
1273 ui.write(_("bookmark '%s' deleted\n") % mark) | |
1274 | |
1245 @command('^prune|obsolete|kill', | 1275 @command('^prune|obsolete|kill', |
1246 [('n', 'new', [], _("successor changeset (DEPRECATED)")), | 1276 [('n', 'new', [], _("successor changeset (DEPRECATED)")), |
1247 ('s', 'succ', [], _("successor changeset")), | 1277 ('s', 'succ', [], _("successor changeset")), |
1248 ('r', 'rev', [], _("revisions to prune"))], | 1278 ('r', 'rev', [], _("revisions to prune")), |
1279 ('B', 'bookmark', '', _("remove revs only reachable from given" | |
1280 " bookmark"))], | |
1249 _('[OPTION] [-r] REV...')) | 1281 _('[OPTION] [-r] REV...')) |
1250 # -d --date | 1282 # -d --date |
1251 # -u --user | 1283 # -u --user |
1252 # -U --noupdate option to prevent wc update and or bookmarks update ? | 1284 # -U --noupdate option to prevent wc update and or bookmarks update ? |
1253 def cmdprune(ui, repo, *revs, **opts): | 1285 def cmdprune(ui, repo, *revs, **opts): |
1261 When the working directory parent is pruned the repository is updated to a | 1293 When the working directory parent is pruned the repository is updated to a |
1262 non obsolete parents. | 1294 non obsolete parents. |
1263 | 1295 |
1264 you can use the ``--succ`` option to informs mercurial that a newer version | 1296 you can use the ``--succ`` option to informs mercurial that a newer version |
1265 of the pruned changeset exists. | 1297 of the pruned changeset exists. |
1266 | 1298 """ |
1267 XXX this commands needs bookmarks support. | 1299 revs = set(scmutil.revrange(repo, list(revs) + opts.get('rev'))) |
1268 """ | |
1269 revs = list(revs) | |
1270 revs.extend(opts['rev']) | |
1271 succs = opts['new'] + opts['succ'] | 1300 succs = opts['new'] + opts['succ'] |
1301 bookmark = opts.get('bookmark') | |
1302 | |
1303 if bookmark: | |
1304 marks,revs = _reachablefrombookmark(repo, revs, bookmark) | |
1305 if not revs: | |
1306 # no revisions to prune - delete bookmark immediately | |
1307 _deletebookmark(ui, marks, bookmark) | |
1308 | |
1309 if not revs: | |
1310 raise util.Abort(_('nothing to prune')) | |
1311 | |
1272 wlock = lock = None | 1312 wlock = lock = None |
1273 wlock = repo.wlock() | 1313 wlock = repo.wlock() |
1274 sortedrevs = lambda specs: sorted(set(scmutil.revrange(repo, specs))) | 1314 sortedrevs = lambda specs: sorted(set(scmutil.revrange(repo, specs))) |
1275 try: | 1315 try: |
1276 lock = repo.lock() | 1316 lock = repo.lock() |
1301 while newnode.obsolete(): | 1341 while newnode.obsolete(): |
1302 newnode = newnode.parents()[0] | 1342 newnode = newnode.parents()[0] |
1303 if newnode.node() != wdp.node(): | 1343 if newnode.node() != wdp.node(): |
1304 commands.update(ui, repo, newnode.rev()) | 1344 commands.update(ui, repo, newnode.rev()) |
1305 ui.status(_('working directory now at %s\n') % newnode) | 1345 ui.status(_('working directory now at %s\n') % newnode) |
1306 # upVdate bookmarks | 1346 # update bookmarks |
1347 if bookmark: | |
1348 _deletebookmark(ui, marks, bookmark) | |
1307 for ctx in repo.unfiltered().set('bookmark() and %ld', precs): | 1349 for ctx in repo.unfiltered().set('bookmark() and %ld', precs): |
1308 ldest = list(repo.set('max((::%d) - obsolete())', ctx)) | 1350 ldest = list(repo.set('max((::%d) - obsolete())', ctx)) |
1309 if ldest: | 1351 if ldest: |
1310 dest = ldest[0] | 1352 dest = ldest[0] |
1311 updatebookmarks = _bookmarksupdater(repo, ctx.node()) | 1353 updatebookmarks = _bookmarksupdater(repo, ctx.node()) |
1312 updatebookmarks(dest.node()) | 1354 updatebookmarks(dest.node()) |
1313 else: | |
1314 # delete bookmarks | |
1315 pass | |
1316 finally: | 1355 finally: |
1317 lockmod.release(lock, wlock) | 1356 lockmod.release(lock, wlock) |
1318 | 1357 |
1319 @command('amend|refresh', | 1358 @command('amend|refresh', |
1320 [('A', 'addremove', None, | 1359 [('A', 'addremove', None, |