comparison hgext/evolve.py @ 1563:6a9f0261b181

prune: remove a list of bookmarks Currently prune works with a single bookmark, the changes in this patch modifies the prune module to work with a list of bookmarks Building on this we can take a list of bookmarks as input and remove all of them in a single go
author Shubhanshu Agrawal <agrawal.shubhanshu@gmail.com>
date Fri, 11 Dec 2015 10:42:46 -0800
parents dbf1532ee868
children 42c30774e63d
comparison
equal deleted inserted replaced
1562:b1158ce4ec50 1563:6a9f0261b181
2206 ui.status(_('working directory now at %s\n') % repo['.']) 2206 ui.status(_('working directory now at %s\n') % repo['.'])
2207 return result 2207 return result
2208 return 1 2208 return 1
2209 return result 2209 return result
2210 2210
2211 def _reachablefrombookmark(repo, revs, bookmark): 2211 def _reachablefrombookmark(repo, revs, bookmarks):
2212 """filter revisions and bookmarks reachable from the given bookmark 2212 """filter revisions and bookmarks reachable from the given bookmark
2213 yoinked from mq.py 2213 yoinked from mq.py
2214 """ 2214 """
2215 repomarks = repo._bookmarks 2215 repomarks = repo._bookmarks
2216 if bookmark not in repomarks: 2216 if not bookmarks.issubset(repomarks):
2217 raise error.Abort(_("bookmark '%s' not found") % bookmark) 2217 raise error.Abort(_("bookmark '%s' not found") %
2218 ','.join(sorted(bookmarks - set(repomarks.keys()))))
2218 2219
2219 # If the requested bookmark is not the only one pointing to a 2220 # If the requested bookmark is not the only one pointing to a
2220 # a revision we have to only delete the bookmark and not strip 2221 # a revision we have to only delete the bookmark and not strip
2221 # anything. revsets cannot detect that case. 2222 # anything. revsets cannot detect that case.
2222 uniquebm = True 2223 nodetobookmarks = {}
2223 for m, n in repomarks.iteritems(): 2224 for mark, node in repomarks.iteritems():
2224 if m != bookmark and n == repo[bookmark].node(): 2225 nodetobookmarks.setdefault(node, []).append(mark)
2225 uniquebm = False 2226 for marks in nodetobookmarks.values():
2226 break 2227 if bookmarks.issuperset(marks):
2227 if uniquebm: 2228 if util.safehasattr(repair, 'stripbmrevset'):
2228 if util.safehasattr(repair, 'stripbmrevset'): 2229 rsrevs = repair.stripbmrevset(repo, marks[0])
2229 rsrevs = repair.stripbmrevset(repo, bookmark) 2230 else:
2230 else: 2231 rsrevs = repo.revs("ancestors(bookmark(%s)) - "
2231 rsrevs = repo.revs("ancestors(bookmark(%s)) - " 2232 "ancestors(head() and not bookmark(%s)) - "
2232 "ancestors(head() and not bookmark(%s)) - " 2233 "ancestors(bookmark() and not bookmark(%s)) - "
2233 "ancestors(bookmark() and not bookmark(%s)) - " 2234 "obsolete()",
2234 "obsolete()", 2235 marks[0], marks[0], marks[0])
2235 bookmark, bookmark, bookmark) 2236 revs = set(revs)
2236 revs = set(revs) 2237 revs.update(set(rsrevs))
2237 revs.update(set(rsrevs)) 2238 revs = sorted(revs)
2238 revs = sorted(revs)
2239 return repomarks, revs 2239 return repomarks, revs
2240 2240
2241 def _deletebookmark(repo, repomarks, bookmark): 2241 def _deletebookmark(repo, repomarks, bookmarks):
2242 wlock = lock = tr = None 2242 wlock = lock = tr = None
2243 try: 2243 try:
2244 wlock = repo.wlock() 2244 wlock = repo.wlock()
2245 lock = repo.lock() 2245 lock = repo.lock()
2246 tr = repo.transaction('prune') 2246 tr = repo.transaction('prune')
2247 del repomarks[bookmark] 2247 for bookmark in bookmarks:
2248 del repomarks[bookmark]
2248 repomarks.recordchange(tr) 2249 repomarks.recordchange(tr)
2249 tr.close() 2250 tr.close()
2250 repo.ui.write(_("bookmark '%s' deleted\n") % bookmark) 2251 for bookmark in sorted(bookmarks):
2252 repo.ui.write(_("bookmark '%s' deleted\n") % bookmark)
2251 finally: 2253 finally:
2252 lockmod.release(tr, lock, wlock) 2254 lockmod.release(tr, lock, wlock)
2253 2255
2254 2256
2255 2257
2301 prune multiple changesets with a single successors, this will record a 2303 prune multiple changesets with a single successors, this will record a
2302 "fold" requires a --fold flag. 2304 "fold" requires a --fold flag.
2303 """ 2305 """
2304 revs = scmutil.revrange(repo, list(revs) + opts.get('rev')) 2306 revs = scmutil.revrange(repo, list(revs) + opts.get('rev'))
2305 succs = opts['new'] + opts['succ'] 2307 succs = opts['new'] + opts['succ']
2306 bookmark = opts.get('bookmark') 2308 bookmarks = None
2309 if opts.get('bookmark'):
2310 bookmarks = set([opts.get('bookmark')])
2307 metadata = _getmetadata(**opts) 2311 metadata = _getmetadata(**opts)
2308 biject = opts.get('biject') 2312 biject = opts.get('biject')
2309 fold = opts.get('fold') 2313 fold = opts.get('fold')
2310 split = opts.get('split') 2314 split = opts.get('split')
2311 2315
2312 options = [o for o in ('biject', 'fold', 'split') if opts.get(o)] 2316 options = [o for o in ('biject', 'fold', 'split') if opts.get(o)]
2313 if 1 < len(options): 2317 if 1 < len(options):
2314 raise error.Abort(_("can only specify one of %s") % ', '.join(options)) 2318 raise error.Abort(_("can only specify one of %s") % ', '.join(options))
2315 2319
2316 if bookmark: 2320 if bookmarks:
2317 repomarks, revs = _reachablefrombookmark(repo, revs, bookmark) 2321 repomarks, revs = _reachablefrombookmark(repo, revs, bookmarks)
2318 if not revs: 2322 if not revs:
2319 # no revisions to prune - delete bookmark immediately 2323 # no revisions to prune - delete bookmark immediately
2320 _deletebookmark(repo, repomarks, bookmark) 2324 _deletebookmark(repo, repomarks, bookmarks)
2321 2325
2322 if not revs: 2326 if not revs:
2323 raise error.Abort(_('nothing to prune')) 2327 raise error.Abort(_('nothing to prune'))
2324 2328
2325 wlock = lock = tr = None 2329 wlock = lock = tr = None
2404 else: 2408 else:
2405 bookactive = bmactive(repo) 2409 bookactive = bmactive(repo)
2406 # Active bookmark that we don't want to delete (with -B option) 2410 # Active bookmark that we don't want to delete (with -B option)
2407 # we deactivate and move it before the update and reactivate it 2411 # we deactivate and move it before the update and reactivate it
2408 # after 2412 # after
2409 movebookmark = bookactive and not bookmark 2413 movebookmark = bookactive and not bookmarks
2410 if movebookmark: 2414 if movebookmark:
2411 bmdeactivate(repo) 2415 bmdeactivate(repo)
2412 repo._bookmarks[bookactive] = newnode.node() 2416 repo._bookmarks[bookactive] = newnode.node()
2413 repo._bookmarks.recordchange(tr) 2417 repo._bookmarks.recordchange(tr)
2414 commands.update(ui, repo, newnode.rev()) 2418 commands.update(ui, repo, newnode.rev())
2415 ui.status(_('working directory now at %s\n') % newnode) 2419 ui.status(_('working directory now at %s\n') % newnode)
2416 if movebookmark: 2420 if movebookmark:
2417 bmactivate(repo, bookactive) 2421 bmactivate(repo, bookactive)
2418 2422
2419 # update bookmarks 2423 # update bookmarks
2420 if bookmark: 2424 if bookmarks:
2421 _deletebookmark(repo, repomarks, bookmark) 2425 _deletebookmark(repo, repomarks, bookmarks)
2422 2426
2423 # create markers 2427 # create markers
2424 obsolete.createmarkers(repo, relations, metadata=metadata) 2428 obsolete.createmarkers(repo, relations, metadata=metadata)
2425 2429
2426 # informs that changeset have been pruned 2430 # informs that changeset have been pruned