author | Yuya Nishihara <yuya@tcha.org> |
Tue, 16 Jan 2018 21:46:17 +0900 | |
changeset 35743 | 3c2a6246fd63 |
parent 35663 | a985834961f7 |
child 35799 | b91bca85ba73 |
permissions | -rw-r--r-- |
35098
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 |
from __future__ import absolute_import |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
9 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
10 |
import hashlib |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
11 |
|
35099
b8e5fb8d2389
lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents:
35098
diff
changeset
|
12 |
from mercurial.i18n import _ |
b8e5fb8d2389
lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents:
35098
diff
changeset
|
13 |
from mercurial.node import bin, nullid, short |
b8e5fb8d2389
lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents:
35098
diff
changeset
|
14 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
15 |
from mercurial import ( |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
16 |
error, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
17 |
filelog, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
18 |
revlog, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
19 |
util, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
20 |
) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
21 |
|
35363
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
22 |
from ..largefiles import lfutil |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
23 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
24 |
from . import ( |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
25 |
blobstore, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
26 |
pointer, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
27 |
) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
28 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
29 |
def supportedoutgoingversions(orig, repo): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
30 |
versions = orig(repo) |
35505
2526579a30e0
lfs: allow non-lfs exchanges when the extension is only enabled on one side
Matt Harbison <matt_harbison@yahoo.com>
parents:
35478
diff
changeset
|
31 |
if 'lfs' in repo.requirements: |
2526579a30e0
lfs: allow non-lfs exchanges when the extension is only enabled on one side
Matt Harbison <matt_harbison@yahoo.com>
parents:
35478
diff
changeset
|
32 |
versions.discard('01') |
2526579a30e0
lfs: allow non-lfs exchanges when the extension is only enabled on one side
Matt Harbison <matt_harbison@yahoo.com>
parents:
35478
diff
changeset
|
33 |
versions.discard('02') |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
34 |
versions.add('03') |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
35 |
return versions |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
36 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
37 |
def allsupportedversions(orig, ui): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
38 |
versions = orig(ui) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
39 |
versions.add('03') |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
40 |
return versions |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
41 |
|
35506
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
42 |
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:
35505
diff
changeset
|
43 |
'''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:
35505
diff
changeset
|
44 |
caps = 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:
35505
diff
changeset
|
45 |
# XXX: change to 'lfs=serve' when separate git server isn't required? |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
46 |
caps.append('lfs') |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
47 |
return caps |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
48 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
49 |
def bypasscheckhash(self, text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
50 |
return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
51 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
52 |
def readfromstore(self, text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
53 |
"""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
|
54 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
59 |
p = pointer.deserialize(text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
60 |
oid = p.oid() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
61 |
store = self.opener.lfslocalblobstore |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
62 |
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
|
63 |
p.filename = self.filename |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
64 |
self.opener.lfsremoteblobstore.readbatch([p], store) |
35476
417e8e040102
lfs: verify lfs object content when transferring to and from the remote store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35473
diff
changeset
|
65 |
|
417e8e040102
lfs: verify lfs object content when transferring to and from the remote store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35473
diff
changeset
|
66 |
# 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:
35473
diff
changeset
|
67 |
text = store.read(oid, verify=False) |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
68 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
69 |
# pack hg filelog metadata |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
70 |
hgmeta = {} |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
71 |
for k in p.keys(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
72 |
if k.startswith('x-hg-'): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
73 |
name = k[len('x-hg-'):] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
74 |
hgmeta[name] = p[k] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
75 |
if hgmeta or text.startswith('\1\n'): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
76 |
text = filelog.packmeta(hgmeta, text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
77 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
78 |
return (text, True) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
79 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
80 |
def writetostore(self, text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
81 |
# hg filelog metadata (includes rename, etc) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
82 |
hgmeta, offset = filelog.parsemeta(text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
83 |
if offset and offset > 0: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
84 |
# 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
|
85 |
text = text[offset:] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
86 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
87 |
# git-lfs only supports sha256 |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
88 |
oid = hashlib.sha256(text).hexdigest() |
35553
a77418095530
lfs: remove the verification option when writing to the local store
Matt Harbison <matt_harbison@yahoo.com>
parents:
35506
diff
changeset
|
89 |
self.opener.lfslocalblobstore.write(oid, text) |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
90 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
91 |
# replace contents with metadata |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
92 |
longoid = 'sha256:%s' % oid |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
93 |
metadata = pointer.gitlfspointer(oid=longoid, size=str(len(text))) |
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 |
# 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
|
96 |
# 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
|
97 |
# this will be used by filectx.isbinary(). |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
98 |
if not util.binary(text): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
99 |
# not hg filelog metadata (affecting commit hash), no "x-hg-" prefix |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
100 |
metadata['x-is-binary'] = '0' |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
101 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
102 |
# 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
|
103 |
if hgmeta is not None: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
104 |
for k, v in hgmeta.iteritems(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
105 |
metadata['x-hg-%s' % k] = v |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
106 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
107 |
rawtext = metadata.serialize() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
108 |
return (rawtext, False) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
109 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
110 |
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
|
111 |
if rev is None: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
112 |
if node is None: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
113 |
# 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
|
114 |
return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
115 |
rev = rlog.rev(node) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
116 |
else: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
117 |
node = rlog.node(rev) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
118 |
if node == nullid: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
119 |
return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
120 |
flags = rlog.flags(rev) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
121 |
return bool(flags & revlog.REVIDX_EXTSTORED) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
122 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
123 |
def filelogaddrevision(orig, self, text, transaction, link, p1, p2, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
124 |
cachedelta=None, node=None, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
125 |
flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
126 |
textlen = len(text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
127 |
# exclude hg rename meta from file size |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
128 |
meta, offset = filelog.parsemeta(text) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
129 |
if offset: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
130 |
textlen -= offset |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
131 |
|
35618
c780e0649e41
lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35568
diff
changeset
|
132 |
lfstrack = self.opener.options['lfstrack'] |
35648
588d02d9208a
lfs: always exclude '.hg*' text files
Matt Harbison <matt_harbison@yahoo.com>
parents:
35624
diff
changeset
|
133 |
|
588d02d9208a
lfs: always exclude '.hg*' text files
Matt Harbison <matt_harbison@yahoo.com>
parents:
35624
diff
changeset
|
134 |
# Always exclude hg owned files |
588d02d9208a
lfs: always exclude '.hg*' text files
Matt Harbison <matt_harbison@yahoo.com>
parents:
35624
diff
changeset
|
135 |
if not self.filename.startswith('.hg') and lfstrack(self.filename, textlen): |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
136 |
flags |= revlog.REVIDX_EXTSTORED |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
137 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
138 |
return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
139 |
node=node, flags=flags, **kwds) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
140 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
141 |
def filelogrenamed(orig, self, node): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
142 |
if _islfs(self, node): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
143 |
rawtext = self.revision(node, raw=True) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
144 |
if not rawtext: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
145 |
return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
146 |
metadata = pointer.deserialize(rawtext) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
147 |
if 'x-hg-copy' in metadata and 'x-hg-copyrev' in metadata: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
148 |
return metadata['x-hg-copy'], bin(metadata['x-hg-copyrev']) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
149 |
else: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
150 |
return False |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
151 |
return orig(self, node) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
152 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
153 |
def filelogsize(orig, self, rev): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
154 |
if _islfs(self, rev=rev): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
155 |
# fast path: use lfs metadata to answer size |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
156 |
rawtext = self.revision(rev, raw=True) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
157 |
metadata = pointer.deserialize(rawtext) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
158 |
return int(metadata['size']) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
159 |
return orig(self, rev) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
160 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
161 |
def filectxcmp(orig, self, fctx): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
162 |
"""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
|
163 |
# 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
|
164 |
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
|
165 |
# fast path: check LFS oid |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
166 |
p1 = pointer.deserialize(self.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
167 |
p2 = pointer.deserialize(fctx.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
168 |
return p1.oid() != p2.oid() |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
169 |
return orig(self, fctx) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
170 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
171 |
def filectxisbinary(orig, self): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
172 |
if self.islfs(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
173 |
# 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
|
174 |
metadata = pointer.deserialize(self.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
175 |
# if lfs metadata says nothing, assume it's binary by default |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
176 |
return bool(int(metadata.get('x-is-binary', 1))) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
177 |
return orig(self) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
178 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
179 |
def filectxislfs(self): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
180 |
return _islfs(self.filelog(), self.filenode()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
181 |
|
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
|
35178
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
186 |
def convertsink(orig, sink): |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
187 |
sink = orig(sink) |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
188 |
if sink.repotype == 'hg': |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
189 |
class lfssink(sink.__class__): |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
190 |
def putcommit(self, files, copies, parents, commit, source, revmap, |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
191 |
full, cleanp2): |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
192 |
pc = super(lfssink, self).putcommit |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
193 |
node = pc(files, copies, parents, commit, source, revmap, full, |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
194 |
cleanp2) |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
195 |
|
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
196 |
if 'lfs' not in self.repo.requirements: |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
197 |
ctx = self.repo[node] |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
198 |
|
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
199 |
# 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:
35099
diff
changeset
|
200 |
# 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:
35099
diff
changeset
|
201 |
if any(f in ctx and ctx[f].islfs() for f, n in files): |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
202 |
self.repo.requirements.add('lfs') |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
203 |
self.repo._writerequirements() |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
204 |
|
35215
8887a45e3384
lfs: enable the extension locally after converting to an 'lfs' repo
Matt Harbison <matt_harbison@yahoo.com>
parents:
35214
diff
changeset
|
205 |
# Permanently enable lfs locally |
35624
188b1371d1ed
lfs: convert EOL of hgrc before appending to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35618
diff
changeset
|
206 |
self.repo.vfs.append( |
188b1371d1ed
lfs: convert EOL of hgrc before appending to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35618
diff
changeset
|
207 |
'hgrc', util.tonativeeol('\n[extensions]\nlfs=\n')) |
35215
8887a45e3384
lfs: enable the extension locally after converting to an 'lfs' repo
Matt Harbison <matt_harbison@yahoo.com>
parents:
35214
diff
changeset
|
208 |
|
35178
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
209 |
return node |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
210 |
|
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
211 |
sink.__class__ = lfssink |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
212 |
|
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
213 |
return sink |
f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents:
35099
diff
changeset
|
214 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
215 |
def vfsinit(orig, self, othervfs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
216 |
orig(self, othervfs) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
217 |
# copy lfs related options |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
218 |
for k, v in othervfs.options.items(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
219 |
if k.startswith('lfs'): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
220 |
self.options[k] = v |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
221 |
# 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
|
222 |
# blobstore attributes are not always ready at this time. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
223 |
for name in ['lfslocalblobstore', 'lfsremoteblobstore']: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
224 |
if util.safehasattr(othervfs, name): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
225 |
setattr(self, name, getattr(othervfs, name)) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
226 |
|
35213
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
227 |
def hgclone(orig, ui, opts, *args, **kwargs): |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
228 |
result = orig(ui, opts, *args, **kwargs) |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
229 |
|
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
230 |
if result is not None: |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
231 |
sourcerepo, destrepo = result |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
232 |
repo = destrepo.local() |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
233 |
|
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
234 |
# When cloning to a remote repo (like through SSH), no repo is available |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
235 |
# from the peer. Therefore the hgrc can't be updated. |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
236 |
if not repo: |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
237 |
return result |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
238 |
|
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
239 |
# If lfs is required for this repo, permanently enable it locally |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
240 |
if 'lfs' in repo.requirements: |
35624
188b1371d1ed
lfs: convert EOL of hgrc before appending to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35618
diff
changeset
|
241 |
repo.vfs.append('hgrc', |
188b1371d1ed
lfs: convert EOL of hgrc before appending to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35618
diff
changeset
|
242 |
util.tonativeeol('\n[extensions]\nlfs=\n')) |
35213
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
243 |
|
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
244 |
return result |
24aa4853c031
lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35178
diff
changeset
|
245 |
|
35214
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
246 |
def hgpostshare(orig, sourcerepo, destrepo, bookmarks=True, defaultpath=None): |
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
247 |
orig(sourcerepo, destrepo, bookmarks, defaultpath) |
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
248 |
|
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
249 |
# If lfs is required for this repo, permanently enable it locally |
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
250 |
if 'lfs' in destrepo.requirements: |
35624
188b1371d1ed
lfs: convert EOL of hgrc before appending to bytes IO
Yuya Nishihara <yuya@tcha.org>
parents:
35618
diff
changeset
|
251 |
destrepo.vfs.append('hgrc', util.tonativeeol('\n[extensions]\nlfs=\n')) |
35214
a8c778b2a689
lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents:
35213
diff
changeset
|
252 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
253 |
def _canskipupload(repo): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
254 |
# 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
|
255 |
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
|
256 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
257 |
def candownload(repo): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
258 |
# 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
|
259 |
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
|
260 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
261 |
def uploadblobsfromrevs(repo, revs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
262 |
'''upload lfs blobs introduced by revs |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
263 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
264 |
Note: also used by other extensions e. g. infinitepush. avoid renaming. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
265 |
''' |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
266 |
if _canskipupload(repo): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
267 |
return |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
268 |
pointers = extractpointers(repo, revs) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
269 |
uploadblobs(repo, pointers) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
270 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
271 |
def prepush(pushop): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
272 |
"""Prepush hook. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
273 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
the remote blobstore. |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
277 |
""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
278 |
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
|
279 |
|
35506
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
280 |
def push(orig, repo, remote, *args, **kwargs): |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
281 |
"""bail on push if the extension isn't enabled on remote when needed""" |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
282 |
if 'lfs' in repo.requirements: |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
283 |
# 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:
35505
diff
changeset
|
284 |
# 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:
35505
diff
changeset
|
285 |
# this repo use lfs, and the remote repo needs the extension loaded. |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
286 |
if not remote.local() and not remote.capable('lfs'): |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
287 |
# 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:
35505
diff
changeset
|
288 |
# are missing between local repos. |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
289 |
m = _("required features are not supported in the destination: %s") |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
290 |
raise error.Abort(m % 'lfs', |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
291 |
hint=_('enable the lfs extension on the server')) |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
292 |
return orig(repo, remote, *args, **kwargs) |
fa865878a849
lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
35505
diff
changeset
|
293 |
|
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
294 |
def writenewbundle(orig, ui, repo, source, filename, bundletype, outgoing, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
295 |
*args, **kwargs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
296 |
"""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
|
297 |
uploadblobsfromrevs(repo, outgoing.missing) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
298 |
return orig(ui, repo, source, filename, bundletype, outgoing, *args, |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
299 |
**kwargs) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
300 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
301 |
def extractpointers(repo, revs): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
302 |
"""return a list of lfs pointers added by given revs""" |
35478
5a73a0446afd
lfs: use ui.note() and ui.debug() instead of ui.write() and their flags
Matt Harbison <matt_harbison@yahoo.com>
parents:
35476
diff
changeset
|
303 |
repo.ui.debug('lfs: computing set of blobs to upload\n') |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
304 |
pointers = {} |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
305 |
for r in revs: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
306 |
ctx = repo[r] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
307 |
for p in pointersfromctx(ctx).values(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
308 |
pointers[p.oid()] = p |
35473
02f54a1ec9eb
lfs: add note messages indicating what store holds the lfs blob
Matt Harbison <matt_harbison@yahoo.com>
parents:
35397
diff
changeset
|
309 |
return sorted(pointers.values()) |
35098
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
310 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
311 |
def pointersfromctx(ctx): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
312 |
"""return a dict {path: pointer} for given single changectx""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
313 |
result = {} |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
314 |
for f in ctx.files(): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
315 |
if f not in ctx: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
316 |
continue |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
317 |
fctx = ctx[f] |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
318 |
if not _islfs(fctx.filelog(), fctx.filenode()): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
319 |
continue |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
320 |
try: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
321 |
result[f] = pointer.deserialize(fctx.rawdata()) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
322 |
except pointer.InvalidPointer as ex: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
323 |
raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n') |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
324 |
% (f, short(ctx.node()), ex)) |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
325 |
return result |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
326 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
327 |
def uploadblobs(repo, pointers): |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
328 |
"""upload given pointers from local blobstore""" |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
329 |
if not pointers: |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
330 |
return |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
331 |
|
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
332 |
remoteblob = repo.svfs.lfsremoteblobstore |
66c5a8cf2868
lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
333 |
remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore) |
35346
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
334 |
|
35363
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
335 |
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:
35346
diff
changeset
|
336 |
orig(ui, srcrepo, dstrepo, requirements) |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
337 |
|
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
338 |
srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
339 |
dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
340 |
|
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
341 |
for dirpath, dirs, files in srclfsvfs.walk(): |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
342 |
for oid in files: |
35397
a7ff4071c8aa
lfs: use 'ui' provided to `upgrade` for output, instead of stealing srcrepo's
Matt Harbison <matt_harbison@yahoo.com>
parents:
35363
diff
changeset
|
343 |
ui.write(_('copying lfs blob %s\n') % oid) |
35363
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
344 |
lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid)) |
b0ba1539af01
lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents:
35346
diff
changeset
|
345 |
|
35346
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
346 |
def upgraderequirements(orig, repo): |
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
347 |
reqs = orig(repo) |
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
348 |
if 'lfs' in repo.requirements: |
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
349 |
reqs.add('lfs') |
9eb19b13e92a
lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents:
35215
diff
changeset
|
350 |
return reqs |