| 1 |
# Copyright 2009-2010 Gregory P. Ward |
| 2 |
# Copyright 2009-2010 Intelerad Medical Systems Incorporated |
| 3 |
# Copyright 2010-2011 Fog Creek Software |
| 4 |
# Copyright 2010-2011 Unity Technologies |
| 5 |
# |
| 6 |
# This software may be used and distributed according to the terms of the |
| 7 |
# GNU General Public License version 2 or any later version. |
| 8 |
|
| 9 |
'''track large binary files |
| 10 |
|
| 11 |
Large binary files tend to be not very compressible, not very |
| 12 |
diffable, and not at all mergeable. Such files are not handled |
| 13 |
efficiently by Mercurial's storage format (revlog), which is based on |
| 14 |
compressed binary deltas; storing large binary files as regular |
| 15 |
Mercurial files wastes bandwidth and disk space and increases |
| 16 |
Mercurial's memory usage. The largefiles extension addresses these |
| 17 |
problems by adding a centralized client-server layer on top of |
| 18 |
Mercurial: largefiles live in a *central store* out on the network |
| 19 |
somewhere, and you only fetch the revisions that you need when you |
| 20 |
need them. |
| 21 |
|
| 22 |
largefiles works by maintaining a "standin file" in .hglf/ for each |
| 23 |
largefile. The standins are small (41 bytes: an SHA-1 hash plus |
| 24 |
newline) and are tracked by Mercurial. Largefile revisions are |
| 25 |
identified by the SHA-1 hash of their contents, which is written to |
| 26 |
the standin. largefiles uses that revision ID to get/put largefile |
| 27 |
revisions from/to the central store. This saves both disk space and |
| 28 |
bandwidth, since you don't need to retrieve all historical revisions |
| 29 |
of large files when you clone or pull. |
| 30 |
|
| 31 |
To start a new repository or add new large binary files, just add |
| 32 |
--large to your :hg:`add` command. For example:: |
| 33 |
|
| 34 |
$ dd if=/dev/urandom of=randomdata count=2000 |
| 35 |
$ hg add --large randomdata |
| 36 |
$ hg commit -m "add randomdata as a largefile" |
| 37 |
|
| 38 |
When you push a changeset that adds/modifies largefiles to a remote |
| 39 |
repository, its largefile revisions will be uploaded along with it. |
| 40 |
Note that the remote Mercurial must also have the largefiles extension |
| 41 |
enabled for this to work. |
| 42 |
|
| 43 |
When you pull a changeset that affects largefiles from a remote |
| 44 |
repository, the largefiles for the changeset will by default not be |
| 45 |
pulled down. However, when you update to such a revision, any |
| 46 |
largefiles needed by that revision are downloaded and cached (if |
| 47 |
they have never been downloaded before). One way to pull largefiles |
| 48 |
when pulling is thus to use --update, which will update your working |
| 49 |
copy to the latest pulled revision (and thereby downloading any new |
| 50 |
largefiles). |
| 51 |
|
| 52 |
If you want to pull largefiles you don't need for update yet, then |
| 53 |
you can use pull with the `--lfrev` option or the :hg:`lfpull` command. |
| 54 |
|
| 55 |
If you know you are pulling from a non-default location and want to |
| 56 |
download all the largefiles that correspond to the new changesets at |
| 57 |
the same time, then you can pull with `--lfrev "pulled()"`. |
| 58 |
|
| 59 |
If you just want to ensure that you will have the largefiles needed to |
| 60 |
merge or rebase with new heads that you are pulling, then you can pull |
| 61 |
with `--lfrev "head(pulled())"` flag to pre-emptively download any largefiles |
| 62 |
that are new in the heads you are pulling. |
| 63 |
|
| 64 |
Keep in mind that network access may now be required to update to |
| 65 |
changesets that you have not previously updated to. The nature of the |
| 66 |
largefiles extension means that updating is no longer guaranteed to |
| 67 |
be a local-only operation. |
| 68 |
|
| 69 |
If you already have large files tracked by Mercurial without the |
| 70 |
largefiles extension, you will need to convert your repository in |
| 71 |
order to benefit from largefiles. This is done with the |
| 72 |
:hg:`lfconvert` command:: |
| 73 |
|
| 74 |
$ hg lfconvert --size 10 oldrepo newrepo |
| 75 |
|
| 76 |
In repositories that already have largefiles in them, any new file |
| 77 |
over 10MB will automatically be added as a largefile. To change this |
| 78 |
threshold, set ``largefiles.minsize`` in your Mercurial config file |
| 79 |
to the minimum size in megabytes to track as a largefile, or use the |
| 80 |
--lfsize option to the add command (also in megabytes):: |
| 81 |
|
| 82 |
[largefiles] |
| 83 |
minsize = 2 |
| 84 |
|
| 85 |
$ hg add --lfsize 2 |
| 86 |
|
| 87 |
The ``largefiles.patterns`` config option allows you to specify a list |
| 88 |
of filename patterns (see :hg:`help patterns`) that should always be |
| 89 |
tracked as largefiles:: |
| 90 |
|
| 91 |
[largefiles] |
| 92 |
patterns = |
| 93 |
*.jpg |
| 94 |
re:.*\\.(png|bmp)$ |
| 95 |
library.zip |
| 96 |
content/audio/* |
| 97 |
|
| 98 |
Files that match one of these patterns will be added as largefiles |
| 99 |
regardless of their size. |
| 100 |
|
| 101 |
The ``largefiles.minsize`` and ``largefiles.patterns`` config options |
| 102 |
will be ignored for any repositories not already containing a |
| 103 |
largefile. To add the first largefile to a repository, you must |
| 104 |
explicitly do so with the --large flag passed to the :hg:`add` |
| 105 |
command. |
| 106 |
''' |
| 107 |
|
| 108 |
from __future__ import annotations |
| 109 |
|
| 110 |
from mercurial import ( |
| 111 |
cmdutil, |
| 112 |
configitems, |
| 113 |
extensions, |
| 114 |
exthelper, |
| 115 |
hg, |
| 116 |
localrepo, |
| 117 |
merge, |
| 118 |
wireprotov1server, |
| 119 |
) |
| 120 |
from mercurial.cmd_impls import ( |
| 121 |
outgoing as out_impl, |
| 122 |
) |
| 123 |
|
| 124 |
from . import ( |
| 125 |
lfcommands, |
| 126 |
overrides, |
| 127 |
proto, |
| 128 |
reposetup, |
| 129 |
) |
| 130 |
|
| 131 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
| 132 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
| 133 |
# be specifying the version(s) of Mercurial they are tested with, or |
| 134 |
# leave the attribute unspecified. |
| 135 |
testedwith = b'ships-with-hg-core' |
| 136 |
|
| 137 |
eh = exthelper.exthelper() |
| 138 |
eh.merge(lfcommands.eh) |
| 139 |
eh.merge(overrides.eh) |
| 140 |
eh.merge(proto.eh) |
| 141 |
|
| 142 |
eh.configitem( |
| 143 |
b'largefiles', |
| 144 |
b'minsize', |
| 145 |
default=configitems.dynamicdefault, |
| 146 |
) |
| 147 |
eh.configitem( |
| 148 |
b'largefiles', |
| 149 |
b'patterns', |
| 150 |
default=list, |
| 151 |
) |
| 152 |
eh.configitem( |
| 153 |
b'largefiles', |
| 154 |
b'usercache', |
| 155 |
default=None, |
| 156 |
) |
| 157 |
|
| 158 |
cmdtable = eh.cmdtable |
| 159 |
configtable = eh.configtable |
| 160 |
extsetup = eh.finalextsetup |
| 161 |
reposetup = reposetup.reposetup |
| 162 |
uisetup = eh.finaluisetup |
| 163 |
|
| 164 |
|
| 165 |
def featuresetup(ui, supported): |
| 166 |
# don't die on seeing a repo with the largefiles requirement |
| 167 |
supported |= {b'largefiles'} |
| 168 |
|
| 169 |
|
| 170 |
@eh.uisetup |
| 171 |
def _uisetup(ui): |
| 172 |
merge.MAYBE_USE_RUST_UPDATE = False |
| 173 |
localrepo.featuresetupfuncs.add(featuresetup) |
| 174 |
hg.wirepeersetupfuncs.append(proto.wirereposetup) |
| 175 |
|
| 176 |
out_impl.outgoinghooks.add(b'largefiles', overrides.outgoinghook) |
| 177 |
cmdutil.summaryremotehooks.add(b'largefiles', overrides.summaryremotehook) |
| 178 |
|
| 179 |
# create the new wireproto commands ... |
| 180 |
wireprotov1server.wireprotocommand(b'putlfile', b'sha', permission=b'push')( |
| 181 |
proto.putlfile |
| 182 |
) |
| 183 |
wireprotov1server.wireprotocommand(b'getlfile', b'sha', permission=b'pull')( |
| 184 |
proto.getlfile |
| 185 |
) |
| 186 |
wireprotov1server.wireprotocommand( |
| 187 |
b'statlfile', b'sha', permission=b'pull' |
| 188 |
)(proto.statlfile) |
| 189 |
wireprotov1server.wireprotocommand(b'lheads', b'', permission=b'pull')( |
| 190 |
wireprotov1server.heads |
| 191 |
) |
| 192 |
|
| 193 |
extensions.wrapfunction( |
| 194 |
wireprotov1server.commands[b'heads'], 'func', proto.heads |
| 195 |
) |
| 196 |
# TODO also wrap wireproto.commandsv2 once heads is implemented there. |
| 197 |
|
| 198 |
# override some extensions' stuff as well |
| 199 |
for name, module in extensions.extensions(): |
| 200 |
if name == b'rebase': |
| 201 |
# TODO: teach exthelper to handle this |
| 202 |
extensions.wrapfunction( |
| 203 |
module, 'rebase', overrides.overriderebasecmd |
| 204 |
) |
| 205 |
|
| 206 |
|
| 207 |
revsetpredicate = eh.revsetpredicate |