hgext/lfs/__init__.py
author Yuya Nishihara <yuya@tcha.org>
Sun, 14 Jan 2018 13:29:15 +0900
changeset 35741 73432eee0ac4
parent 35735 693e3bcae19e
child 35768 60a6ab7bcda7
permissions -rw-r--r--
fileset: add kind:pat operator ":" isn't taken as a symbol character but an infix operator so we can write e.g. "path:'foo bar'" as well as "'path:foo bar'". An invalid pattern kind is rejected in the former form as we know a kind is specified explicitly. The binding strength is copied from "x:y" range operator of revset. Perhaps it can be adjusted later if we want to parse "foo:bar()" as "(foo:bar)()", not "foo:(bar())". We can also add "kind:" postfix operator if we want. One possible confusion is that the scope of the leading "set:" vs "kind:pat" operator. The former is consumed by a matcher so applies to the whole fileset expression: $ hg files 'set:foo() or kind:bar or baz' ^^^^^^^^^^^^^^^^^^^^^^^^ Whereas the scope of kind:pat operator is narrow: $ hg files 'set:foo() or kind:bar or baz' ^^^
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
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    10
The extension reads its configuration from a versioned ``.hglfs``
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    11
configuration file found in the root of the working directory. The
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    12
``.hglfs`` file uses the same syntax as all other Mercurial
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    13
configuration files. It uses a single section, ``[track]``.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    14
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    15
The ``[track]`` section specifies which files are stored as LFS (or
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    16
not). Each line is keyed by a file pattern, with a predicate value.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    17
The first file pattern match is used, so put more specific patterns
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    18
first.  The available predicates are ``all()``, ``none()``, and
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    19
``size()``. See "hg help filesets.size" for the latter.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    20
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    21
Example versioned ``.hglfs`` file::
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    22
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    23
  [track]
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    24
  # No Makefile or python file, anywhere, will be LFS
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    25
  **Makefile = none()
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    26
  **.py = none()
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    27
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    28
  **.zip = all()
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    29
  **.exe = size(">1MB")
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    30
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    31
  # Catchall for everything not matched above
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    32
  ** = size(">10MB")
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    33
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    34
Configs::
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    35
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    36
    [lfs]
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    37
    # Remote endpoint. Multiple protocols are supported:
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    38
    # - 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
    39
    #   git-lfs endpoint
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    40
    # - file:///tmp/path
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    41
    #   local filesystem, usually for testing
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    42
    # if unset, lfs will prompt setting this when it must use this value.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    43
    # (default: unset)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    44
    url = https://example.com/lfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    45
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    46
    # 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
    47
    # 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
    48
    # 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
    49
    # 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
    50
    # 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
    51
    #
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    52
    # Some examples:
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    53
    # - all()                       # everything
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    54
    # - none()                      # nothing
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    55
    # - 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
    56
    # - !**.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
    57
    # - **.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
    58
    # - 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
    59
    # - (**.php & size(">2MB")) | (**.js & size(">5MB")) | **.tar.gz
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35735
diff changeset
    60
    #     | (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
    61
    # (default: none())
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    62
    #
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    63
    # 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
    64
    # 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
    65
    track = size(">10M")
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    66
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    67
    # 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
    68
    retry = 5
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
    69
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
    70
    # 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
    71
    # 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
    72
    usercache = /path/to/global/cache
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    73
"""
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    74
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    75
from __future__ import absolute_import
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    76
35099
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
    77
from mercurial.i18n import _
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
    78
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    79
from mercurial import (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    80
    bundle2,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    81
    changegroup,
35663
a985834961f7 lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents: 35658
diff changeset
    82
    cmdutil,
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    83
    config,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    84
    context,
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
    85
    error,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    86
    exchange,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    87
    extensions,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    88
    filelog,
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    89
    fileset,
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
    90
    hg,
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
    91
    localrepo,
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
    92
    minifileset,
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
    93
    node,
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
    94
    pycompat,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    95
    registrar,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    96
    revlog,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    97
    scmutil,
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
    98
    templatekw,
35346
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
    99
    upgrade,
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   100
    util,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   101
    vfs as vfsmod,
35506
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
   102
    wireproto,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   103
)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   104
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   105
from . import (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   106
    blobstore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   107
    wrapper,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   108
)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   109
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   110
# 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
   111
# 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
   112
# 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
   113
# leave the attribute unspecified.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   114
testedwith = 'ships-with-hg-core'
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   115
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   116
configtable = {}
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   117
configitem = registrar.configitem(configtable)
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   118
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
   119
configitem('experimental', 'lfs.user-agent',
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
   120
    default=None,
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
   121
)
35732
10e62d5efa73 lfs: default to not using workers for upload/download
Matt Harbison <matt_harbison@yahoo.com>
parents: 35731
diff changeset
   122
configitem('experimental', 'lfs.worker-enable',
10e62d5efa73 lfs: default to not using workers for upload/download
Matt Harbison <matt_harbison@yahoo.com>
parents: 35731
diff changeset
   123
    default=False,
10e62d5efa73 lfs: default to not using workers for upload/download
Matt Harbison <matt_harbison@yahoo.com>
parents: 35731
diff changeset
   124
)
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
   125
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   126
configitem('lfs', 'url',
35614
6d6d20658cce lfs: drop deprecated remote store config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35506
diff changeset
   127
    default=None,
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   128
)
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   129
configitem('lfs', 'usercache',
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   130
    default=None,
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
   131
)
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   132
# Deprecated
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   133
configitem('lfs', 'threshold',
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   134
    default=None,
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   135
)
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   136
configitem('lfs', 'track',
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   137
    default='none()',
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
   138
)
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   139
configitem('lfs', 'retry',
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   140
    default=5,
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   141
)
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
   142
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   143
cmdtable = {}
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   144
command = registrar.command(cmdtable)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   145
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   146
templatekeyword = registrar.templatekeyword()
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   147
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
   148
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
   149
    # don't die on seeing a repo with the lfs requirement
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
   150
    supported |= {'lfs'}
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
   151
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
   152
def uisetup(ui):
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
   153
    localrepo.localrepository.featuresetupfuncs.add(featuresetup)
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
   154
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   155
def reposetup(ui, repo):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   156
    # 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
   157
    if not repo.local():
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   158
        return
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   159
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   160
    repo.svfs.lfslocalblobstore = blobstore.local(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   161
    repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   162
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   163
    class lfsrepo(repo.__class__):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   164
        @localrepo.unfilteredmethod
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   165
        def commitctx(self, ctx, error=False):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   166
            repo.svfs.options['lfstrack'] = _trackedmatcher(self, ctx)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   167
            return super(lfsrepo, self).commitctx(ctx, error)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   168
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   169
    repo.__class__ = lfsrepo
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   170
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
   171
    if 'lfs' not in repo.requirements:
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
   172
        def checkrequireslfs(ui, repo, **kwargs):
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
   173
            if 'lfs' not in repo.requirements:
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   174
                last = kwargs.get('node_last')
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   175
                _bin = node.bin
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   176
                if last:
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   177
                    s = repo.set('%n:%n', _bin(kwargs['node']), _bin(last))
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   178
                else:
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   179
                    s = repo.set('%n', _bin(kwargs['node']))
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   180
            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
   181
                # TODO: is there a way to just walk the files in the commit?
35452
488634db5928 lfs: fix committing deleted files caused by e0a1b9ee93cd
Jun Wu <quark@fb.com>
parents: 35440
diff changeset
   182
                if any(ctx[f].islfs() for f in ctx.files() if f in ctx):
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
   183
                    repo.requirements.add('lfs')
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
   184
                    repo._writerequirements()
35735
693e3bcae19e lfs: defer registering the pre-push hook until blobs are committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35732
diff changeset
   185
                    repo.prepushoutgoinghooks.add('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
   186
                    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
   187
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
   188
        ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs')
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
   189
        ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs')
35735
693e3bcae19e lfs: defer registering the pre-push hook until blobs are committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35732
diff changeset
   190
    else:
693e3bcae19e lfs: defer registering the pre-push hook until blobs are committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35732
diff changeset
   191
        repo.prepushoutgoinghooks.add('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
   192
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   193
def _trackedmatcher(repo, ctx):
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   194
    """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
   195
    track a given file with lfs."""
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   196
    data = ''
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   197
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   198
    if '.hglfs' in ctx.added() or '.hglfs' in ctx.modified():
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   199
        data = ctx['.hglfs'].data()
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   200
    elif '.hglfs' not in ctx.removed():
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   201
        p1 = repo['.']
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   202
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   203
        if '.hglfs' not in p1:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   204
            # No '.hglfs' in wdir or in parent.  Fallback to config
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   205
            # for now.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   206
            trackspec = repo.ui.config('lfs', 'track')
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   207
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   208
            # deprecated config: lfs.threshold
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   209
            threshold = repo.ui.configbytes('lfs', 'threshold')
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   210
            if threshold:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   211
                fileset.parse(trackspec)  # make sure syntax errors are confined
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   212
                trackspec = "(%s) | size('>%d')" % (trackspec, threshold)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   213
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   214
            return minifileset.compile(trackspec)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   215
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   216
        data = p1['.hglfs'].data()
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   217
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   218
    # In removed, or not in parent
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   219
    if not data:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   220
        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
   221
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   222
    # 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
   223
    # and line number.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   224
    cfg = config.config()
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   225
    cfg.parse('.hglfs', data)
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   226
35665
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   227
    try:
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   228
        rules = [(minifileset.compile(pattern), minifileset.compile(rule))
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   229
                 for pattern, rule in cfg.items('track')]
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   230
    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
   231
        # 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
   232
        # .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
   233
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   234
        # TODO: See if the line number of the file can be made available.
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   235
        raise error.Abort(_('parse error in .hglfs: %s') % e)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   236
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   237
    def _match(path, size):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   238
        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
   239
            if pat(path, size):
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   240
                return rule(path, size)
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   241
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   242
        return False
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   243
1ad1e59b405e lfs: control tracked file selection via a tracked file
Matt Harbison <matt_harbison@yahoo.com>
parents: 35664
diff changeset
   244
    return _match
35664
3c838bdc57b6 lfs: move the tracked file function creation to a method
Matt Harbison <matt_harbison@yahoo.com>
parents: 35663
diff changeset
   245
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   246
def wrapfilelog(filelog):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   247
    wrapfunction = extensions.wrapfunction
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   248
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   249
    wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   250
    wrapfunction(filelog, 'renamed', wrapper.filelogrenamed)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   251
    wrapfunction(filelog, 'size', wrapper.filelogsize)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   252
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   253
def extsetup(ui):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   254
    wrapfilelog(filelog.filelog)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   255
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   256
    wrapfunction = extensions.wrapfunction
35178
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
   257
35663
a985834961f7 lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`
Matt Harbison <matt_harbison@yahoo.com>
parents: 35658
diff changeset
   258
    wrapfunction(cmdutil, '_updatecatformatter', wrapper._updatecatformatter)
35178
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
   259
    wrapfunction(scmutil, 'wrapconvertsink', wrapper.convertsink)
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
   260
35363
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
   261
    wrapfunction(upgrade, '_finishdatamigration',
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
   262
                 wrapper.upgradefinishdatamigration)
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
   263
35346
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   264
    wrapfunction(upgrade, 'preservedrequirements',
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   265
                 wrapper.upgraderequirements)
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   266
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   267
    wrapfunction(upgrade, 'supporteddestrequirements',
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   268
                 wrapper.upgraderequirements)
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
   269
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   270
    wrapfunction(changegroup,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   271
                 'supportedoutgoingversions',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   272
                 wrapper.supportedoutgoingversions)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   273
    wrapfunction(changegroup,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   274
                 'allsupportedversions',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   275
                 wrapper.allsupportedversions)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   276
35506
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
   277
    wrapfunction(exchange, 'push', wrapper.push)
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
   278
    wrapfunction(wireproto, '_capabilities', wrapper._capabilities)
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
   279
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   280
    wrapfunction(context.basefilectx, 'cmp', wrapper.filectxcmp)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   281
    wrapfunction(context.basefilectx, 'isbinary', wrapper.filectxisbinary)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   282
    context.basefilectx.islfs = wrapper.filectxislfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   283
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   284
    revlog.addflagprocessor(
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   285
        revlog.REVIDX_EXTSTORED,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   286
        (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   287
            wrapper.readfromstore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   288
            wrapper.writetostore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   289
            wrapper.bypasscheckhash,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   290
        ),
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   291
    )
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   292
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
   293
    wrapfunction(hg, 'clone', wrapper.hgclone)
35214
a8c778b2a689 lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35213
diff changeset
   294
    wrapfunction(hg, 'postshare', wrapper.hgpostshare)
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
   295
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   296
    # 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
   297
    # "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
   298
    # "packed1". Using "packed1" with lfs will likely cause trouble.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   299
    names = [k for k, v in exchange._bundlespeccgversions.items() if v == '02']
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   300
    for k in names:
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   301
        exchange._bundlespeccgversions[k] = '03'
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   302
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   303
    # bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   304
    # options and blob stores are passed from othervfs to the new readonlyvfs.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   305
    wrapfunction(vfsmod.readonlyvfs, '__init__', wrapper.vfsinit)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   306
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   307
    # when writing a bundle via "hg bundle" command, upload related LFS blobs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   308
    wrapfunction(bundle2, 'writenewbundle', wrapper.writenewbundle)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   309
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   310
@templatekeyword('lfs_files')
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   311
def lfsfiles(repo, ctx, **args):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   312
    """List of strings. LFS files added or modified by the changeset."""
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   313
    args = pycompat.byteskwargs(args)
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   314
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   315
    pointers = wrapper.pointersfromctx(ctx) # {path: pointer}
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   316
    files = sorted(pointers.keys())
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   317
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   318
    def lfsattrs(v):
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   319
        # In the file spec, version is first and the other keys are sorted.
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   320
        sortkeyfunc = lambda x: (x[0] != 'version', x)
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   321
        items = sorted(pointers[v].iteritems(), key=sortkeyfunc)
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   322
        return util.sortdict(items)
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   323
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   324
    makemap = lambda v: {
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   325
        'file': v,
35658
a1222a8cc93b lfs: add the '{oid}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35657
diff changeset
   326
        'oid': pointers[v].oid(),
35731
f58245b9e3ea lfs: add the '{lfsattrs}' template keyword to '{lfs_files}'
Matt Harbison <matt_harbison@yahoo.com>
parents: 35665
diff changeset
   327
        'lfsattrs': templatekw.hybriddict(lfsattrs(v)),
35657
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   328
    }
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   329
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   330
    # TODO: make the separator ', '?
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   331
    f = templatekw._showlist('lfs_file', files, args)
8580e5898cb7 lfs: convert '{lfs_files}' keyword to a hybrid list
Matt Harbison <matt_harbison@yahoo.com>
parents: 35618
diff changeset
   332
    return templatekw._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
   333
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   334
@command('debuglfsupload',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   335
         [('r', 'rev', [], _('upload large files introduced by REV'))])
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   336
def debuglfsupload(ui, repo, **opts):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   337
    """upload lfs blobs added by the working copy parent or given revisions"""
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   338
    revs = opts.get('rev', [])
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   339
    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
   340
    wrapper.uploadblobs(repo, pointers)