comparison hgext/obsolete.py @ 112:eae9be0ee00e

adapt obsolete to phase.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Mon, 19 Dec 2011 14:05:25 +0100
parents a2e8057117d3
children 1a64195e2b09
comparison
equal deleted inserted replaced
111:ab4cef4fbd03 112:eae9be0ee00e
99 99
100 def obsolete(ctx): 100 def obsolete(ctx):
101 """is the changeset obsolete by other""" 101 """is the changeset obsolete by other"""
102 if ctx.node()is None: 102 if ctx.node()is None:
103 return False 103 return False
104 return bool(ctx._repo.obsoletedby(ctx.node())) and ctx.state().mutable 104 return bool(ctx._repo.obsoletedby(ctx.node())) and ctx.phase()
105 105
106 context.changectx.obsolete = obsolete 106 context.changectx.obsolete = obsolete
107 107
108 ohidden = context.changectx.hidden 108 ohidden = context.changectx.hidden
109 def hidden(ctx): 109 def hidden(ctx):
112 XXX we need something cleaner""" 112 XXX we need something cleaner"""
113 # hack to fill hiddenrevs 113 # hack to fill hiddenrevs
114 # compute hidden (XXX should move elsewhere) 114 # compute hidden (XXX should move elsewhere)
115 if not getattr(ctx._repo.changelog, 'hiddeninit', False): 115 if not getattr(ctx._repo.changelog, 'hiddeninit', False):
116 shown = ['not obsolete()', '.', 'bookmark()', 'tagged()', 116 shown = ['not obsolete()', '.', 'bookmark()', 'tagged()',
117 'publishedheads()'] 117 'public()']
118 basicquery = 'obsolete() - (::(%s))' % (' or '.join(shown)) 118 basicquery = 'obsolete() - (::(%s))' % (' or '.join(shown))
119 ctx._repo.changelog.hiddenrevs.update( 119 ctx._repo.changelog.hiddenrevs.update(
120 scmutil.revrange(ctx._repo, [basicquery])) 120 scmutil.revrange(ctx._repo, [basicquery]))
121 ctx._repo.changelog.hiddeninit = True 121 ctx._repo.changelog.hiddeninit = True
122 122
124 context.changectx.hidden = hidden 124 context.changectx.hidden = hidden
125 125
126 ### revset 126 ### revset
127 ############################# 127 #############################
128 128
129 def revsetpublic(repo, subset, x):
130 args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
131 # XXX slow stop using context
132 return [r for r in subset if repo._phaserev[r] == 0]
133
129 def revsetobsolete(repo, subset, x): 134 def revsetobsolete(repo, subset, x):
130 """filter obsolet entry""" 135 """filter obsolet entry"""
131 args = revset.getargs(x, 0, 0, 'publicheads takes no arguments') 136 args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
132 # XXX slow stop using context 137 # XXX slow stop using context
133 return [r for r in subset if r in repo._obsoleteset] 138 return [r for r in subset if r in repo._obsoleteset and repo._phaserev[r] > 0]
134 139
135 ### Other Extension compat 140 ### Other Extension compat
136 ############################ 141 ############################
137 142
138 def concludenode(orig, repo, rev, *args, **kwargs): 143 def concludenode(orig, repo, rev, *args, **kwargs):
176 heads = sorted(map(repo.changelog.node, selected)) 181 heads = sorted(map(repo.changelog.node, selected))
177 182
178 return common, heads 183 return common, heads
179 184
180 def extsetup(ui): 185 def extsetup(ui):
181 try:
182 rebase = extensions.find('states')
183 except KeyError:
184 raise error.Abort(_('obsolete extension require states extension.'))
185 186
186 revset.symbols["obsolete"] = revsetobsolete 187 revset.symbols["obsolete"] = revsetobsolete
188 revset.symbols["public"] = revsetpublic
187 189
188 extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout) 190 extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout)
189 191
190 try: 192 try:
191 rebase = extensions.find('rebase') 193 rebase = extensions.find('rebase')
346 if sub == nullid: 348 if sub == nullid:
347 sub = None 349 sub = None
348 self._obssubrels.setdefault(sub, set()).add(obj) 350 self._obssubrels.setdefault(sub, set()).add(obj)
349 self._obsobjrels.setdefault(obj, set()).add(sub) 351 self._obsobjrels.setdefault(obj, set()).add(sub)
350 try: 352 try:
351 if not self.nodestate(obj).mutable: 353 if self[obj].phase() == 0:
352 if sub is None: 354 if sub is None:
353 self.ui.warn( 355 self.ui.warn(
354 _("trying to kill immutable changeset %(obj)s\n") 356 _("trying to kill immutable changeset %(obj)s\n")
355 % {'obj': short(obj)}) 357 % {'obj': short(obj)})
356 if sub is not None: 358 if sub is not None:
461 journalpath = self.join(journalname) 463 journalpath = self.join(journalname)
462 util.copyfile(filepath, journalpath) 464 util.copyfile(filepath, journalpath)
463 entries.append(journalpath) 465 entries.append(journalpath)
464 return tuple(entries) 466 return tuple(entries)
465 467
466 def rollback(self, dryrun=False): 468 def rollback(self, dryrun=False, **kwargs):
467 """wrapped version of rollback that restore obsolete data""" 469 """wrapped version of rollback that restore obsolete data"""
468 wlock = lock = None 470 wlock = lock = None
469 try: 471 try:
470 wlock = self.wlock() 472 wlock = self.wlock()
471 lock = self.lock() 473 lock = self.lock()
472 ret = orollback(dryrun) 474 ret = orollback(dryrun, **kwargs)
473 if not (ret or dryrun): #rollback did not failed 475 if not (ret or dryrun): #rollback did not failed
474 src = self.join('undo.obsolete-relations') 476 src = self.join('undo.obsolete-relations')
475 dst = self.join('obsolete-relations') 477 dst = self.join('obsolete-relations')
476 if os.path.exists(src): 478 if os.path.exists(src):
477 util.rename(src, dst) 479 util.rename(src, dst)