hgext/lfs/__init__.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 20 Sep 2021 10:59:26 -0400
changeset 48011 8655a77dce94
parent 46113 59fa3890d40a
child 48116 5ced12cfa41b
permissions -rw-r--r--
parser: force a `ValueError` to bytes before passing to `error.ParseError` I'm not sure what changed before pytype 09-09-2021 (from 04-15-2021), but this started getting flagged. I think there's a pytype bug here, because I don't see how `.lower()` can be getting called on a `ValueError` after it is forced to a byte string. That's suppressed for now to make progress. This fixes: File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: ValueError) Attributes of protocol Iterable[int] are not implemented on ValueError: __iter__ File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: No attribute 'lower' on ValueError [attribute-error] In Union[ValueError, mercurial.pycompat.bytestr] Differential Revision: https://phab.mercurial-scm.org/D11471
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     1
# lfs - hash-preserving large file support using Git-LFS protocol
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
"""lfs - large file support (EXPERIMENTAL)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     9
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    10
This extension allows large files to be tracked outside of the normal
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    11
repository storage and stored on a centralized server, similar to the
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    12
``largefiles`` extension.  The ``git-lfs`` protocol is used when
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    13
communicating with the server, so existing git infrastructure can be
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    14
harnessed.  Even though the files are stored outside of the repository,
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    15
they are still integrity checked in the same manner as normal files.
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    16
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    17
The files stored outside of the repository are downloaded on demand,
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    18
which reduces the time to clone, and possibly the local disk usage.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    19
This changes fundamental workflows in a DVCS, so careful thought
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    20
should be given before deploying it.  :hg:`convert` can be used to
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    21
convert LFS repositories to normal repositories that no longer
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    22
require this extension, and do so without changing the commit hashes.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    23
This allows the extension to be disabled if the centralized workflow
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    24
becomes burdensome.  However, the pre and post convert clones will
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    25
not be able to communicate with each other unless the extension is
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    26
enabled on both.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    27
35807
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    28
To start a new repository, or to add LFS files to an existing one, just
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    29
create an ``.hglfs`` file as described below in the root directory of
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    30
the repository.  Typically, this file should be put under version
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    31
control, so that the settings will propagate to other repositories with
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    32
push and pull.  During any commit, Mercurial will consult this file to
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    33
determine if an added or modified file should be stored externally.  The
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    34
type of storage depends on the characteristics of the file at each
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    35
commit.  A file that is near a size threshold may switch back and forth
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
    36
between LFS and normal storage, as needed.
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    37
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    38
Alternately, both normal repositories and largefile controlled
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    39
repositories can be converted to LFS by using :hg:`convert` and the
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    40
``lfs.track`` config option described below.  The ``.hglfs`` file
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    41
should then be created and added, to control subsequent LFS selection.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    42
The hashes are also unchanged in this case.  The LFS and non-LFS
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    43
repositories can be distinguished because the LFS repository will
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    44
abort any command if this extension is disabled.
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    45
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    46
Committed LFS files are held locally, until the repository is pushed.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    47
Prior to pushing the normal repository data, the LFS files that are
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    48
tracked by the outgoing commits are automatically uploaded to the
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    49
configured central server.  No LFS files are transferred on
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    50
:hg:`pull` or :hg:`clone`.  Instead, the files are downloaded on
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    51
demand as they need to be read, if a cached copy cannot be found
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    52
locally.  Both committing and downloading an LFS file will link the
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    53
file to a usercache, to speed up future access.  See the `usercache`
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    54
config setting described below.
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    55
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    56
The extension reads its configuration from a versioned ``.hglfs``
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    57
configuration file found in the root of the working directory. The
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    58
``.hglfs`` file uses the same syntax as all other Mercurial
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    59
configuration files. It uses a single section, ``[track]``.
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    60
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    61
The ``[track]`` section specifies which files are stored as LFS (or
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    62
not). Each line is keyed by a file pattern, with a predicate value.
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    63
The first file pattern match is used, so put more specific patterns
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    64
first.  The available predicates are ``all()``, ``none()``, and
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    65
``size()``. See "hg help filesets.size" for the latter.
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    66
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    67
Example versioned ``.hglfs`` file::
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    68
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    69
  [track]
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    70
  # No Makefile or python file, anywhere, will be LFS
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    71
  **Makefile = none()
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    72
  **.py = none()
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    73
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    74
  **.zip = all()
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    75
  **.exe = size(">1MB")
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    76
43303
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    77
  # Catchall for everything not matched above
26caf96a5fa9 lfs: dedent documentation section about .hglfs file
Denis Laxalde <denis@laxalde.org>
parents: 43105
diff changeset
    78
  ** = size(">10MB")
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    79
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    80
Configs::
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    81
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    82
    [lfs]
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    83
    # Remote endpoint. Multiple protocols are supported:
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    84
    # - http(s)://user:pass@example.com/path
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    85
    #   git-lfs endpoint
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    86
    # - file:///tmp/path
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    87
    #   local filesystem, usually for testing
37564
31a4ea773369 lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents: 37562
diff changeset
    88
    # if unset, lfs will assume the remote repository also handles blob storage
31a4ea773369 lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents: 37562
diff changeset
    89
    # for http(s) URLs.  Otherwise, lfs will prompt to set this when it must
31a4ea773369 lfs: infer the blob store URL from an explicit push dest or default-push
Matt Harbison <matt_harbison@yahoo.com>
parents: 37562
diff changeset
    90
    # use this value.
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    91
    # (default: unset)
35768
60a6ab7bcda7 lfs: expand the user facing documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 35741
diff changeset
    92
    url = https://example.com/repo.git/info/lfs
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    93
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    94
    # Which files to track in LFS.  Path tests are "**.extname" for file
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    95
    # extensions, and "path:under/some/directory" for path prefix.  Both
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35735
diff changeset
    96
    # are relative to the repository root.
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    97
    # File size can be tested with the "size()" fileset, and tests can be
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    98
    # joined with fileset operators.  (See "hg help filesets.operators".)
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    99
    #
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   100
    # Some examples:
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   101
    # - all()                       # everything
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   102
    # - none()                      # nothing
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   103
    # - size(">20MB")               # larger than 20MB
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   104
    # - !**.txt                     # anything not a *.txt file
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   105
    # - **.zip | **.tar.gz | **.7z  # some types of compressed files
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35735
diff changeset
   106
    # - path:bin                    # files under "bin" in the project root
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   107
    # - (**.php & size(">2MB")) | (**.js & size(">5MB")) | **.tar.gz
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35735
diff changeset
   108
    #     | (path:bin & !path:/bin/README) | size(">1GB")
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   109
    # (default: none())
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   110
    #
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   111
    # This is ignored if there is a tracked '.hglfs' file, and this setting
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   112
    # will eventually be deprecated and removed.
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   113
    track = size(">10M")
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   114
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   115
    # how many times to retry before giving up on transferring an object
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   116
    retry = 5
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   117
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   118
    # the local directory to store lfs files for sharing across local clones.
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   119
    # If not set, the cache is located in an OS specific cache location.
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   120
    usercache = /path/to/global/cache
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   121
"""
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
from __future__ import absolute_import
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   124
40268
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   125
import sys
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   126
35099
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
   127
from mercurial.i18n import _
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   128
from mercurial.node import bin
35099
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
   129
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   130
from mercurial import (
45784
74271829ddc0 clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45106
diff changeset
   131
    bundlecaches,
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   132
    config,
41279
c9e1104e6272 exthelper: drop the addattr() decorator
Matt Harbison <matt_harbison@yahoo.com>
parents: 41230
diff changeset
   133
    context,
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   134
    error,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   135
    extensions,
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   136
    exthelper,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   137
    filelog,
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38800
diff changeset
   138
    filesetlang,
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   139
    localrepo,
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   140
    minifileset,
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   141
    pycompat,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   142
    revlog,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   143
    scmutil,
36921
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36598
diff changeset
   144
    templateutil,
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   145
    util,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   146
)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   147
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   148
from mercurial.interfaces import repository
42813
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42620
diff changeset
   149
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   150
from . import (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   151
    blobstore,
37147
a2566597acb5 lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents: 37138
diff changeset
   152
    wireprotolfsserver,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   153
    wrapper,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   154
)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   155
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   156
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   157
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   158
# be specifying the version(s) of Mercurial they are tested with, or
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   159
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   160
testedwith = b'ships-with-hg-core'
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   161
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   162
eh = exthelper.exthelper()
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   163
eh.merge(wrapper.eh)
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   164
eh.merge(wireprotolfsserver.eh)
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   165
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   166
cmdtable = eh.cmdtable
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   167
configtable = eh.configtable
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   168
extsetup = eh.finalextsetup
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   169
uisetup = eh.finaluisetup
41070
8f40e21ca842 exthelper: reintroduce the ability to register filesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 41069
diff changeset
   170
filesetpredicate = eh.filesetpredicate
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   171
reposetup = eh.finalreposetup
41069
70ca0e846d25 exthelper: reintroduce the ability to register templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 41048
diff changeset
   172
templatekeyword = eh.templatekeyword
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   173
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   174
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   175
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   176
    b'lfs.serve',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   177
    default=True,
37248
dfb38c4850a9 lfs: add an experimental knob to disable blob serving
Matt Harbison <matt_harbison@yahoo.com>
parents: 37165
diff changeset
   178
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   179
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   180
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   181
    b'lfs.user-agent',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   182
    default=None,
35440
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
   183
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   184
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   185
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   186
    b'lfs.disableusercache',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   187
    default=False,
37562
e5cd8d1a094d lfs: special case the null:// usercache instead of treating it as a url
Matt Harbison <matt_harbison@yahoo.com>
parents: 37518
diff changeset
   188
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   189
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   190
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   191
    b'lfs.worker-enable',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   192
    default=True,
35732
10e62d5efa73 lfs: default to not using workers for upload/download
Matt Harbison <matt_harbison@yahoo.com>
parents: 35731
diff changeset
   193
)
35440
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
   194
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   195
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   196
    b'lfs',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   197
    b'url',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   198
    default=None,
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   199
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   200
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   201
    b'lfs',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   202
    b'usercache',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   203
    default=None,
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   204
)
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   205
# Deprecated
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   206
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   207
    b'lfs',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   208
    b'threshold',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   209
    default=None,
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   210
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   211
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   212
    b'lfs',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   213
    b'track',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   214
    default=b'none()',
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   215
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   216
eh.configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   217
    b'lfs',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   218
    b'retry',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45784
diff changeset
   219
    default=5,
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   220
)
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   221
40268
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   222
lfsprocessor = (
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   223
    wrapper.readfromstore,
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   224
    wrapper.writetostore,
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   225
    wrapper.bypasscheckhash,
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   226
)
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   227
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   228
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   229
def featuresetup(ui, supported):
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   230
    # don't die on seeing a repo with the lfs requirement
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   231
    supported |= {b'lfs'}
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   232
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   233
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   234
@eh.uisetup
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   235
def _uisetup(ui):
37135
ecac0006b90e localrepo: move featuresetupfuncs out of localrepository class (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37132
diff changeset
   236
    localrepo.featuresetupfuncs.add(featuresetup)
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   237
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   238
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   239
@eh.reposetup
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   240
def _reposetup(ui, repo):
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   241
    # Nothing to do with a remote repo
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   242
    if not repo.local():
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   243
        return
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   244
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   245
    repo.svfs.lfslocalblobstore = blobstore.local(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   246
    repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   247
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   248
    class lfsrepo(repo.__class__):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   249
        @localrepo.unfilteredmethod
42620
d98ec36be808 convert: add a config option to help doing identity hg->hg conversion
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 41279
diff changeset
   250
        def commitctx(self, ctx, error=False, origctx=None):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   251
            repo.svfs.options[b'lfstrack'] = _trackedmatcher(self)
42620
d98ec36be808 convert: add a config option to help doing identity hg->hg conversion
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 41279
diff changeset
   252
            return super(lfsrepo, self).commitctx(ctx, error, origctx=origctx)
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   253
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   254
    repo.__class__ = lfsrepo
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   255
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   256
    if b'lfs' not in repo.requirements:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   257
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   258
        def checkrequireslfs(ui, repo, **kwargs):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   259
            if b'lfs' in repo.requirements:
40131
535fc8a22365 lfs: avoid a potential variable reference before assignment error in cmdserver
Matt Harbison <matt_harbison@yahoo.com>
parents: 38689
diff changeset
   260
                return 0
535fc8a22365 lfs: avoid a potential variable reference before assignment error in cmdserver
Matt Harbison <matt_harbison@yahoo.com>
parents: 38689
diff changeset
   261
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43303
diff changeset
   262
            last = kwargs.get('node_last')
40131
535fc8a22365 lfs: avoid a potential variable reference before assignment error in cmdserver
Matt Harbison <matt_harbison@yahoo.com>
parents: 38689
diff changeset
   263
            if last:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   264
                s = repo.set(b'%n:%n', bin(kwargs['node']), bin(last))
40131
535fc8a22365 lfs: avoid a potential variable reference before assignment error in cmdserver
Matt Harbison <matt_harbison@yahoo.com>
parents: 38689
diff changeset
   265
            else:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   266
                s = repo.set(b'%n', bin(kwargs['node']))
41230
d2d716cc0700 narrow: extract repo property for store narrowmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 41070
diff changeset
   267
            match = repo._storenarrowmatch
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   268
            for ctx in s:
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   269
                # TODO: is there a way to just walk the files in the commit?
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   270
                if any(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   271
                    ctx[f].islfs() for f in ctx.files() if f in ctx and match(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   272
                ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   273
                    repo.requirements.add(b'lfs')
39851
1f7b3b980af8 lfs: add repository feature denoting the use of LFS
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38805
diff changeset
   274
                    repo.features.add(repository.REPO_FEATURE_LFS)
45106
a03c177a4679 scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44274
diff changeset
   275
                    scmutil.writereporequirements(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
                    repo.prepushoutgoinghooks.add(b'lfs', wrapper.prepush)
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   277
                    break
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   278
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   279
        ui.setconfig(b'hooks', b'commit.lfs', checkrequireslfs, b'lfs')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   280
        ui.setconfig(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   281
            b'hooks', b'pretxnchangegroup.lfs', checkrequireslfs, b'lfs'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   282
        )
35735
693e3bcae19e lfs: defer registering the pre-push hook until blobs are committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35732
diff changeset
   283
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   284
        repo.prepushoutgoinghooks.add(b'lfs', wrapper.prepush)
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
   285
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   286
35880
6bd2846a82e8 lfs: drop an unused function parameter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35807
diff changeset
   287
def _trackedmatcher(repo):
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   288
    """Return a function (path, size) -> bool indicating whether or not to
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   289
    track a given file with lfs."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   290
    if not repo.wvfs.exists(b'.hglfs'):
35807
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
   291
        # No '.hglfs' in wdir.  Fallback to config for now.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   292
        trackspec = repo.ui.config(b'lfs', b'track')
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   293
35807
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
   294
        # deprecated config: lfs.threshold
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
        threshold = repo.ui.configbytes(b'lfs', b'threshold')
35807
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
   296
        if threshold:
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38800
diff changeset
   297
            filesetlang.parse(trackspec)  # make sure syntax errors are confined
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
            trackspec = b"(%s) | size('>%d')" % (trackspec, threshold)
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   299
35807
4425790f2373 lfs: don't require the .hglfs file to be tracked to control the policy
Matt Harbison <matt_harbison@yahoo.com>
parents: 35798
diff changeset
   300
        return minifileset.compile(trackspec)
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   301
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   302
    data = repo.wvfs.tryread(b'.hglfs')
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   303
    if not data:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   304
        return lambda p, s: False
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   305
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   306
    # Parse errors here will abort with a message that points to the .hglfs file
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   307
    # and line number.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   308
    cfg = config.config()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   309
    cfg.parse(b'.hglfs', data)
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   310
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   311
    try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   312
        rules = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   313
            (minifileset.compile(pattern), minifileset.compile(rule))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   314
            for pattern, rule in cfg.items(b'track')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   315
        ]
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   316
    except error.ParseError as e:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   317
        # The original exception gives no indicator that the error is in the
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   318
        # .hglfs file, so add that.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   319
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   320
        # TODO: See if the line number of the file can be made available.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   321
        raise error.Abort(_(b'parse error in .hglfs: %s') % e)
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   322
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   323
    def _match(path, size):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   324
        for pat, rule in rules:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   325
            if pat(path, size):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   326
                return rule(path, size)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   327
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   328
        return False
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   329
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   330
    return _match
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   331
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   332
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   333
# Called by remotefilelog
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   334
def wrapfilelog(filelog):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   335
    wrapfunction = extensions.wrapfunction
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   336
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   337
    wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   338
    wrapfunction(filelog, 'renamed', wrapper.filelogrenamed)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   339
    wrapfunction(filelog, 'size', wrapper.filelogsize)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   340
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   341
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   342
@eh.wrapfunction(localrepo, b'resolverevlogstorevfsoptions')
40268
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   343
def _resolverevlogstorevfsoptions(orig, ui, requirements, features):
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   344
    opts = orig(ui, requirements, features)
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   345
    for name, module in extensions.extensions(ui):
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   346
        if module is sys.modules[__name__]:
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   347
            if revlog.REVIDX_EXTSTORED in opts[b'flagprocessors']:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   348
                msg = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   349
                    _(b"cannot register multiple processors on flag '%#x'.")
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   350
                    % revlog.REVIDX_EXTSTORED
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   351
                )
40268
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   352
                raise error.Abort(msg)
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   353
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   354
            opts[b'flagprocessors'][revlog.REVIDX_EXTSTORED] = lfsprocessor
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   355
            break
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   356
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   357
    return opts
9c4cbbb0fc51 lfs: register the flag processors per repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 39868
diff changeset
   358
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   359
41048
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   360
@eh.extsetup
84d61fdcefa5 lfs: convert to using exthelper to wrap functions
Matt Harbison <matt_harbison@yahoo.com>
parents: 40313
diff changeset
   361
def _extsetup(ui):
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   362
    wrapfilelog(filelog.filelog)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   363
41279
c9e1104e6272 exthelper: drop the addattr() decorator
Matt Harbison <matt_harbison@yahoo.com>
parents: 41230
diff changeset
   364
    context.basefilectx.islfs = wrapper.filectxislfs
c9e1104e6272 exthelper: drop the addattr() decorator
Matt Harbison <matt_harbison@yahoo.com>
parents: 41230
diff changeset
   365
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   366
    scmutil.fileprefetchhooks.add(b'lfs', wrapper._prefetchfiles)
35922
0b79f99fd7b0 lfs: prefetch lfs blobs when applying merge updates
Matt Harbison <matt_harbison@yahoo.com>
parents: 35880
diff changeset
   367
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   368
    # Make bundle choose changegroup3 instead of changegroup2. This affects
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   369
    # "hg bundle" command. Note: it does not cover all bundle formats like
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   370
    # "packed1". Using "packed1" with lfs will likely cause trouble.
45784
74271829ddc0 clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45106
diff changeset
   371
    bundlecaches._bundlespeccontentopts[b"v2"][b"cg.version"] = b"03"
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   372
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   373
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   374
@eh.filesetpredicate(b'lfs()')
35990
eefb5d603482 lfs: add a fileset for detecting lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35924
diff changeset
   375
def lfsfileset(mctx, x):
eefb5d603482 lfs: add a fileset for detecting lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35924
diff changeset
   376
    """File that uses LFS storage."""
eefb5d603482 lfs: add a fileset for detecting lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35924
diff changeset
   377
    # i18n: "lfs" is a keyword
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   378
    filesetlang.getargs(x, 0, 0, _(b"lfs takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
   379
    ctx = mctx.ctx
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   380
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
   381
    def lfsfilep(f):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
   382
        return wrapper.pointerfromctx(ctx, f, removed=True) is not None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   383
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   384
    return mctx.predicate(lfsfilep, predrepr=b'<lfs>')
35990
eefb5d603482 lfs: add a fileset for detecting lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35924
diff changeset
   385
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   386
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   387
@eh.templatekeyword(b'lfs_files', requires={b'ctx'})
36598
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36519
diff changeset
   388
def lfsfiles(context, mapping):
35999
8c7d5e90e6bd lfs: teach '{lfs_files}' to handle removed files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35990
diff changeset
   389
    """List of strings. All files modified, added, or removed by this
8c7d5e90e6bd lfs: teach '{lfs_files}' to handle removed files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35990
diff changeset
   390
    changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   391
    ctx = context.resource(mapping, b'ctx')
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   392
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   393
    pointers = wrapper.pointersfromctx(ctx, removed=True)  # {path: pointer}
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   394
    files = sorted(pointers.keys())
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   395
35769
f00edef84c3b lfs: rename {lfsattrs} to {pointer}
Matt Harbison <matt_harbison@yahoo.com>
parents: 35768
diff changeset
   396
    def pointer(v):
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   397
        # In the file spec, version is first and the other keys are sorted.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   398
        sortkeyfunc = lambda x: (x[0] != b'version', x)
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
   399
        items = sorted(pycompat.iteritems(pointers[v]), key=sortkeyfunc)
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   400
        return util.sortdict(items)
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   401
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   402
    makemap = lambda v: {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   403
        b'file': v,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   404
        b'lfsoid': pointers[v].oid() if pointers[v] else None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   405
        b'lfspointer': templateutil.hybriddict(pointer(v)),
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   406
    }
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   407
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   408
    # TODO: make the separator ', '?
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   409
    f = templateutil._showcompatlist(context, mapping, b'lfs_file', files)
36921
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36598
diff changeset
   410
    return templateutil.hybrid(f, files, makemap, pycompat.identity)
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   411
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   412
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   413
@eh.command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   414
    b'debuglfsupload',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   415
    [(b'r', b'rev', [], _(b'upload large files introduced by REV'))],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
   416
)
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   417
def debuglfsupload(ui, repo, **opts):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   418
    """upload lfs blobs added by the working copy parent or given revisions"""
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43303
diff changeset
   419
    revs = opts.get('rev', [])
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   420
    pointers = wrapper.extractpointers(repo, scmutil.revrange(repo, revs))
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   421
    wrapper.uploadblobs(repo, pointers)
44071
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   422
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   423
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   424
@eh.wrapcommand(
44072
1a6dd50cd0db lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents: 44071
diff changeset
   425
    b'verify',
1a6dd50cd0db lfs: don't skip locally available blobs when verifying
Matt Harbison <matt_harbison@yahoo.com>
parents: 44071
diff changeset
   426
    opts=[(b'', b'no-lfs', None, _(b'skip missing lfs blob content'))],
44071
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   427
)
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   428
def verify(orig, ui, repo, **opts):
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   429
    skipflags = repo.ui.configint(b'verify', b'skipflags')
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   430
    no_lfs = opts.pop('no_lfs')
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   431
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   432
    if skipflags:
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   433
        # --lfs overrides the config bit, if set.
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   434
        if no_lfs is False:
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   435
            skipflags &= ~repository.REVISION_FLAG_EXTSTORED
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   436
    else:
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   437
        skipflags = 0
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   438
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   439
    if no_lfs is True:
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   440
        skipflags |= repository.REVISION_FLAG_EXTSTORED
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   441
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   442
    with ui.configoverride({(b'verify', b'skipflags'): skipflags}):
34e8305f02bd lfs: add a switch to `hg verify` to ignore the content of blobs
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
   443
        return orig(ui, repo, **opts)