Mercurial > hg
annotate hgext/remotefilelog/repack.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 5fadf6103790 |
children | 687b865b95ad |
rev | line source |
---|---|
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 import os |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 import time |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 from mercurial.i18n import _ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 from mercurial.node import ( |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 nullid, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 short, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 ) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 from mercurial import ( |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 encoding, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 error, |
42943
5fadf6103790
remotefilelog: replace repack lock to solve race condition
Boris Feld <boris.feld@octobus.net>
parents:
42842
diff
changeset
|
14 lock as lockmod, |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 mdiff, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 policy, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 pycompat, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 scmutil, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 util, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 vfs, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 ) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 from mercurial.utils import procutil |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 from . import ( |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 constants, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 contentstore, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 datapack, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 historypack, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 metadatastore, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 shallowutil, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 ) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 osutil = policy.importmod(r'osutil') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
34 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 class RepackAlreadyRunning(error.Abort): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 pass |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
38 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
39 def backgroundrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
40 repo, incremental=True, packsonly=False, ensurestart=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
41 ): |
40711
72d88a975655
remotefilelog: drop some compatibility cruft for finding the hg exeutable
Matt Harbison <matt_harbison@yahoo.com>
parents:
40613
diff
changeset
|
42 cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'repack'] |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 msg = _("(running background repack)\n") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 if incremental: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 cmd.append('--incremental') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 msg = _("(running background incremental repack)\n") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 if packsonly: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 cmd.append('--packsonly') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 repo.ui.warn(msg) |
42497
df1419c5756a
remotefilelog: tell runbgcommand to not block on child process startup
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
50 # We know this command will find a binary, so don't block on it starting. |
42842
2c74337e6483
remotefilelog: reduce probability of race-condition in remotefilelog tests
Boris Feld <boris.feld@octobus.net>
parents:
42497
diff
changeset
|
51 procutil.runbgcommand(cmd, encoding.environ, ensurestart=ensurestart) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
53 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 def fullrepack(repo, options=None): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 """If ``packsonly`` is True, stores creating only loose objects are skipped. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 if util.safehasattr(repo, 'shareddatastores'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
58 datasource = contentstore.unioncontentstore(*repo.shareddatastores) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 historysource = metadatastore.unionmetadatastore( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
60 *repo.sharedhistorystores, allowincomplete=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
61 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 packpath = shallowutil.getcachepackpath( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
64 repo, constants.FILEPACK_CATEGORY |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
65 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
66 _runrepack( |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
68 datasource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
69 historysource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
70 packpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
71 constants.FILEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
72 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
73 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 if util.safehasattr(repo.manifestlog, 'datastore'): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 localdata, shareddata = _getmanifeststores(repo) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 lpackpath, ldstores, lhstores = localdata |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 spackpath, sdstores, shstores = shareddata |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 # Repack the shared manifest store |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 datasource = contentstore.unioncontentstore(*sdstores) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 historysource = metadatastore.unionmetadatastore( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
83 *shstores, allowincomplete=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
84 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
85 _runrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
86 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
87 datasource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
88 historysource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
89 spackpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
90 constants.TREEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
91 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
92 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 # Repack the local manifest store |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 datasource = contentstore.unioncontentstore( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
96 *ldstores, allowincomplete=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
97 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 historysource = metadatastore.unionmetadatastore( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
99 *lhstores, allowincomplete=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
100 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
101 _runrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
102 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
103 datasource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
104 historysource, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
105 lpackpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
106 constants.TREEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
107 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
108 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
109 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
111 def incrementalrepack(repo, options=None): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 """This repacks the repo by looking at the distribution of pack files in the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 repo and performing the most minimal repack to keep the repo in good shape. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 if util.safehasattr(repo, 'shareddatastores'): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 packpath = shallowutil.getcachepackpath( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
117 repo, constants.FILEPACK_CATEGORY |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
118 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
119 _incrementalrepack( |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
121 repo.shareddatastores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
122 repo.sharedhistorystores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
123 packpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
124 constants.FILEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
125 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
126 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 if util.safehasattr(repo.manifestlog, 'datastore'): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 localdata, shareddata = _getmanifeststores(repo) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 lpackpath, ldstores, lhstores = localdata |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 spackpath, sdstores, shstores = shareddata |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 # Repack the shared manifest store |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
134 _incrementalrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
135 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
136 sdstores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
137 shstores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
138 spackpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
139 constants.TREEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
140 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
141 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 # Repack the local manifest store |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
144 _incrementalrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
145 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
146 ldstores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
147 lhstores, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
148 lpackpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
149 constants.TREEPACK_CATEGORY, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
150 allowincompletedata=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
151 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
152 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
153 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 def _getmanifeststores(repo): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 shareddatastores = repo.manifestlog.shareddatastores |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 localdatastores = repo.manifestlog.localdatastores |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 sharedhistorystores = repo.manifestlog.sharedhistorystores |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 localhistorystores = repo.manifestlog.localhistorystores |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
161 sharedpackpath = shallowutil.getcachepackpath( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
162 repo, constants.TREEPACK_CATEGORY |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
163 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
164 localpackpath = shallowutil.getlocalpackpath( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
165 repo.svfs.vfs.base, constants.TREEPACK_CATEGORY |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
166 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
168 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
169 (localpackpath, localdatastores, localhistorystores), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
170 (sharedpackpath, shareddatastores, sharedhistorystores), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
171 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
172 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 def _topacks(packpath, files, constructor): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 paths = list(os.path.join(packpath, p) for p in files) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 packs = list(constructor(p) for p in paths) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 return packs |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
179 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 def _deletebigpacks(repo, folder, files): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 """Deletes packfiles that are bigger than ``packs.maxpacksize``. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 Returns ``files` with the removed files omitted.""" |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 maxsize = repo.ui.configbytes("packs", "maxpacksize") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 if maxsize <= 0: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 return files |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 # This only considers datapacks today, but we could broaden it to include |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 # historypacks. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 VALIDEXTS = [".datapack", ".dataidx"] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 # Either an oversize index or datapack will trigger cleanup of the whole |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 # pack: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
194 oversized = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
195 os.path.splitext(path)[0] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
196 for path, ftype, stat in files |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
197 if (stat.st_size > maxsize and (os.path.splitext(path)[1] in VALIDEXTS)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
198 } |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 for rootfname in oversized: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 rootpath = os.path.join(folder, rootfname) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 for ext in VALIDEXTS: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 path = rootpath + ext |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
204 repo.ui.debug( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
205 'removing oversize packfile %s (%s)\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
206 % (path, util.bytecount(os.stat(path).st_size)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
207 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 os.unlink(path) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 return [row for row in files if os.path.basename(row[0]) not in oversized] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
211 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
212 def _incrementalrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
213 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
214 datastore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
215 historystore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
216 packpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
217 category, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
218 allowincompletedata=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
219 options=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
220 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
221 shallowutil.mkstickygroupdir(repo.ui, packpath) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
223 files = osutil.listdir(packpath, stat=True) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 files = _deletebigpacks(repo, packpath, files) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
225 datapacks = _topacks( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
226 packpath, _computeincrementaldatapack(repo.ui, files), datapack.datapack |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
227 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
228 datapacks.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
229 s for s in datastore if not isinstance(s, datapack.datapackstore) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
230 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
232 historypacks = _topacks( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
233 packpath, |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 _computeincrementalhistorypack(repo.ui, files), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
235 historypack.historypack, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
236 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
237 historypacks.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
238 s |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
239 for s in historystore |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
240 if not isinstance(s, historypack.historypackstore) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
241 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
243 # ``allhistory{files,packs}`` contains all known history packs, even ones we |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
244 # don't plan to repack. They are used during the datapack repack to ensure |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 # good ordering of nodes. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
246 allhistoryfiles = _allpackfileswithsuffix( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
247 files, historypack.PACKSUFFIX, historypack.INDEXSUFFIX |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
248 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
249 allhistorypacks = _topacks( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
250 packpath, |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 (f for f, mode, stat in allhistoryfiles), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
252 historypack.historypack, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
253 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
254 allhistorypacks.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
255 s |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
256 for s in historystore |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
257 if not isinstance(s, historypack.historypackstore) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
258 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
259 _runrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
260 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
261 contentstore.unioncontentstore( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
262 *datapacks, allowincomplete=allowincompletedata |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
263 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
264 metadatastore.unionmetadatastore(*historypacks, allowincomplete=True), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
265 packpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
266 category, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
267 fullhistory=metadatastore.unionmetadatastore( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
268 *allhistorypacks, allowincomplete=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
269 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
270 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
271 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
272 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 def _computeincrementaldatapack(ui, files): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
275 opts = { |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
276 'gencountlimit': ui.configint('remotefilelog', 'data.gencountlimit'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
277 'generations': ui.configlist('remotefilelog', 'data.generations'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
278 'maxrepackpacks': ui.configint('remotefilelog', 'data.maxrepackpacks'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
279 'repackmaxpacksize': ui.configbytes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
280 'remotefilelog', 'data.repackmaxpacksize' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
281 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
282 'repacksizelimit': ui.configbytes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
283 'remotefilelog', 'data.repacksizelimit' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
284 ), |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
285 } |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
286 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
287 packfiles = _allpackfileswithsuffix( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
288 files, datapack.PACKSUFFIX, datapack.INDEXSUFFIX |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
289 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
290 return _computeincrementalpack(packfiles, opts) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
291 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
292 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
293 def _computeincrementalhistorypack(ui, files): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
294 opts = { |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
295 'gencountlimit': ui.configint('remotefilelog', 'history.gencountlimit'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
296 'generations': ui.configlist( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
297 'remotefilelog', 'history.generations', ['100MB'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
298 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
299 'maxrepackpacks': ui.configint( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
300 'remotefilelog', 'history.maxrepackpacks' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
301 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
302 'repackmaxpacksize': ui.configbytes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
303 'remotefilelog', 'history.repackmaxpacksize', '400MB' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
304 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
305 'repacksizelimit': ui.configbytes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
306 'remotefilelog', 'history.repacksizelimit' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
307 ), |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
308 } |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
309 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
310 packfiles = _allpackfileswithsuffix( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
311 files, historypack.PACKSUFFIX, historypack.INDEXSUFFIX |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
312 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
313 return _computeincrementalpack(packfiles, opts) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
314 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
315 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
316 def _allpackfileswithsuffix(files, packsuffix, indexsuffix): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
317 result = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
318 fileset = set(fn for fn, mode, stat in files) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
319 for filename, mode, stat in files: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
320 if not filename.endswith(packsuffix): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
321 continue |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
322 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
323 prefix = filename[: -len(packsuffix)] |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
324 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
325 # Don't process a pack if it doesn't have an index. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
326 if (prefix + indexsuffix) not in fileset: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
327 continue |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
328 result.append((prefix, mode, stat)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
329 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
330 return result |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
331 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
332 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
333 def _computeincrementalpack(files, opts): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
334 """Given a set of pack files along with the configuration options, this |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
335 function computes the list of files that should be packed as part of an |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
336 incremental repack. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
337 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
338 It tries to strike a balance between keeping incremental repacks cheap (i.e. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
339 packing small things when possible, and rolling the packs up to the big ones |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
340 over time). |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
341 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
342 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
343 limits = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
344 sorted((util.sizetoint(s) for s in opts['generations']), reverse=True) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
345 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
346 limits.append(0) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
347 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
348 # Group the packs by generation (i.e. by size) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
349 generations = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
350 for i in pycompat.xrange(len(limits)): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
351 generations.append([]) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
352 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
353 sizes = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
354 for prefix, mode, stat in files: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
355 size = stat.st_size |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 if size > opts['repackmaxpacksize']: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
357 continue |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
358 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
359 sizes[prefix] = size |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
360 for i, limit in enumerate(limits): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
361 if size > limit: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
362 generations[i].append(prefix) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
363 break |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
364 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
365 # Steps for picking what packs to repack: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
366 # 1. Pick the largest generation with > gencountlimit pack files. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
367 # 2. Take the smallest three packs. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
368 # 3. While total-size-of-packs < repacksizelimit: add another pack |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
369 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
370 # Find the largest generation with more than gencountlimit packs |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
371 genpacks = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
372 for i, limit in enumerate(limits): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
373 if len(generations[i]) > opts['gencountlimit']: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
374 # Sort to be smallest last, for easy popping later |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
375 genpacks.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
376 sorted(generations[i], reverse=True, key=lambda x: sizes[x]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
377 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
378 break |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
379 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
380 # Take as many packs from the generation as we can |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
381 chosenpacks = genpacks[-3:] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
382 genpacks = genpacks[:-3] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
383 repacksize = sum(sizes[n] for n in chosenpacks) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
384 while ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
385 repacksize < opts['repacksizelimit'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
386 and genpacks |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
387 and len(chosenpacks) < opts['maxrepackpacks'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
388 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
389 chosenpacks.append(genpacks.pop()) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
390 repacksize += sizes[chosenpacks[-1]] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
391 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
392 return chosenpacks |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
393 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
394 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
395 def _runrepack( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
396 repo, data, history, packpath, category, fullhistory=None, options=None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
397 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
398 shallowutil.mkstickygroupdir(repo.ui, packpath) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
399 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
400 def isold(repo, filename, node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
401 """Check if the file node is older than a limit. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
402 Unless a limit is specified in the config the default limit is taken. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
403 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
404 filectx = repo.filectx(filename, fileid=node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
405 filetime = repo[filectx.linkrev()].date() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
406 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
407 ttl = repo.ui.configint('remotefilelog', 'nodettl') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
408 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
409 limit = time.time() - ttl |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
410 return filetime[0] < limit |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
411 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
412 garbagecollect = repo.ui.configbool('remotefilelog', 'gcrepack') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
413 if not fullhistory: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
414 fullhistory = history |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
415 packer = repacker( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
416 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
417 data, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
418 history, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
419 fullhistory, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
420 category, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
421 gc=garbagecollect, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
422 isold=isold, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
423 options=options, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
424 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
425 |
41806
118c1ec4f31b
remotefilelog: do not specify an explicit version for repack
Kyle Lippincott <spectral@google.com>
parents:
41365
diff
changeset
|
426 with datapack.mutabledatapack(repo.ui, packpath) as dpack: |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
427 with historypack.mutablehistorypack(repo.ui, packpath) as hpack: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
428 try: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
429 packer.run(dpack, hpack) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
430 except error.LockHeld: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
431 raise RepackAlreadyRunning( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
432 _("skipping repack - another repack " "is already running") |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
433 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
434 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
435 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
436 def keepset(repo, keyfn, lastkeepkeys=None): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
437 """Computes a keepset which is not garbage collected. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
438 'keyfn' is a function that maps filename, node to a unique key. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
439 'lastkeepkeys' is an optional argument and if provided the keepset |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
440 function updates lastkeepkeys with more keys and returns the result. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
441 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
442 if not lastkeepkeys: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
443 keepkeys = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
444 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
445 keepkeys = lastkeepkeys |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
446 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
447 # We want to keep: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
448 # 1. Working copy parent |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
449 # 2. Draft commits |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
450 # 3. Parents of draft commits |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
451 # 4. Pullprefetch and bgprefetchrevs revsets if specified |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
452 revs = ['.', 'draft()', 'parents(draft())'] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
453 prefetchrevs = repo.ui.config('remotefilelog', 'pullprefetch', None) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
454 if prefetchrevs: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
455 revs.append('(%s)' % prefetchrevs) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
456 prefetchrevs = repo.ui.config('remotefilelog', 'bgprefetchrevs', None) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
457 if prefetchrevs: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
458 revs.append('(%s)' % prefetchrevs) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
459 revs = '+'.join(revs) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
460 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
461 revs = ['sort((%s), "topo")' % revs] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
462 keep = scmutil.revrange(repo, revs) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
463 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
464 processed = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
465 lastmanifest = None |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
466 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
467 # process the commits in toposorted order starting from the oldest |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
468 for r in reversed(keep._list): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
469 if repo[r].p1().rev() in processed: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
470 # if the direct parent has already been processed |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
471 # then we only need to process the delta |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
472 m = repo[r].manifestctx().readdelta() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
473 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
474 # otherwise take the manifest and diff it |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
475 # with the previous manifest if one exists |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
476 if lastmanifest: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
477 m = repo[r].manifest().diff(lastmanifest) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
478 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
479 m = repo[r].manifest() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
480 lastmanifest = repo[r].manifest() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
481 processed.add(r) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
482 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
483 # populate keepkeys with keys from the current manifest |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
484 if type(m) is dict: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
485 # m is a result of diff of two manifests and is a dictionary that |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
486 # maps filename to ((newnode, newflag), (oldnode, oldflag)) tuple |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
487 for filename, diff in m.iteritems(): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
488 if diff[0][0] is not None: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
489 keepkeys.add(keyfn(filename, diff[0][0])) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
490 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
491 # m is a manifest object |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
492 for filename, filenode in m.iteritems(): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
493 keepkeys.add(keyfn(filename, filenode)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
494 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
495 return keepkeys |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
496 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
497 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
498 class repacker(object): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
499 """Class for orchestrating the repack of data and history information into a |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
500 new format. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
501 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
502 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
503 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
504 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
505 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
506 data, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
507 history, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
508 fullhistory, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
509 category, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
510 gc=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
511 isold=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
512 options=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
513 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
514 self.repo = repo |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
515 self.data = data |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
516 self.history = history |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
517 self.fullhistory = fullhistory |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
518 self.unit = constants.getunits(category) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
519 self.garbagecollect = gc |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
520 self.options = options |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
521 if self.garbagecollect: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
522 if not isold: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
523 raise ValueError("Function 'isold' is not properly specified") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
524 # use (filename, node) tuple as a keepset key |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
525 self.keepkeys = keepset(repo, lambda f, n: (f, n)) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
526 self.isold = isold |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
527 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
528 def run(self, targetdata, targethistory): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
529 ledger = repackledger() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
530 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
531 with lockmod.lock( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
532 repacklockvfs(self.repo), "repacklock", desc=None, timeout=0 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
533 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
534 self.repo.hook('prerepack') |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
535 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
536 # Populate ledger from source |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
537 self.data.markledger(ledger, options=self.options) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
538 self.history.markledger(ledger, options=self.options) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
539 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
540 # Run repack |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
541 self.repackdata(ledger, targetdata) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
542 self.repackhistory(ledger, targethistory) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
543 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
544 # Call cleanup on each source |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
545 for source in ledger.sources: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
546 source.cleanup(ledger) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
547 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
548 def _chainorphans(self, ui, filename, nodes, orphans, deltabases): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
549 """Reorderes ``orphans`` into a single chain inside ``nodes`` and |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
550 ``deltabases``. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
551 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
552 We often have orphan entries (nodes without a base that aren't |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
553 referenced by other nodes -- i.e., part of a chain) due to gaps in |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
554 history. Rather than store them as individual fulltexts, we prefer to |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
555 insert them as one chain sorted by size. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
556 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
557 if not orphans: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
558 return nodes |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
559 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
560 def getsize(node, default=0): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
561 meta = self.data.getmeta(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
562 if constants.METAKEYSIZE in meta: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
563 return meta[constants.METAKEYSIZE] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
564 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
565 return default |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
566 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
567 # Sort orphans by size; biggest first is preferred, since it's more |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
568 # likely to be the newest version assuming files grow over time. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
569 # (Sort by node first to ensure the sort is stable.) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
570 orphans = sorted(orphans) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
571 orphans = list(sorted(orphans, key=getsize, reverse=True)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
572 if ui.debugflag: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
573 ui.debug( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
574 "%s: orphan chain: %s\n" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
575 % (filename, ", ".join([short(s) for s in orphans])) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
576 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
577 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
578 # Create one contiguous chain and reassign deltabases. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
579 for i, node in enumerate(orphans): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
580 if i == 0: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
581 deltabases[node] = (nullid, 0) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
582 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
583 parent = orphans[i - 1] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
584 deltabases[node] = (parent, deltabases[parent][1] + 1) |
41255
60b3edccf2f7
remotefilelog: use list comprehension instead of filter for py3 portability
Augie Fackler <augie@google.com>
parents:
40843
diff
changeset
|
585 nodes = [n for n in nodes if n not in orphans] |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
586 nodes += orphans |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
587 return nodes |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
588 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
589 def repackdata(self, ledger, target): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
590 ui = self.repo.ui |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
591 maxchainlen = ui.configint('packs', 'maxchainlen', 1000) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
592 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
593 byfile = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
594 for entry in ledger.entries.itervalues(): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
595 if entry.datasource: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
596 byfile.setdefault(entry.filename, {})[entry.node] = entry |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
597 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
598 count = 0 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
599 repackprogress = ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
600 _("repacking data"), unit=self.unit, total=len(byfile) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
601 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
602 for filename, entries in sorted(byfile.iteritems()): |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
603 repackprogress.update(count) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
604 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
605 ancestors = {} |
40613
9769e0f6ffe0
py3: don't use dict.iterkeys()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40526
diff
changeset
|
606 nodes = list(node for node in entries) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
607 nohistory = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
608 buildprogress = ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
609 _("building history"), unit='nodes', total=len(nodes) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
610 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
611 for i, node in enumerate(nodes): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
612 if node in ancestors: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
613 continue |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
614 buildprogress.update(i) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
615 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
616 ancestors.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
617 self.fullhistory.getancestors( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
618 filename, node, known=ancestors |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
619 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
620 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
621 except KeyError: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
622 # Since we're packing data entries, we may not have the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
623 # corresponding history entries for them. It's not a big |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
624 # deal, but the entries won't be delta'd perfectly. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
625 nohistory.append(node) |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
626 buildprogress.complete() |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
627 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
628 # Order the nodes children first, so we can produce reverse deltas |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
629 orderednodes = list(reversed(self._toposort(ancestors))) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
630 if len(nohistory) > 0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
631 ui.debug( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
632 'repackdata: %d nodes without history\n' % len(nohistory) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
633 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
634 orderednodes.extend(sorted(nohistory)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
635 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
636 # Filter orderednodes to just the nodes we want to serialize (it |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
637 # currently also has the edge nodes' ancestors). |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
638 orderednodes = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
639 filter(lambda node: node in nodes, orderednodes) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
640 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
641 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
642 # Garbage collect old nodes: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
643 if self.garbagecollect: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
644 neworderednodes = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
645 for node in orderednodes: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
646 # If the node is old and is not in the keepset, we skip it, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
647 # and mark as garbage collected |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
648 if (filename, node) not in self.keepkeys and self.isold( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
649 self.repo, filename, node |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
650 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
651 entries[node].gced = True |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
652 continue |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
653 neworderednodes.append(node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
654 orderednodes = neworderednodes |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
655 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
656 # Compute delta bases for nodes: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
657 deltabases = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
658 nobase = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
659 referenced = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
660 nodes = set(nodes) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
661 processprogress = ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
662 _("processing nodes"), unit='nodes', total=len(orderednodes) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
663 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
664 for i, node in enumerate(orderednodes): |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
665 processprogress.update(i) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
666 # Find delta base |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
667 # TODO: allow delta'ing against most recent descendant instead |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
668 # of immediate child |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
669 deltatuple = deltabases.get(node, None) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
670 if deltatuple is None: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
671 deltabase, chainlen = nullid, 0 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
672 deltabases[node] = (nullid, 0) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
673 nobase.add(node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
674 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
675 deltabase, chainlen = deltatuple |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
676 referenced.add(deltabase) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
677 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
678 # Use available ancestor information to inform our delta choices |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
679 ancestorinfo = ancestors.get(node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
680 if ancestorinfo: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
681 p1, p2, linknode, copyfrom = ancestorinfo |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
682 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
683 # The presence of copyfrom means we're at a point where the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
684 # file was copied from elsewhere. So don't attempt to do any |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
685 # deltas with the other file. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
686 if copyfrom: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
687 p1 = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
688 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
689 if chainlen < maxchainlen: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
690 # Record this child as the delta base for its parents. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
691 # This may be non optimal, since the parents may have |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
692 # many children, and this will only choose the last one. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
693 # TODO: record all children and try all deltas to find |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
694 # best |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
695 if p1 != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
696 deltabases[p1] = (node, chainlen + 1) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
697 if p2 != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
698 deltabases[p2] = (node, chainlen + 1) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
699 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
700 # experimental config: repack.chainorphansbysize |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
701 if ui.configbool('repack', 'chainorphansbysize'): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
702 orphans = nobase - referenced |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
703 orderednodes = self._chainorphans( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
704 ui, filename, orderednodes, orphans, deltabases |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
705 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
706 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
707 # Compute deltas and write to the pack |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
708 for i, node in enumerate(orderednodes): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
709 deltabase, chainlen = deltabases[node] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
710 # Compute delta |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
711 # TODO: Optimize the deltachain fetching. Since we're |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
712 # iterating over the different version of the file, we may |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
713 # be fetching the same deltachain over and over again. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
714 if deltabase != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
715 deltaentry = self.data.getdelta(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
716 delta, deltabasename, origdeltabase, meta = deltaentry |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
717 size = meta.get(constants.METAKEYSIZE) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
718 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
719 deltabasename != filename |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
720 or origdeltabase != deltabase |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
721 or size is None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
722 ): |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
723 deltabasetext = self.data.get(filename, deltabase) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
724 original = self.data.get(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
725 size = len(original) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
726 delta = mdiff.textdiff(deltabasetext, original) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
727 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
728 delta = self.data.get(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
729 size = len(delta) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
730 meta = self.data.getmeta(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
731 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
732 # TODO: don't use the delta if it's larger than the fulltext |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
733 if constants.METAKEYSIZE not in meta: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
734 meta[constants.METAKEYSIZE] = size |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
735 target.add(filename, node, deltabase, delta, meta) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
736 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
737 entries[node].datarepacked = True |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
738 |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
739 processprogress.complete() |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
740 count += 1 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
741 |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
742 repackprogress.complete() |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
743 target.close(ledger=ledger) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
744 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
745 def repackhistory(self, ledger, target): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
746 ui = self.repo.ui |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
747 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
748 byfile = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
749 for entry in ledger.entries.itervalues(): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
750 if entry.historysource: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
751 byfile.setdefault(entry.filename, {})[entry.node] = entry |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
752 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
753 progress = ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
754 _("repacking history"), unit=self.unit, total=len(byfile) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
755 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
756 for filename, entries in sorted(byfile.iteritems()): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
757 ancestors = {} |
40613
9769e0f6ffe0
py3: don't use dict.iterkeys()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40526
diff
changeset
|
758 nodes = list(node for node in entries) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
759 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
760 for node in nodes: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
761 if node in ancestors: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
762 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
763 ancestors.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
764 self.history.getancestors(filename, node, known=ancestors) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
765 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
766 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
767 # Order the nodes children first |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
768 orderednodes = reversed(self._toposort(ancestors)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
769 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
770 # Write to the pack |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
771 dontprocess = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
772 for node in orderednodes: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
773 p1, p2, linknode, copyfrom = ancestors[node] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
774 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
775 # If the node is marked dontprocess, but it's also in the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
776 # explicit entries set, that means the node exists both in this |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
777 # file and in another file that was copied to this file. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
778 # Usually this happens if the file was copied to another file, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
779 # then the copy was deleted, then reintroduced without copy |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
780 # metadata. The original add and the new add have the same hash |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
781 # since the content is identical and the parents are null. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
782 if node in dontprocess and node not in entries: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
783 # If copyfrom == filename, it means the copy history |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
784 # went to come other file, then came back to this one, so we |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
785 # should continue processing it. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
786 if p1 != nullid and copyfrom != filename: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
787 dontprocess.add(p1) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
788 if p2 != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
789 dontprocess.add(p2) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
790 continue |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
791 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
792 if copyfrom: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
793 dontprocess.add(p1) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
794 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
795 target.add(filename, node, p1, p2, linknode, copyfrom) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
796 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
797 if node in entries: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
798 entries[node].historyrepacked = True |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
799 |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
800 progress.increment() |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
801 |
40843
b80915b52476
remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents:
40804
diff
changeset
|
802 progress.complete() |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
803 target.close(ledger=ledger) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
804 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
805 def _toposort(self, ancestors): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
806 def parentfunc(node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
807 p1, p2, linknode, copyfrom = ancestors[node] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
808 parents = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
809 if p1 != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
810 parents.append(p1) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
811 if p2 != nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
812 parents.append(p2) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
813 return parents |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
814 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
815 sortednodes = shallowutil.sortnodes(ancestors.keys(), parentfunc) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
816 return sortednodes |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
817 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
818 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
819 class repackledger(object): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
820 """Storage for all the bookkeeping that happens during a repack. It contains |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
821 the list of revisions being repacked, what happened to each revision, and |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
822 which source store contained which revision originally (for later cleanup). |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
823 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
824 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
825 def __init__(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
826 self.entries = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
827 self.sources = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
828 self.created = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
829 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
830 def markdataentry(self, source, filename, node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
831 """Mark the given filename+node revision as having a data rev in the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
832 given source. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
833 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
834 entry = self._getorcreateentry(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
835 entry.datasource = True |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
836 entries = self.sources.get(source) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
837 if not entries: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
838 entries = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
839 self.sources[source] = entries |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
840 entries.add(entry) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
841 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
842 def markhistoryentry(self, source, filename, node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
843 """Mark the given filename+node revision as having a history rev in the |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
844 given source. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
845 """ |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
846 entry = self._getorcreateentry(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
847 entry.historysource = True |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
848 entries = self.sources.get(source) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
849 if not entries: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
850 entries = set() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
851 self.sources[source] = entries |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
852 entries.add(entry) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
853 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
854 def _getorcreateentry(self, filename, node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
855 key = (filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
856 value = self.entries.get(key) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
857 if not value: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
858 value = repackentry(filename, node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
859 self.entries[key] = value |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
860 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
861 return value |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
862 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
863 def addcreated(self, value): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
864 self.created.add(value) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
865 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
866 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
867 class repackentry(object): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
868 """Simple class representing a single revision entry in the repackledger. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
869 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
870 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
871 __slots__ = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
872 r'filename', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
873 r'node', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
874 r'datasource', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
875 r'historysource', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
876 r'datarepacked', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
877 r'historyrepacked', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
878 r'gced', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
879 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
880 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
881 def __init__(self, filename, node): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
882 self.filename = filename |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
883 self.node = node |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
884 # If the revision has a data entry in the source |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
885 self.datasource = False |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
886 # If the revision has a history entry in the source |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
887 self.historysource = False |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
888 # If the revision's data entry was repacked into the repack target |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
889 self.datarepacked = False |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
890 # If the revision's history entry was repacked into the repack target |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
891 self.historyrepacked = False |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
892 # If garbage collected |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
893 self.gced = False |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
894 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
895 |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
896 def repacklockvfs(repo): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
897 if util.safehasattr(repo, 'name'): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
898 # Lock in the shared cache so repacks across multiple copies of the same |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
899 # repo are coordinated. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
900 sharedcachepath = shallowutil.getcachepackpath( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
901 repo, constants.FILEPACK_CATEGORY |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42943
diff
changeset
|
902 ) |
40495
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
903 return vfs.vfs(sharedcachepath) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
904 else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
905 return repo.svfs |