Mercurial > public > mercurial-scm > hg
comparison mercurial/utils/storageutil.py @ 40009:631c6f5058b9
storageutil: make all callables optional
Not all storage backends may implement these callables. That's part
of the reason these methods aren't exposed on the storage interface.
Differential Revision: https://phab.mercurial-scm.org/D4804
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 16:16:09 -0700 |
parents | 842ffcf1d42f |
children | f5d819d84461 |
comparison
equal
deleted
inserted
replaced
40008:842ffcf1d42f | 40009:631c6f5058b9 |
---|---|
16 nullid, | 16 nullid, |
17 nullrev, | 17 nullrev, |
18 ) | 18 ) |
19 from .. import ( | 19 from .. import ( |
20 error, | 20 error, |
21 mdiff, | |
21 pycompat, | 22 pycompat, |
22 ) | 23 ) |
23 | 24 |
24 _nullhash = hashlib.sha1(nullid) | 25 _nullhash = hashlib.sha1(nullid) |
25 | 26 |
261 if plinkrev >= minlinkrev: | 262 if plinkrev >= minlinkrev: |
262 futurelargelinkrevs.add(plinkrev) | 263 futurelargelinkrevs.add(plinkrev) |
263 | 264 |
264 return strippoint, brokenrevs | 265 return strippoint, brokenrevs |
265 | 266 |
266 def emitrevisions(store, revs, resultcls, deltaparentfn, candeltafn, | 267 def emitrevisions(store, revs, resultcls, deltaparentfn=None, candeltafn=None, |
267 rawsizefn, revdifffn, flagsfn, sendfulltext=False, | 268 rawsizefn=None, revdifffn=None, flagsfn=None, |
269 sendfulltext=False, | |
268 revisiondata=False, assumehaveparentrevisions=False, | 270 revisiondata=False, assumehaveparentrevisions=False, |
269 deltaprevious=False): | 271 deltaprevious=False): |
270 """Generic implementation of ifiledata.emitrevisions(). | 272 """Generic implementation of ifiledata.emitrevisions(). |
271 | 273 |
272 Emitting revision data is subtly complex. This function attempts to | 274 Emitting revision data is subtly complex. This function attempts to |
280 | 282 |
281 ``resultcls`` | 283 ``resultcls`` |
282 A type implementing the ``irevisiondelta`` interface that will be | 284 A type implementing the ``irevisiondelta`` interface that will be |
283 constructed and returned. | 285 constructed and returned. |
284 | 286 |
285 ``deltaparentfn`` | 287 ``deltaparentfn`` (optional) |
286 Callable receiving a revision number and returning the revision number | 288 Callable receiving a revision number and returning the revision number |
287 of a revision that the internal delta is stored against. This delta | 289 of a revision that the internal delta is stored against. This delta |
288 will be preferred over computing a new arbitrary delta. | 290 will be preferred over computing a new arbitrary delta. |
289 | 291 |
290 ``candeltafn`` | 292 If not defined, a delta will always be computed from raw revision |
293 data. | |
294 | |
295 ``candeltafn`` (optional) | |
291 Callable receiving a pair of revision numbers that returns a bool | 296 Callable receiving a pair of revision numbers that returns a bool |
292 indicating whether a delta between them can be produced. | 297 indicating whether a delta between them can be produced. |
293 | 298 |
294 ``rawsizefn`` | 299 If not defined, it is assumed that any two revisions can delta with |
300 each other. | |
301 | |
302 ``rawsizefn`` (optional) | |
295 Callable receiving a revision number and returning the length of the | 303 Callable receiving a revision number and returning the length of the |
296 ``store.revision(rev, raw=True)``. | 304 ``store.revision(rev, raw=True)``. |
297 | 305 |
298 ``revdifffn`` | 306 If not defined, ``len(store.revision(rev, raw=True))`` will be called. |
307 | |
308 ``revdifffn`` (optional) | |
299 Callable receiving a pair of revision numbers that returns a delta | 309 Callable receiving a pair of revision numbers that returns a delta |
300 between them. | 310 between them. |
301 | 311 |
302 ``flagsfn`` | 312 If not defined, a delta will be computed by invoking mdiff code |
313 on ``store.revision()`` results. | |
314 | |
315 Defining this function allows a precomputed or stored delta to be | |
316 used without having to compute on. | |
317 | |
318 ``flagsfn`` (optional) | |
303 Callable receiving a revision number and returns the integer flags | 319 Callable receiving a revision number and returns the integer flags |
304 value for it. | 320 value for it. If not defined, flags value will be 0. |
305 | 321 |
306 ``sendfulltext`` | 322 ``sendfulltext`` |
307 Whether to send fulltext revisions instead of deltas, if allowed. | 323 Whether to send fulltext revisions instead of deltas, if allowed. |
308 | 324 |
309 ``revisiondata`` | 325 ``revisiondata`` |
325 for rev in revs: | 341 for rev in revs: |
326 if rev == nullrev: | 342 if rev == nullrev: |
327 continue | 343 continue |
328 | 344 |
329 node = fnode(rev) | 345 node = fnode(rev) |
330 deltaparentrev = deltaparentfn(rev) | |
331 p1rev, p2rev = store.parentrevs(rev) | 346 p1rev, p2rev = store.parentrevs(rev) |
347 | |
348 if deltaparentfn: | |
349 deltaparentrev = deltaparentfn(rev) | |
350 else: | |
351 deltaparentrev = nullrev | |
332 | 352 |
333 # Forced delta against previous mode. | 353 # Forced delta against previous mode. |
334 if deltaprevious: | 354 if deltaprevious: |
335 baserev = prevrev | 355 baserev = prevrev |
336 | 356 |
371 else: | 391 else: |
372 baserev = nullrev | 392 baserev = nullrev |
373 | 393 |
374 # But we can't actually use our chosen delta base for whatever | 394 # But we can't actually use our chosen delta base for whatever |
375 # reason. Reset to fulltext. | 395 # reason. Reset to fulltext. |
376 if baserev != nullrev and not candeltafn(baserev, rev): | 396 if baserev != nullrev and (candeltafn and not candeltafn(baserev, rev)): |
377 baserev = nullrev | 397 baserev = nullrev |
378 | 398 |
379 revision = None | 399 revision = None |
380 delta = None | 400 delta = None |
381 baserevisionsize = None | 401 baserevisionsize = None |
386 revision = store.revision(node, raw=True) | 406 revision = store.revision(node, raw=True) |
387 except error.CensoredNodeError as e: | 407 except error.CensoredNodeError as e: |
388 revision = e.tombstone | 408 revision = e.tombstone |
389 | 409 |
390 if baserev != nullrev: | 410 if baserev != nullrev: |
391 baserevisionsize = rawsizefn(baserev) | 411 if rawsizefn: |
412 baserevisionsize = rawsizefn(baserev) | |
413 else: | |
414 baserevisionsize = len(store.revision(baserev, | |
415 raw=True)) | |
392 | 416 |
393 elif baserev == nullrev and not deltaprevious: | 417 elif baserev == nullrev and not deltaprevious: |
394 revision = store.revision(node, raw=True) | 418 revision = store.revision(node, raw=True) |
395 available.add(rev) | 419 available.add(rev) |
396 else: | 420 else: |
397 delta = revdifffn(baserev, rev) | 421 if revdifffn: |
422 delta = revdifffn(baserev, rev) | |
423 else: | |
424 delta = mdiff.textdiff(store.revision(baserev, raw=True), | |
425 store.revision(rev, raw=True)) | |
426 | |
398 available.add(rev) | 427 available.add(rev) |
399 | 428 |
400 yield resultcls( | 429 yield resultcls( |
401 node=node, | 430 node=node, |
402 p1node=fnode(p1rev), | 431 p1node=fnode(p1rev), |
403 p2node=fnode(p2rev), | 432 p2node=fnode(p2rev), |
404 basenode=fnode(baserev), | 433 basenode=fnode(baserev), |
405 flags=flagsfn(rev), | 434 flags=flagsfn(rev) if flagsfn else 0, |
406 baserevisionsize=baserevisionsize, | 435 baserevisionsize=baserevisionsize, |
407 revision=revision, | 436 revision=revision, |
408 delta=delta) | 437 delta=delta) |
409 | 438 |
410 prevrev = rev | 439 prevrev = rev |