hgext/evolve.py
changeset 823 9aa20585e158
parent 821 202376586cf6
child 824 fed090e07621
equal deleted inserted replaced
822:5f5d269278e9 823:9aa20585e158
    61 from mercurial import templatekw
    61 from mercurial import templatekw
    62 from mercurial.i18n import _
    62 from mercurial.i18n import _
    63 from mercurial.commands import walkopts, commitopts, commitopts2
    63 from mercurial.commands import walkopts, commitopts, commitopts2
    64 from mercurial.node import nullid
    64 from mercurial.node import nullid
    65 from mercurial import wireproto
    65 from mercurial import wireproto
       
    66 from mercurial import localrepo
    66 
    67 
    67 _pack = struct.pack
    68 _pack = struct.pack
    68 
    69 
    69 
    70 
    70 # This extension contains the following code
    71 # This extension contains the following code
  2181             tr.release()
  2182             tr.release()
  2182     finally:
  2183     finally:
  2183         lock.release()
  2184         lock.release()
  2184     return wireproto.pushres(0)
  2185     return wireproto.pushres(0)
  2185 
  2186 
       
  2187 @eh.wrapfunction(exchange, '_pullobsolete')
       
  2188 def _pullobsolete(orig, pullop):
       
  2189     if not obsolete._enabled:
       
  2190         return None
       
  2191     if not pullop.remote.capable('_evoext_pullobsmarkers_0'):
       
  2192         return orig(pullop)
       
  2193     tr = None
       
  2194     ui = pullop.repo.ui
       
  2195     ui.status("OBSEXC: pull obsolescence markers\n")
       
  2196     obsdata = pullop.remote.evoext_pullobsmarkers_0()
       
  2197     obsdata = obsdata.read()
       
  2198     if len(obsdata) > 5:
       
  2199         ui.status("OBSEXC: merging obsolescence markers (%i bytes)\n"
       
  2200                        % len(obsdata))
       
  2201         tr = pullop.gettransaction()
       
  2202         old = len(pullop.repo.obsstore._all)
       
  2203         pullop.repo.obsstore.mergemarkers(tr, obsdata)
       
  2204         new = len(pullop.repo.obsstore._all) - old
       
  2205         ui.status("OBSEXC: %i markers added\n" % new)
       
  2206         if new:
       
  2207             pullop.repo.invalidatevolatilesets()
       
  2208     ui.status("OBSEXC: DONE\n")
       
  2209     return tr
       
  2210 
       
  2211 def _getobsmarkersstream(repo, heads=None, common=None):
       
  2212     revset = ''
       
  2213     args = []
       
  2214     repo = repo.unfiltered()
       
  2215     if heads is None:
       
  2216         revset = 'all()'
       
  2217     elif heads:
       
  2218         revset += "(::%ln)"
       
  2219         args.append(heads)
       
  2220     else:
       
  2221         assert False, 'pulling no heads?'
       
  2222     if common:
       
  2223         revset += ' - (::%ln)'
       
  2224         args.append(common)
       
  2225     nodes = [c.node() for c in repo.set(revset, *args)]
       
  2226     markers = repo.obsstore.relevantmarkers(nodes)
       
  2227     obsdata = StringIO()
       
  2228     _encodemarkersstream(obsdata, markers)
       
  2229     obsdata.seek(0)
       
  2230     return obsdata
       
  2231 
       
  2232 @eh.addattr(wireproto.wirepeer, 'evoext_pullobsmarkers_0')
       
  2233 def client_pullobsmarkers(self, heads=None, common=None):
       
  2234     self.requirecap('_evoext_pullobsmarkers_0', _('look up remote obsmarkers'))
       
  2235     opts = {}
       
  2236     if heads is not None:
       
  2237         opts['heads'] = wireproto.encodelist(heads)
       
  2238     if common is not None:
       
  2239         opts['common'] = wireproto.encodelist(common)
       
  2240     f = self._callstream("evoext_pullobsmarkers_0", **opts)
       
  2241     f = self._decompress(f)
       
  2242     length= int(f.read(20))
       
  2243     return StringIO(f.read(length))
       
  2244 
       
  2245 @eh.addattr(localrepo.localpeer, 'evoext_pullobsmarkers_0')
       
  2246 def local_pullobsmarkers(self, heads=None, common=None):
       
  2247     return _getobsmarkersstream(self._repo, heads=heads, common=common)
       
  2248 
       
  2249 def srv_pullobsmarkers(repo, proto, others):
       
  2250     opts = wireproto.options('', ['heads', 'common'], others)
       
  2251     for k, v in opts.iteritems():
       
  2252         if k in ('heads', 'common'):
       
  2253             opts[k] = wireproto.decodelist(v)
       
  2254     obsdata = _getobsmarkersstream(repo, **opts)
       
  2255     length = '%20i' % len(obsdata.getvalue())
       
  2256     def data():
       
  2257         yield length
       
  2258         for c in proto.groupchunks(obsdata):
       
  2259             yield c
       
  2260     return wireproto.streamres(data())
       
  2261 
  2186 @eh.wrapfunction(wireproto, 'capabilities')
  2262 @eh.wrapfunction(wireproto, 'capabilities')
  2187 def capabilities(orig, repo, proto):
  2263 def capabilities(orig, repo, proto):
  2188     """wrapper to advertise new capability"""
  2264     """wrapper to advertise new capability"""
  2189     caps = orig(repo, proto)
  2265     caps = orig(repo, proto)
  2190     if obsolete._enabled:
  2266     if obsolete._enabled:
  2191         caps += ' _evoext_pushobsmarkers_0'
  2267         caps += ' _evoext_pushobsmarkers_0'
       
  2268         caps += ' _evoext_pullobsmarkers_0'
  2192     return caps
  2269     return caps
  2193 
  2270 
  2194 @eh.extsetup
  2271 @eh.extsetup
  2195 def _installwireprotocol(ui):
  2272 def _installwireprotocol(ui):
       
  2273     localrepo.MODERNCAPS.add('_evoext_pullobsmarkers_0')
  2196     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
  2274     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
       
  2275     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')