Mercurial > public > mercurial-scm > hg-stable
annotate hgext/lfs/wrapper.py @ 48966:6000f5b25c9b
py2: remove simple from __future__ statements
These were needed for Python 2 support. Now that our linter no longer
mandates these, we can start deleting them.
Differential Revision: https://phab.mercurial-scm.org/D12254
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 03 Mar 2022 17:34:00 +0100 |
parents | d55b71393907 |
children | f254fc73d956 |
rev | line source |
---|---|
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
1 # wrapper.py - methods wrapping core mercurial logic |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
2 # |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
3 # Copyright 2017 Facebook, Inc. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
4 # |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
7 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
8 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
9 import hashlib |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
10 |
35122
b8e5fb8d2389
lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents:
35121
diff
changeset
|
11 from mercurial.i18n import _ |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46722
diff
changeset
|
12 from mercurial.node import bin, hex, short |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
13 from mercurial.pycompat import ( |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
14 getattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
15 setattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
16 ) |
35122
b8e5fb8d2389
lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents:
35121
diff
changeset
|
17 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
18 from mercurial import ( |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
19 bundle2, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
20 changegroup, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
21 cmdutil, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
22 context, |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
23 error, |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
24 exchange, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
25 exthelper, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
26 localrepo, |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
27 pycompat, |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
28 revlog, |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
29 scmutil, |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
30 util, |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
31 vfs as vfsmod, |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
32 wireprotov1server, |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
33 ) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
34 |
46051
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
35 from mercurial.upgrade_utils import ( |
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
36 actions as upgrade_actions, |
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
37 engine as upgrade_engine, |
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
38 ) |
46050
f105c49e89cd
upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45957
diff
changeset
|
39 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
40 from mercurial.interfaces import repository |
42823
268662aac075
interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42791
diff
changeset
|
41 |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36633
diff
changeset
|
42 from mercurial.utils import ( |
39883
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39861
diff
changeset
|
43 storageutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36633
diff
changeset
|
44 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36633
diff
changeset
|
45 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36633
diff
changeset
|
46 |
35372
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
47 from ..largefiles import lfutil |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
48 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
49 from . import ( |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
50 blobstore, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
51 pointer, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
52 ) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
53 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
54 eh = exthelper.exthelper() |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
55 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
56 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 @eh.wrapfunction(localrepo, b'makefilestorage') |
39856
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
58 def localrepomakefilestorage(orig, requirements, features, **kwargs): |
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
59 if b'lfs' in requirements: |
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
60 features.add(repository.REPO_FEATURE_LFS) |
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
61 |
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
62 return orig(requirements=requirements, features=features, **kwargs) |
1f7b3b980af8
lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39854
diff
changeset
|
63 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
64 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 @eh.wrapfunction(changegroup, b'allsupportedversions') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
66 def allsupportedversions(orig, ui): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
67 versions = orig(ui) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 versions.add(b'03') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
69 return versions |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
70 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
71 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 @eh.wrapfunction(wireprotov1server, b'_capabilities') |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
73 def _capabilities(orig, repo, proto): |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
74 '''Wrap server command to announce lfs server capability''' |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
75 caps = orig(repo, proto) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
76 if util.safehasattr(repo.svfs, b'lfslocalblobstore'): |
40324
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
77 # Advertise a slightly different capability when lfs is *required*, so |
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
78 # that the client knows it MUST load the extension. If lfs is not |
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
79 # required on the server, there's no reason to autoload the extension |
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
80 # on the client. |
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
81 if b'lfs' in repo.requirements: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 caps.append(b'lfs-serve') |
40324
6637b079ae45
lfs: autoload the extension when cloning from repo with lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
39950
diff
changeset
|
83 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
84 caps.append(b'lfs') |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
85 return caps |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
86 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
87 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
88 def bypasscheckhash(self, text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
89 return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
90 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
91 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
92 def readfromstore(self, text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
93 """Read filelog content from local blobstore transform for flagprocessor. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
94 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
95 Default tranform for flagprocessor, returning contents from blobstore. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
96 Returns a 2-typle (text, validatehash) where validatehash is True as the |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
97 contents of the blobstore should be checked using checkhash. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
98 """ |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
99 p = pointer.deserialize(text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
100 oid = p.oid() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
101 store = self.opener.lfslocalblobstore |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
102 if not store.has(oid): |
35568
ebf14075a5c1
lfs: improve the error message for a missing remote blob
Matt Harbison <matt_harbison@yahoo.com>
parents:
35553
diff
changeset
|
103 p.filename = self.filename |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
104 self.opener.lfsremoteblobstore.readbatch([p], store) |
35480
417e8e040102
lfs: verify lfs object content when transferring to and from the remote store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35477
diff
changeset
|
105 |
417e8e040102
lfs: verify lfs object content when transferring to and from the remote store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35477
diff
changeset
|
106 # The caller will validate the content |
417e8e040102
lfs: verify lfs object content when transferring to and from the remote store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35477
diff
changeset
|
107 text = store.read(oid, verify=False) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
108 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
109 # pack hg filelog metadata |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
110 hgmeta = {} |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
111 for k in p.keys(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
112 if k.startswith(b'x-hg-'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
113 name = k[len(b'x-hg-') :] |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
114 hgmeta[name] = p[k] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 if hgmeta or text.startswith(b'\1\n'): |
39883
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39861
diff
changeset
|
116 text = storageutil.packmeta(hgmeta, text) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
117 |
46722
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46219
diff
changeset
|
118 return (text, True) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
119 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
120 |
46722
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46219
diff
changeset
|
121 def writetostore(self, text): |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
122 # hg filelog metadata (includes rename, etc) |
39883
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39861
diff
changeset
|
123 hgmeta, offset = storageutil.parsemeta(text) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
124 if offset and offset > 0: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
125 # lfs blob does not contain hg filelog metadata |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
126 text = text[offset:] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
127 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
128 # git-lfs only supports sha256 |
36633
f6b9f9ddd0de
lfs: convert hexdigest to bytes using sysbytes
Augie Fackler <augie@google.com>
parents:
36632
diff
changeset
|
129 oid = hex(hashlib.sha256(text).digest()) |
35553
a77418095530
lfs: remove the verification option when writing to the local store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35510
diff
changeset
|
130 self.opener.lfslocalblobstore.write(oid, text) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
131 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
132 # replace contents with metadata |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 longoid = b'sha256:%s' % oid |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 metadata = pointer.gitlfspointer(oid=longoid, size=b'%d' % len(text)) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
135 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
136 # by default, we expect the content to be binary. however, LFS could also |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
137 # be used for non-binary content. add a special entry for non-binary data. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
138 # this will be used by filectx.isbinary(). |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36633
diff
changeset
|
139 if not stringutil.binary(text): |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
140 # not hg filelog metadata (affecting commit hash), no "x-hg-" prefix |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 metadata[b'x-is-binary'] = b'0' |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
142 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
143 # translate hg filelog metadata to lfs metadata with "x-hg-" prefix |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
144 if hgmeta is not None: |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
145 for k, v in pycompat.iteritems(hgmeta): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 metadata[b'x-hg-%s' % k] = v |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
147 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
148 rawtext = metadata.serialize() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
149 return (rawtext, False) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
150 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
151 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
152 def _islfs(rlog, node=None, rev=None): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
153 if rev is None: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
154 if node is None: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
155 # both None - likely working copy content where node is not ready |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
156 return False |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
157 rev = rlog.rev(node) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
158 else: |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
159 node = rlog.node(rev) |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46722
diff
changeset
|
160 if node == rlog.nullid: |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
161 return False |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
162 flags = rlog.flags(rev) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
163 return bool(flags & revlog.REVIDX_EXTSTORED) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
164 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
165 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
166 # Wrapping may also be applied by remotefilelog |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
167 def filelogaddrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
168 orig, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
169 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
170 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
171 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
172 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
173 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
174 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
175 cachedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
176 node=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
177 flags=revlog.REVIDX_DEFAULT_FLAGS, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
178 **kwds |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
179 ): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
180 # The matcher isn't available if reposetup() wasn't called. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
181 lfstrack = self._revlog.opener.options.get(b'lfstrack') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
182 |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
183 if lfstrack: |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
184 textlen = len(text) |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
185 # exclude hg rename meta from file size |
39883
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39861
diff
changeset
|
186 meta, offset = storageutil.parsemeta(text) |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
187 if offset: |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
188 textlen -= offset |
35648
588d02d9208a
lfs: always exclude '.hg*' text files
Matt Harbison <matt_harbison@yahoo.com>
parents:
35624
diff
changeset
|
189 |
39861
96838b620b9c
filelog: store filename directly on revlog instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39860
diff
changeset
|
190 if lfstrack(self._revlog.filename, textlen): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
191 flags |= revlog.REVIDX_EXTSTORED |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
192 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
193 return orig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
194 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
195 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
196 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
197 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
198 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
199 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
200 cachedelta=cachedelta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
201 node=node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
202 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
203 **kwds |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
204 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
205 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
206 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
207 # Wrapping may also be applied by remotefilelog |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
208 def filelogrenamed(orig, self, node): |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
209 if _islfs(self._revlog, node): |
42791
f972f43badb3
rawdata: update callers in lfs' wrapper
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41279
diff
changeset
|
210 rawtext = self._revlog.rawdata(node) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
211 if not rawtext: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
212 return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
213 metadata = pointer.deserialize(rawtext) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
214 if b'x-hg-copy' in metadata and b'x-hg-copyrev' in metadata: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 return metadata[b'x-hg-copy'], bin(metadata[b'x-hg-copyrev']) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
216 else: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
217 return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
218 return orig(self, node) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
219 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
220 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
221 # Wrapping may also be applied by remotefilelog |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
222 def filelogsize(orig, self, rev): |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
223 if _islfs(self._revlog, rev=rev): |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
224 # fast path: use lfs metadata to answer size |
42791
f972f43badb3
rawdata: update callers in lfs' wrapper
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41279
diff
changeset
|
225 rawtext = self._revlog.rawdata(rev) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
226 metadata = pointer.deserialize(rawtext) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 return int(metadata[b'size']) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
228 return orig(self, rev) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
229 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
230 |
44072
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
231 @eh.wrapfunction(revlog, b'_verify_revision') |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
232 def _verify_revision(orig, rl, skipflags, state, node): |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
233 if _islfs(rl, node=node): |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
234 rawtext = rl.rawdata(node) |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
235 metadata = pointer.deserialize(rawtext) |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
236 |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
237 # Don't skip blobs that are stored locally, as local verification is |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
238 # relatively cheap and there's no other way to verify the raw data in |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
239 # the revlog. |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
240 if rl.opener.lfslocalblobstore.has(metadata.oid()): |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
241 skipflags &= ~revlog.REVIDX_EXTSTORED |
44073
b9e174d4ed11
verify: allow the storage to signal when renames can be tested on `skipread`
Matt Harbison <matt_harbison@yahoo.com>
parents:
44072
diff
changeset
|
242 elif skipflags & revlog.REVIDX_EXTSTORED: |
b9e174d4ed11
verify: allow the storage to signal when renames can be tested on `skipread`
Matt Harbison <matt_harbison@yahoo.com>
parents:
44072
diff
changeset
|
243 # The wrapped method will set `skipread`, but there's enough local |
b9e174d4ed11
verify: allow the storage to signal when renames can be tested on `skipread`
Matt Harbison <matt_harbison@yahoo.com>
parents:
44072
diff
changeset
|
244 # info to check renames. |
b9e174d4ed11
verify: allow the storage to signal when renames can be tested on `skipread`
Matt Harbison <matt_harbison@yahoo.com>
parents:
44072
diff
changeset
|
245 state[b'safe_renamed'].add(node) |
44072
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
246 |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
247 orig(rl, skipflags, state, node) |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
248 |
1a6dd50cd0db
lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents:
43963
diff
changeset
|
249 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
250 @eh.wrapfunction(context.basefilectx, b'cmp') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
251 def filectxcmp(orig, self, fctx): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
252 """returns True if text is different than fctx""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
253 # some fctx (ex. hg-git) is not based on basefilectx and do not have islfs |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
254 if self.islfs() and getattr(fctx, 'islfs', lambda: False)(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
255 # fast path: check LFS oid |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
256 p1 = pointer.deserialize(self.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
257 p2 = pointer.deserialize(fctx.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
258 return p1.oid() != p2.oid() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
259 return orig(self, fctx) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
260 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
261 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
262 @eh.wrapfunction(context.basefilectx, b'isbinary') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
263 def filectxisbinary(orig, self): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
264 if self.islfs(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
265 # fast path: use lfs metadata to answer isbinary |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
266 metadata = pointer.deserialize(self.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
267 # if lfs metadata says nothing, assume it's binary by default |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
268 return bool(int(metadata.get(b'x-is-binary', 1))) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
269 return orig(self) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
270 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
271 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
272 def filectxislfs(self): |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
273 return _islfs(self.filelog()._revlog, self.filenode()) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
274 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
275 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 @eh.wrapfunction(cmdutil, b'_updatecatformatter') |
35663
a985834961f7
lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents:
35648
diff
changeset
|
277 def _updatecatformatter(orig, fm, ctx, matcher, path, decode): |
a985834961f7
lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents:
35648
diff
changeset
|
278 orig(fm, ctx, matcher, path, decode) |
a985834961f7
lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents:
35648
diff
changeset
|
279 fm.data(rawdata=ctx[path].rawdata()) |
a985834961f7
lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents:
35648
diff
changeset
|
280 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
281 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
282 @eh.wrapfunction(scmutil, b'wrapconvertsink') |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
283 def convertsink(orig, sink): |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
284 sink = orig(sink) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
285 if sink.repotype == b'hg': |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
286 |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
287 class lfssink(sink.__class__): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
288 def putcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
289 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
290 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
291 copies, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
292 parents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
293 commit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
294 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
295 revmap, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
296 full, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
297 cleanp2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
298 ): |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
299 pc = super(lfssink, self).putcommit |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
300 node = pc( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
301 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
302 copies, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
303 parents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
304 commit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
305 source, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
306 revmap, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
307 full, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
308 cleanp2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
309 ) |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
310 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
311 if b'lfs' not in self.repo.requirements: |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
312 ctx = self.repo[node] |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
313 |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
314 # The file list may contain removed files, so check for |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
315 # membership before assuming it is in the context. |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
316 if any(f in ctx and ctx[f].islfs() for f, n in files): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
317 self.repo.requirements.add(b'lfs') |
45106
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
318 scmutil.writereporequirements(self.repo) |
35189
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
319 |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
320 return node |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
321 |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
322 sink.__class__ = lfssink |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
323 |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
324 return sink |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35122
diff
changeset
|
325 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
326 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
327 # bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs |
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
328 # options and blob stores are passed from othervfs to the new readonlyvfs. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
329 @eh.wrapfunction(vfsmod.readonlyvfs, b'__init__') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
330 def vfsinit(orig, self, othervfs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
331 orig(self, othervfs) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
332 # copy lfs related options |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
333 for k, v in othervfs.options.items(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
334 if k.startswith(b'lfs'): |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
335 self.options[k] = v |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
336 # also copy lfs blobstores. note: this can run before reposetup, so lfs |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
337 # blobstore attributes are not always ready at this time. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
338 for name in [b'lfslocalblobstore', b'lfsremoteblobstore']: |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
339 if util.safehasattr(othervfs, name): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
340 setattr(self, name, getattr(othervfs, name)) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
341 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
342 |
45073
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44073
diff
changeset
|
343 def _prefetchfiles(repo, revmatches): |
35962
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
344 """Ensure that required LFS blobs are present, fetching them as a group if |
36180
60dd840a7fdb
merge: invoke scmutil.fileprefetchhooks() prior to applying updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
36176
diff
changeset
|
345 needed.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
346 if not util.safehasattr(repo.svfs, b'lfslocalblobstore'): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
347 return |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
348 |
35962
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
349 pointers = [] |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
350 oids = set() |
35962
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
351 localstore = repo.svfs.lfslocalblobstore |
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
352 |
45073
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44073
diff
changeset
|
353 for rev, match in revmatches: |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
354 ctx = repo[rev] |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
355 for f in ctx.walk(match): |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
356 p = pointerfromctx(ctx, f) |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
357 if p and p.oid() not in oids and not localstore.has(p.oid()): |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
358 p.filename = f |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
359 pointers.append(p) |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37564
diff
changeset
|
360 oids.add(p.oid()) |
35962
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
361 |
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
362 if pointers: |
37518
092eff6833a7
lfs: infer the blob store URL from paths.default
Matt Harbison <matt_harbison@yahoo.com>
parents:
37442
diff
changeset
|
363 # Recalculating the repo store here allows 'paths.default' that is set |
092eff6833a7
lfs: infer the blob store URL from paths.default
Matt Harbison <matt_harbison@yahoo.com>
parents:
37442
diff
changeset
|
364 # on the repo by a clone command to be used for the update. |
092eff6833a7
lfs: infer the blob store URL from paths.default
Matt Harbison <matt_harbison@yahoo.com>
parents:
37442
diff
changeset
|
365 blobstore.remote(repo).readbatch(pointers, localstore) |
35962
0b79f99fd7b0
lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents:
35961
diff
changeset
|
366 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
367 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
368 def _canskipupload(repo): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
369 # Skip if this hasn't been passed to reposetup() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 if not util.safehasattr(repo.svfs, b'lfsremoteblobstore'): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
371 return True |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
372 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
373 # if remotestore is a null store, upload is a no-op and can be skipped |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
374 return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
375 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
376 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
377 def candownload(repo): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
378 # Skip if this hasn't been passed to reposetup() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 if not util.safehasattr(repo.svfs, b'lfsremoteblobstore'): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
380 return False |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
381 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
382 # if remotestore is a null store, downloads will lead to nothing |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
383 return not isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
384 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
385 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
386 def uploadblobsfromrevs(repo, revs): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45106
diff
changeset
|
387 """upload lfs blobs introduced by revs |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
388 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
389 Note: also used by other extensions e. g. infinitepush. avoid renaming. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45106
diff
changeset
|
390 """ |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
391 if _canskipupload(repo): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
392 return |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
393 pointers = extractpointers(repo, revs) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
394 uploadblobs(repo, pointers) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
395 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
396 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
397 def prepush(pushop): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
398 """Prepush hook. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
399 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
400 Read through the revisions to push, looking for filelog entries that can be |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
401 deserialized into metadata so that we can block the push on their upload to |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
402 the remote blobstore. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
403 """ |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
404 return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
405 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
406 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
407 @eh.wrapfunction(exchange, b'push') |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
408 def push(orig, repo, remote, *args, **kwargs): |
37564
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
409 """bail on push if the extension isn't enabled on remote when needed, and |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
410 update the remote store based on the destination path.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
411 if b'lfs' in repo.requirements: |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
412 # If the remote peer is for a local repo, the requirement tests in the |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
413 # base class method enforce lfs support. Otherwise, some revisions in |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
414 # this repo use lfs, and the remote repo needs the extension loaded. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
415 if not remote.local() and not remote.capable(b'lfs'): |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
416 # This is a copy of the message in exchange.push() when requirements |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
417 # are missing between local repos. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
418 m = _(b"required features are not supported in the destination: %s") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
419 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 m % b'lfs', hint=_(b'enable the lfs extension on the server') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
421 ) |
37564
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
422 |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
423 # Repositories where this extension is disabled won't have the field. |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
424 # But if there's a requirement, then the extension must be loaded AND |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
425 # there may be blobs to push. |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
426 remotestore = repo.svfs.lfsremoteblobstore |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
427 try: |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
428 repo.svfs.lfsremoteblobstore = blobstore.remote(repo, remote.url()) |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
429 return orig(repo, remote, *args, **kwargs) |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
430 finally: |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
431 repo.svfs.lfsremoteblobstore = remotestore |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
432 else: |
31a4ea773369
lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents:
37518
diff
changeset
|
433 return orig(repo, remote, *args, **kwargs) |
35510
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35509
diff
changeset
|
434 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
435 |
41051
84d61fdcefa5
lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents:
40386
diff
changeset
|
436 # when writing a bundle via "hg bundle" command, upload related LFS blobs |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
437 @eh.wrapfunction(bundle2, b'writenewbundle') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
438 def writenewbundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
439 orig, ui, repo, source, filename, bundletype, outgoing, *args, **kwargs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
440 ): |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
441 """upload LFS blobs added by outgoing revisions on 'hg bundle'""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
442 uploadblobsfromrevs(repo, outgoing.missing) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
443 return orig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
444 ui, repo, source, filename, bundletype, outgoing, *args, **kwargs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
445 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
446 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
447 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
448 def extractpointers(repo, revs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
449 """return a list of lfs pointers added by given revs""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
450 repo.ui.debug(b'lfs: computing set of blobs to upload\n') |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
451 pointers = {} |
39297
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
452 |
39416
b26350d9d7b5
lfs: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
39297
diff
changeset
|
453 makeprogress = repo.ui.makeprogress |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
454 with makeprogress( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
455 _(b'lfs search'), _(b'changesets'), len(revs) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
456 ) as progress: |
39297
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
457 for r in revs: |
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
458 ctx = repo[r] |
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
459 for p in pointersfromctx(ctx).values(): |
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
460 pointers[p.oid()] = p |
37e56607cbb9
lfs: add a progress bar when searching for blobs to upload
Matt Harbison <matt_harbison@yahoo.com>
parents:
37851
diff
changeset
|
461 progress.increment() |
39950
e1f97179a3f5
lfs: explicitly name a key when sorting blob pointers
Matt Harbison <matt_harbison@yahoo.com>
parents:
39883
diff
changeset
|
462 return sorted(pointers.values(), key=lambda p: p.oid()) |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
463 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
464 |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
465 def pointerfromctx(ctx, f, removed=False): |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
466 """return a pointer for the named file from the given changectx, or None if |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
467 the file isn't LFS. |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
468 |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
469 Optionally, the pointer for a file deleted from the context can be returned. |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
470 Since no such pointer is actually stored, and to distinguish from a non LFS |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
471 file, this pointer is represented by an empty dict. |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
472 """ |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
473 _ctx = ctx |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
474 if f not in ctx: |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
475 if not removed: |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
476 return None |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
477 if f in ctx.p1(): |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
478 _ctx = ctx.p1() |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
479 elif f in ctx.p2(): |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
480 _ctx = ctx.p2() |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
481 else: |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
482 return None |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
483 fctx = _ctx[f] |
43963
26cf356ae772
lfs: fix a discrepancy with a function wanting a filelog, but calling it rlog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43105
diff
changeset
|
484 if not _islfs(fctx.filelog()._revlog, fctx.filenode()): |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
485 return None |
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
486 try: |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
487 p = pointer.deserialize(fctx.rawdata()) |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
488 if ctx == _ctx: |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
489 return p |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
490 return {} |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
491 except pointer.InvalidPointer as ex: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
492 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
493 _(b'lfs: corrupted pointer (%s@%s): %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
494 % (f, short(_ctx.node()), ex) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
495 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
496 |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
497 |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
498 def pointersfromctx(ctx, removed=False): |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
499 """return a dict {path: pointer} for given single changectx. |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
500 |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
501 If ``removed`` == True and the LFS file was removed from ``ctx``, the value |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
502 stored for the path is an empty dict. |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
503 """ |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
504 result = {} |
40386
4a81d82474e9
lfs: consult the narrow matcher when extracting pointers from ctx (issue5794)
Matt Harbison <matt_harbison@yahoo.com>
parents:
40368
diff
changeset
|
505 m = ctx.repo().narrowmatch() |
4a81d82474e9
lfs: consult the narrow matcher when extracting pointers from ctx (issue5794)
Matt Harbison <matt_harbison@yahoo.com>
parents:
40368
diff
changeset
|
506 |
4a81d82474e9
lfs: consult the narrow matcher when extracting pointers from ctx (issue5794)
Matt Harbison <matt_harbison@yahoo.com>
parents:
40368
diff
changeset
|
507 # TODO: consider manifest.fastread() instead |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
508 for f in ctx.files(): |
40386
4a81d82474e9
lfs: consult the narrow matcher when extracting pointers from ctx (issue5794)
Matt Harbison <matt_harbison@yahoo.com>
parents:
40368
diff
changeset
|
509 if not m(f): |
4a81d82474e9
lfs: consult the narrow matcher when extracting pointers from ctx (issue5794)
Matt Harbison <matt_harbison@yahoo.com>
parents:
40368
diff
changeset
|
510 continue |
36037
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
511 p = pointerfromctx(ctx, f, removed=removed) |
dce43aaaf209
lfs: allow a pointer to be extracted from a context that removes the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35964
diff
changeset
|
512 if p is not None: |
35961
47e737d27e01
lfs: factor out a method for extracting the pointer of a single file
Matt Harbison <matt_harbison@yahoo.com>
parents:
35799
diff
changeset
|
513 result[f] = p |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
514 return result |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
515 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
516 |
35121
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
517 def uploadblobs(repo, pointers): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
518 """upload given pointers from local blobstore""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
519 if not pointers: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
520 return |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
521 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
522 remoteblob = repo.svfs.lfsremoteblobstore |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
523 remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore) |
35355
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35225
diff
changeset
|
524 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
525 |
46219
481d9aed669c
engine: make hook point for extension a public function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46051
diff
changeset
|
526 @eh.wrapfunction(upgrade_engine, b'finishdatamigration') |
35372
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
527 def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements): |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
528 orig(ui, srcrepo, dstrepo, requirements) |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
529 |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
530 # Skip if this hasn't been passed to reposetup() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
531 if util.safehasattr( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
532 srcrepo.svfs, b'lfslocalblobstore' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
533 ) and util.safehasattr(dstrepo.svfs, b'lfslocalblobstore'): |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
534 srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
535 dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs |
35372
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
536 |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
537 for dirpath, dirs, files in srclfsvfs.walk(): |
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
538 for oid in files: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
539 ui.write(_(b'copying lfs blob %s\n') % oid) |
37851
3790efb388ca
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
540 lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid)) |
35372
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35355
diff
changeset
|
541 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42990
diff
changeset
|
542 |
46051
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
543 @eh.wrapfunction(upgrade_actions, b'preservedrequirements') |
4b89cf08d8dc
upgrade: split definition and management of the actions from the main code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46050
diff
changeset
|
544 @eh.wrapfunction(upgrade_actions, b'supporteddestrequirements') |
35355
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35225
diff
changeset
|
545 def upgraderequirements(orig, repo): |
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35225
diff
changeset
|
546 reqs = orig(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
547 if b'lfs' in repo.requirements: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
548 reqs.add(b'lfs') |
35355
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35225
diff
changeset
|
549 return reqs |