hgext/largefiles/lfutil.py
author Mads Kiilerich <madski@unity3d.com>
Sat, 19 Mar 2016 08:27:54 -0700
changeset 28575 78e4e558fa74
parent 28574 7a4e1749cb07
child 28576 33bd95443e7f
permissions -rw-r--r--
largefiles: drop partial support for not having a user cache 971c55ce03b8 introduced support for not having a "global" user cache. In the rare cases where the environment didn't provide the location of the current home directory, the usercachepath function could return None. That functionality has since bitrotten and several code paths did not correctly check for usercachepath returning None: $ HOME= XDG_CACHE_HOME= hg up --config extensions.largefiles= getting changed largefiles abort: unknown largefiles usercache location Dropping the partial support for it is thus not really a backward compatibility breaking change. Thus: consistently fail early if the usercache location is unknown. It is relevant to be able to control where the largefiles are stored and how they propagate, but that should probably be done differently. The dysfunctional code just gets in the way.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     1
# Copyright 2009-2010 Gregory P. Ward
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     2
# Copyright 2009-2010 Intelerad Medical Systems Incorporated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     3
# Copyright 2010-2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     4
# Copyright 2010-2011 Unity Technologies
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     5
#
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     8
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     9
'''largefiles utility code: must not import other modules in this package.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
import os
15320
681267a5f491 largefiles: use XDG and OS X-specific cache locations by default (issue3067)
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15319
diff changeset
    12
import platform
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
import stat
23185
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
    14
import copy
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    15
15226
2223ea21c98f largefiles: cleanup import, now that we can assume > 1.9 for bundled extension
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
    16
from mercurial import dirstate, httpconnection, match as match_, util, scmutil
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    17
from mercurial.i18n import _
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26025
diff changeset
    18
from mercurial import node, error
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    19
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    20
shortname = '.hglf'
18151
90ad387d9245 largefiles: use constant for '.hglf/'
Mads Kiilerich <madski@unity3d.com>
parents: 18150
diff changeset
    21
shortnameslash = shortname + '/'
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    22
longname = 'largefiles'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    23
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    24
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    25
# -- Private worker functions ------------------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    26
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    27
def getminsize(ui, assumelfiles, opt, default=10):
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    28
    lfsize = opt
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    29
    if not lfsize and assumelfiles:
15304
9aa9d4bb3d88 largefiles: rename config setting 'size' to 'minsize'
Greg Ward <greg@gerg.ca>
parents: 15255
diff changeset
    30
        lfsize = ui.config(longname, 'minsize', default=default)
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    31
    if lfsize:
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    32
        try:
15228
ee625de3541e largefiles: allow minimum size to be a float
Greg Ward <greg@gerg.ca>
parents: 15227
diff changeset
    33
            lfsize = float(lfsize)
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    34
        except ValueError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26025
diff changeset
    35
            raise error.Abort(_('largefiles: size must be number (not %s)\n')
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    36
                             % lfsize)
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    37
    if lfsize is None:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26025
diff changeset
    38
        raise error.Abort(_('minimum size for largefiles must be specified'))
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    39
    return lfsize
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15226
diff changeset
    40
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    41
def link(src, dest):
18998
d035c3902111 largefiles: refactoring - create destination dir in lfutil.link
Mads Kiilerich <madski@unity3d.com>
parents: 18980
diff changeset
    42
    util.makedirs(os.path.dirname(dest))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    43
    try:
15206
f85c76b16f27 largefiles: fix commit of specified file on non-windows
Na'Tosha Bard <natosha@unity3d.com>
parents: 15188
diff changeset
    44
        util.oslink(src, dest)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    45
    except OSError:
15572
926bc23d0b6a largefiles: copy files into .hg/largefiles atomically
Martin Geisler <mg@aragost.com>
parents: 15571
diff changeset
    46
        # if hardlinks fail, fallback on atomic copy
926bc23d0b6a largefiles: copy files into .hg/largefiles atomically
Martin Geisler <mg@aragost.com>
parents: 15571
diff changeset
    47
        dst = util.atomictempfile(dest)
15699
84e55467093c largefiles: copy files in binary mode (issue3164)
Matt Mackall <mpm@selenic.com>
parents: 15658
diff changeset
    48
        for chunk in util.filechunkiter(open(src, 'rb')):
15572
926bc23d0b6a largefiles: copy files into .hg/largefiles atomically
Martin Geisler <mg@aragost.com>
parents: 15571
diff changeset
    49
            dst.write(chunk)
926bc23d0b6a largefiles: copy files into .hg/largefiles atomically
Martin Geisler <mg@aragost.com>
parents: 15571
diff changeset
    50
        dst.close()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    51
        os.chmod(dest, os.stat(src).st_mode)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    52
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
    53
def usercachepath(ui, hash):
28574
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    54
    '''Return the correct location in the "global" largefiles cache for a file
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    55
    with the given hash.
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    56
    This cache is used for sharing of largefiles across repositories - both
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    57
    to preserve download bandwidth and storage space.'''
28575
78e4e558fa74 largefiles: drop partial support for not having a user cache
Mads Kiilerich <madski@unity3d.com>
parents: 28574
diff changeset
    58
    return os.path.join(_usercachedir(ui), hash)
28574
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    59
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    60
def _usercachedir(ui):
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    61
    '''Return the location of the "global" largefiles cache.'''
15350
8b8dd13295db largefiles: use ui.configpath() where appropriate
Greg Ward <greg@gerg.ca>
parents: 15349
diff changeset
    62
    path = ui.configpath(longname, 'usercache', None)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    63
    if path:
28574
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    64
        return path
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    65
    if os.name == 'nt':
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    66
        appdata = os.getenv('LOCALAPPDATA', os.getenv('APPDATA'))
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    67
        if appdata:
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    68
            return os.path.join(appdata, longname)
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    69
    elif platform.system() == 'Darwin':
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    70
        home = os.getenv('HOME')
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    71
        if home:
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    72
            return os.path.join(home, 'Library', 'Caches', longname)
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    73
    elif os.name == 'posix':
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    74
        path = os.getenv('XDG_CACHE_HOME')
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    75
        if path:
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    76
            return os.path.join(path, longname)
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    77
        home = os.getenv('HOME')
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    78
        if home:
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    79
            return os.path.join(home, '.cache', longname)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    80
    else:
28574
7a4e1749cb07 largefiles: refactor usercachepath - extract user cache path function
Mads Kiilerich <madski@unity3d.com>
parents: 28560
diff changeset
    81
        raise error.Abort(_('unknown operating system: %s\n') % os.name)
28575
78e4e558fa74 largefiles: drop partial support for not having a user cache
Mads Kiilerich <madski@unity3d.com>
parents: 28574
diff changeset
    82
    raise error.Abort(_('unknown %s usercache location\n') % longname)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
    84
def inusercache(ui, hash):
15658
971c55ce03b8 largefiles: don't require a user cache (issue3088) (issue3155)
Kevin Gessner <kevin@fogcreek.com>
parents: 15572
diff changeset
    85
    path = usercachepath(ui, hash)
28575
78e4e558fa74 largefiles: drop partial support for not having a user cache
Mads Kiilerich <madski@unity3d.com>
parents: 28574
diff changeset
    86
    return os.path.exists(path)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    87
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    88
def findfile(repo, hash):
24631
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
    89
    path, exists = findstorepath(repo, hash)
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
    90
    if exists:
16928
73b9286e667c largefiles: lowercase messages
Martin Geisler <mg@aragost.com>
parents: 16247
diff changeset
    91
        repo.ui.note(_('found %s in store\n') % hash)
24631
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
    92
        return path
15317
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    93
    elif inusercache(repo.ui, hash):
16928
73b9286e667c largefiles: lowercase messages
Martin Geisler <mg@aragost.com>
parents: 16247
diff changeset
    94
        repo.ui.note(_('found %s in system cache\n') % hash)
15408
db8b0ee74025 largefiles: ensure destination directory exists before findfile links to there
Hao Lian <hao@fogcreek.com>
parents: 15392
diff changeset
    95
        path = storepath(repo, hash)
db8b0ee74025 largefiles: ensure destination directory exists before findfile links to there
Hao Lian <hao@fogcreek.com>
parents: 15392
diff changeset
    96
        link(usercachepath(repo.ui, hash), path)
15913
c35dcde25174 largefiles: refactor lfutil.findfiles to be more logical
Na'Tosha Bard <natosha@unity3d.com>
parents: 15796
diff changeset
    97
        return path
c35dcde25174 largefiles: refactor lfutil.findfiles to be more logical
Na'Tosha Bard <natosha@unity3d.com>
parents: 15796
diff changeset
    98
    return None
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   100
class largefilesdirstate(dirstate.dirstate):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
    def __getitem__(self, key):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   102
        return super(largefilesdirstate, self).__getitem__(unixpath(key))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   103
    def normal(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   104
        return super(largefilesdirstate, self).normal(unixpath(f))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
    def remove(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   106
        return super(largefilesdirstate, self).remove(unixpath(f))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
    def add(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   108
        return super(largefilesdirstate, self).add(unixpath(f))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
    def drop(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   110
        return super(largefilesdirstate, self).drop(unixpath(f))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
    def forget(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   112
        return super(largefilesdirstate, self).forget(unixpath(f))
15793
3ef07ecdb0d5 largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents: 15700
diff changeset
   113
    def normallookup(self, f):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   114
        return super(largefilesdirstate, self).normallookup(unixpath(f))
21085
66c6da0bc7e2 largefiles: fix profile of unused largefilesdirstate._ignore
Mads Kiilerich <madski@unity3d.com>
parents: 21042
diff changeset
   115
    def _ignore(self, f):
18148
bf6252d12c34 largefiles: simplify lfdirstate ignore handling - it is only for tracking .hglf
Mads Kiilerich <madski@unity3d.com>
parents: 18147
diff changeset
   116
        return False
26749
4a82cb5c1dc8 dirstate: show develwarn for write() invocation without transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26627
diff changeset
   117
    def write(self, tr=False):
4a82cb5c1dc8 dirstate: show develwarn for write() invocation without transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26627
diff changeset
   118
        # (1) disable PENDING mode always
4a82cb5c1dc8 dirstate: show develwarn for write() invocation without transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26627
diff changeset
   119
        #     (lfdirstate isn't yet managed as a part of the transaction)
4a82cb5c1dc8 dirstate: show develwarn for write() invocation without transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26627
diff changeset
   120
        # (2) avoid develwarn 'use dirstate.write with ....'
4a82cb5c1dc8 dirstate: show develwarn for write() invocation without transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26627
diff changeset
   121
        super(largefilesdirstate, self).write(None)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   122
17659
ae57920ac188 largefiles: enable islfilesrepo() prior to a commit (issue3541)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17270
diff changeset
   123
def openlfdirstate(ui, repo, create=True):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   124
    '''
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   125
    Return a dirstate object that tracks largefiles: i.e. its root is
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   126
    the repo root, but it is saved in .hg/largefiles/dirstate.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   127
    '''
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   128
    vfs = repo.vfs
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   129
    lfstoredir = longname
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   130
    opener = scmutil.opener(vfs.join(lfstoredir))
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   131
    lfdirstate = largefilesdirstate(opener, ui, repo.root,
15349
63455eb771af largefiles: drop more unnecessary compatibility checks
Greg Ward <greg@gerg.ca>
parents: 15347
diff changeset
   132
                                     repo.dirstate._validate)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   133
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   134
    # If the largefiles dirstate does not exist, populate and create
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   135
    # it. This ensures that we create it on the first meaningful
15794
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   136
    # largefiles operation in a new clone.
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   137
    if create and not vfs.exists(vfs.join(lfstoredir, 'dirstate')):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   138
        matcher = getstandinmatcher(repo)
21917
ac3b3a2d976d largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 21085
diff changeset
   139
        standins = repo.dirstate.walk(matcher, [], False, False)
ac3b3a2d976d largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 21085
diff changeset
   140
ac3b3a2d976d largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 21085
diff changeset
   141
        if len(standins) > 0:
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   142
            vfs.makedirs(lfstoredir)
21917
ac3b3a2d976d largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 21085
diff changeset
   143
ac3b3a2d976d largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate
Matt Harbison <matt_harbison@yahoo.com>
parents: 21085
diff changeset
   144
        for standin in standins:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   145
            lfile = splitstandin(standin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   146
            lfdirstate.normallookup(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   147
    return lfdirstate
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   148
23039
1350b9170089 largefiles: remove confusing rev parameter for lfdirstatestatus
Mads Kiilerich <madski@unity3d.com>
parents: 22919
diff changeset
   149
def lfdirstatestatus(lfdirstate, repo):
1350b9170089 largefiles: remove confusing rev parameter for lfdirstatestatus
Mads Kiilerich <madski@unity3d.com>
parents: 22919
diff changeset
   150
    wctx = repo['.']
15794
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   151
    match = match_.always(repo.root, repo.getcwd())
22911
509e2cbee679 dirstate: separate 'lookup' status field from others
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22095
diff changeset
   152
    unsure, s = lfdirstate.status(match, [], False, False, False)
22919
1982bdb7e2cc largefiles: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22912
diff changeset
   153
    modified, clean = s.modified, s.clean
15794
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   154
    for lfile in unsure:
18299
a7a88a458a4c largefiles: fix revert removing a largefile from a merge
Mads Kiilerich <madski@unity3d.com>
parents: 18154
diff changeset
   155
        try:
23039
1350b9170089 largefiles: remove confusing rev parameter for lfdirstatestatus
Mads Kiilerich <madski@unity3d.com>
parents: 22919
diff changeset
   156
            fctx = wctx[standin(lfile)]
18299
a7a88a458a4c largefiles: fix revert removing a largefile from a merge
Mads Kiilerich <madski@unity3d.com>
parents: 18154
diff changeset
   157
        except LookupError:
a7a88a458a4c largefiles: fix revert removing a largefile from a merge
Mads Kiilerich <madski@unity3d.com>
parents: 18154
diff changeset
   158
            fctx = None
a7a88a458a4c largefiles: fix revert removing a largefile from a merge
Mads Kiilerich <madski@unity3d.com>
parents: 18154
diff changeset
   159
        if not fctx or fctx.data().strip() != hashfile(repo.wjoin(lfile)):
15794
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   160
            modified.append(lfile)
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   161
        else:
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   162
            clean.append(lfile)
0d91211dd12f largefiles: fix inappropriate locking (issue3182)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   163
            lfdirstate.normal(lfile)
22912
3b8e6c095239 lfutil: avoid creating unnecessary copy of status tuple
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22911
diff changeset
   164
    return s
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   165
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   166
def listlfiles(repo, rev=None, matcher=None):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   167
    '''return a list of largefiles in the working copy or the
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   168
    specified changeset'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   169
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   170
    if matcher is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   171
        matcher = getstandinmatcher(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   172
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   173
    # ignore unknown files in working directory
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   174
    return [splitstandin(f)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   175
            for f in repo[rev].walk(matcher)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   176
            if rev is not None or repo.dirstate[f] != '?']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   177
24631
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   178
def instore(repo, hash, forcelocal=False):
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   179
    return os.path.exists(storepath(repo, hash, forcelocal))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   180
24631
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   181
def storepath(repo, hash, forcelocal=False):
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   182
    if not forcelocal and repo.shared():
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   183
        return repo.vfs.reljoin(repo.sharedpath, longname, hash)
24627
f33236c9b025 largefiles: drop os.path reference in lfutil.storepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24336
diff changeset
   184
    return repo.join(longname, hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   185
24629
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   186
def findstorepath(repo, hash):
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   187
    '''Search through the local store path(s) to find the file for the given
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   188
    hash.  If the file is not found, its path in the primary store is returned.
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   189
    The return value is a tuple of (path, exists(path)).
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   190
    '''
24631
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   191
    # For shared repos, the primary store is in the share source.  But for
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   192
    # backward compatibility, force a lookup in the local store if it wasn't
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   193
    # found in the share source.
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   194
    path = storepath(repo, hash, False)
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   195
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   196
    if instore(repo, hash):
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   197
        return (path, True)
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   198
    elif repo.shared() and instore(repo, hash, True):
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   199
        return storepath(repo, hash, True)
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   200
2a3f24786d09 largefiles: use the share source as the primary local store (issue4471)
Matt Harbison <matt_harbison@yahoo.com>
parents: 24629
diff changeset
   201
    return (path, False)
24629
8dc2533f03ef largefiles: introduce lfutil.findstorepath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 24627
diff changeset
   202
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   203
def copyfromcache(repo, hash, filename):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   204
    '''Copy the specified largefile from the repo or system cache to
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   205
    filename in the repository. Return true on success or false if the
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   206
    file was not found in either cache (which should not happened:
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   207
    this is meant to be called only after ensuring that the needed
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   208
    largefile exists in the cache).'''
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   209
    wvfs = repo.wvfs
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   210
    path = findfile(repo, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   211
    if path is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   212
        return False
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   213
    wvfs.makedirs(wvfs.dirname(wvfs.join(filename)))
15570
0f208626d503 largefiles: add comment about non-atomic working directory
Martin Geisler <mg@aragost.com>
parents: 15553
diff changeset
   214
    # The write may fail before the file is fully written, but we
0f208626d503 largefiles: add comment about non-atomic working directory
Martin Geisler <mg@aragost.com>
parents: 15553
diff changeset
   215
    # don't use atomic writes in the working copy.
26823
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   216
    with open(path, 'rb') as srcfd:
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   217
        with wvfs(filename, 'wb') as destfd:
26823
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   218
            gothash = copyandhash(srcfd, destfd)
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   219
    if gothash != hash:
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   220
        repo.ui.warn(_('%s: data corruption in %s with hash %s\n')
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   221
                     % (filename, path, gothash))
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   222
        wvfs.unlink(filename)
26823
45e8bd2f36f0 largefiles: check hash of files in the store before copying to working dir
Mads Kiilerich <madski@unity3d.com>
parents: 26817
diff changeset
   223
        return False
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   224
    return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   225
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   226
def copytostore(repo, rev, file, uploaded=False):
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   227
    wvfs = repo.wvfs
17877
92bbb21d4b13 largefiles: respect the rev when reading standins in copytostore() (issue3630)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17794
diff changeset
   228
    hash = readstandin(repo, file, rev)
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   229
    if instore(repo, hash):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   230
        return
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   231
    if wvfs.exists(file):
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   232
        copytostoreabsolute(repo, wvfs.join(file), hash)
27903
512a814c5595 largefiles: fix commit of missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 26823
diff changeset
   233
    else:
512a814c5595 largefiles: fix commit of missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 26823
diff changeset
   234
        repo.ui.warn(_("%s: largefile %s not available from local store\n") %
512a814c5595 largefiles: fix commit of missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 26823
diff changeset
   235
                     (file, hash))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   236
15796
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   237
def copyalltostore(repo, node):
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   238
    '''Copy all largefiles in a given revision to the store'''
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   239
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   240
    ctx = repo[node]
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   241
    for filename in ctx.files():
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   242
        if isstandin(filename) and filename in ctx.manifest():
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   243
            realfile = splitstandin(filename)
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   244
            copytostore(repo, ctx.node(), realfile)
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   245
3e5b6045ccfc largefiles: factor out a copyalltostore() function
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 15794
diff changeset
   246
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   247
def copytostoreabsolute(repo, file, hash):
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   248
    if inusercache(repo.ui, hash):
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   249
        link(usercachepath(repo.ui, hash), storepath(repo, hash))
23276
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23274
diff changeset
   250
    else:
18998
d035c3902111 largefiles: refactoring - create destination dir in lfutil.link
Mads Kiilerich <madski@unity3d.com>
parents: 18980
diff changeset
   251
        util.makedirs(os.path.dirname(storepath(repo, hash)))
16153
05197f9fd1f3 largefiles: use repo.store.createmode for new files in .hg/largefiles
Martin Geisler <mg@aragost.com>
parents: 16103
diff changeset
   252
        dst = util.atomictempfile(storepath(repo, hash),
05197f9fd1f3 largefiles: use repo.store.createmode for new files in .hg/largefiles
Martin Geisler <mg@aragost.com>
parents: 16103
diff changeset
   253
                                  createmode=repo.store.createmode)
15699
84e55467093c largefiles: copy files in binary mode (issue3164)
Matt Mackall <mpm@selenic.com>
parents: 15658
diff changeset
   254
        for chunk in util.filechunkiter(open(file, 'rb')):
15571
809788118aa2 largefiles: write .hg/largefiles/ files atomically
Martin Geisler <mg@aragost.com>
parents: 15570
diff changeset
   255
            dst.write(chunk)
809788118aa2 largefiles: write .hg/largefiles/ files atomically
Martin Geisler <mg@aragost.com>
parents: 15570
diff changeset
   256
        dst.close()
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   257
        linktousercache(repo, hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   258
15316
c65f5b6e26d4 largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15304
diff changeset
   259
def linktousercache(repo, hash):
15658
971c55ce03b8 largefiles: don't require a user cache (issue3088) (issue3155)
Kevin Gessner <kevin@fogcreek.com>
parents: 15572
diff changeset
   260
    path = usercachepath(repo.ui, hash)
28575
78e4e558fa74 largefiles: drop partial support for not having a user cache
Mads Kiilerich <madski@unity3d.com>
parents: 28574
diff changeset
   261
    link(storepath(repo, hash), path)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   262
25292
31d543cd7062 largefiles: pass in whole matcher to getstandinmatcher()
Martin von Zweigbergk <martinvonz@google.com>
parents: 25291
diff changeset
   263
def getstandinmatcher(repo, rmatcher=None):
31d543cd7062 largefiles: pass in whole matcher to getstandinmatcher()
Martin von Zweigbergk <martinvonz@google.com>
parents: 25291
diff changeset
   264
    '''Return a match object that applies rmatcher to the standin directory'''
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   265
    wvfs = repo.wvfs
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   266
    standindir = shortname
25470
378a8e700e02 largefiles: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25293
diff changeset
   267
378a8e700e02 largefiles: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25293
diff changeset
   268
    # no warnings about missing files or directories
378a8e700e02 largefiles: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25293
diff changeset
   269
    badfn = lambda f, msg: None
378a8e700e02 largefiles: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25293
diff changeset
   270
25293
ab618e52788a largefiles: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25292
diff changeset
   271
    if rmatcher and not rmatcher.always():
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   272
        pats = [wvfs.join(standindir, pat) for pat in rmatcher.files()]
26025
ba8089433090 largefiles: ensure lfutil.getstandinmatcher() only matches standins
Matt Harbison <matt_harbison@yahoo.com>
parents: 25470
diff changeset
   273
        if not pats:
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   274
            pats = [wvfs.join(standindir)]
25470
378a8e700e02 largefiles: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25293
diff changeset
   275
        match = scmutil.match(repo[None], pats, badfn=badfn)
25293
ab618e52788a largefiles: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25292
diff changeset
   276
        # if pats is empty, it would incorrectly always match, so clear _always
ab618e52788a largefiles: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25292
diff changeset
   277
        match._always = False
18724
894a5897a9dd largefiles: getstandinmatcher should not depend on existence of directories
Mads Kiilerich <madski@unity3d.com>
parents: 18490
diff changeset
   278
    else:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   279
        # no patterns: relative to repo root
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   280
        match = scmutil.match(repo[None], [wvfs.join(standindir)], badfn=badfn)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   281
    return match
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   282
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   283
def composestandinmatcher(repo, rmatcher):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   284
    '''Return a matcher that accepts standins corresponding to the
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   285
    files accepted by rmatcher. Pass the list of files in the matcher
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   286
    as the paths specified by the user.'''
25292
31d543cd7062 largefiles: pass in whole matcher to getstandinmatcher()
Martin von Zweigbergk <martinvonz@google.com>
parents: 25291
diff changeset
   287
    smatcher = getstandinmatcher(repo, rmatcher)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   288
    isstandin = smatcher.matchfn
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   289
    def composedmatchfn(f):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   290
        return isstandin(f) and rmatcher.matchfn(splitstandin(f))
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16245
diff changeset
   291
    smatcher.matchfn = composedmatchfn
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   292
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   293
    return smatcher
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   294
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   295
def standin(filename):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   296
    '''Return the repo-relative path to the standin for the specified big
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   297
    file.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   298
    # Notes:
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 17270
diff changeset
   299
    # 1) Some callers want an absolute path, but for instance addlargefiles
18154
93c697d9c158 largefiles: remove trivial portability wrappers
Mads Kiilerich <madski@unity3d.com>
parents: 18153
diff changeset
   300
    #    needs it repo-relative so it can be passed to repo[None].add().  So
93c697d9c158 largefiles: remove trivial portability wrappers
Mads Kiilerich <madski@unity3d.com>
parents: 18153
diff changeset
   301
    #    leave it up to the caller to use repo.wjoin() to get an absolute path.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   302
    # 2) Join with '/' because that's what dirstate always uses, even on
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   303
    #    Windows. Change existing separator to '/' first in case we are
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   304
    #    passed filenames from an external source (like the command line).
18151
90ad387d9245 largefiles: use constant for '.hglf/'
Mads Kiilerich <madski@unity3d.com>
parents: 18150
diff changeset
   305
    return shortnameslash + util.pconvert(filename)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   306
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   307
def isstandin(filename):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   308
    '''Return true if filename is a big file standin. filename must be
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   309
    in Mercurial's internal form (slash-separated).'''
18151
90ad387d9245 largefiles: use constant for '.hglf/'
Mads Kiilerich <madski@unity3d.com>
parents: 18150
diff changeset
   310
    return filename.startswith(shortnameslash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   311
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   312
def splitstandin(filename):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   313
    # Split on / because that's what dirstate always uses, even on Windows.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   314
    # Change local separator to / first just in case we are passed filenames
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   315
    # from an external source (like the command line).
16066
6a42846cf769 i18n: use util.pconvert() instead of 'str.replace()' for problematic encoding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15915
diff changeset
   316
    bits = util.pconvert(filename).split('/', 1)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   317
    if len(bits) == 2 and bits[0] == shortname:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   318
        return bits[1]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   319
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   320
        return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   321
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   322
def updatestandin(repo, standin):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   323
    file = repo.wjoin(splitstandin(standin))
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   324
    if repo.wvfs.exists(splitstandin(standin)):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   325
        hash = hashfile(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   326
        executable = getexecutable(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   327
        writestandin(repo, standin, hash, executable)
27947
571ba161f6be largefiles: prevent committing a missing largefile
Matt Harbison <matt_harbison@yahoo.com>
parents: 27942
diff changeset
   328
    else:
571ba161f6be largefiles: prevent committing a missing largefile
Matt Harbison <matt_harbison@yahoo.com>
parents: 27942
diff changeset
   329
        raise error.Abort(_('%s: file not found!') % splitstandin(standin))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   330
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   331
def readstandin(repo, filename, node=None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   332
    '''read hex hash from standin for filename at given node, or working
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   333
    directory if no node is given'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   334
    return repo[node][standin(filename)].data().strip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   335
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   336
def writestandin(repo, standin, hash, executable):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   337
    '''write hash to <repo.root>/<standin>'''
19089
0509ae083ec1 largefiles: use repo.wwrite for writing standins (issue3909)
Mads Kiilerich <madski@unity3d.com>
parents: 19010
diff changeset
   338
    repo.wwrite(standin, hash + '\n', executable and 'x' or '')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   339
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   340
def copyandhash(instream, outfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   341
    '''Read bytes from instream (iterable) and write them to outfile,
19002
5083baa6cbf8 largefiles: remove blecch from lfutil.copyandhash - don't close the passed fd
Mads Kiilerich <madski@unity3d.com>
parents: 19001
diff changeset
   342
    computing the SHA-1 hash of the data along the way. Return the hash.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   343
    hasher = util.sha1('')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   344
    for data in instream:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   345
        hasher.update(data)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   346
        outfile.write(data)
18999
c1b5f9c4d989 largefiles: refactoring - return hex from _getfile and copyandhash
Mads Kiilerich <madski@unity3d.com>
parents: 18998
diff changeset
   347
    return hasher.hexdigest()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   348
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   349
def hashrepofile(repo, file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   350
    return hashfile(repo.wjoin(file))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   351
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   352
def hashfile(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   353
    if not os.path.exists(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   354
        return ''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   355
    hasher = util.sha1('')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   356
    fd = open(file, 'rb')
19001
2a35296a6304 largefiles: drop lfutil.blockstream - use filechunkiter like everybody else
Mads Kiilerich <madski@unity3d.com>
parents: 18999
diff changeset
   357
    for data in util.filechunkiter(fd, 128 * 1024):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   358
        hasher.update(data)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   359
    fd.close()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   360
    return hasher.hexdigest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   361
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   362
def getexecutable(filename):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   363
    mode = os.stat(filename).st_mode
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   364
    return ((mode & stat.S_IXUSR) and
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   365
            (mode & stat.S_IXGRP) and
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   366
            (mode & stat.S_IXOTH))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   367
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   368
def urljoin(first, second, *arg):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   369
    def join(left, right):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   370
        if not left.endswith('/'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   371
            left += '/'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   372
        if right.startswith('/'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   373
            right = right[1:]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   374
        return left + right
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   375
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   376
    url = join(first, second)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   377
    for a in arg:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   378
        url = join(url, a)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   379
    return url
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   380
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   381
def hexsha1(data):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   382
    """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   383
    object data"""
15347
799e56609ef6 largefiles: use util.sha1() instead of hashlib.sha1() everywhere
Thomas Arendsen Hein <thomas@intevation.de>
parents: 15333
diff changeset
   384
    h = util.sha1()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   385
    for chunk in util.filechunkiter(data):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   386
        h.update(chunk)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   387
    return h.hexdigest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   388
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   389
def httpsendfile(ui, filename):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15206
diff changeset
   390
    return httpconnection.httpsendfile(ui, filename, 'rb')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   391
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   392
def unixpath(path):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
   393
    '''Return a version of path normalized for use with the lfdirstate.'''
16066
6a42846cf769 i18n: use util.pconvert() instead of 'str.replace()' for problematic encoding
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15915
diff changeset
   394
    return util.pconvert(os.path.normpath(path))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   395
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   396
def islfilesrepo(repo):
17659
ae57920ac188 largefiles: enable islfilesrepo() prior to a commit (issue3541)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17270
diff changeset
   397
    if ('largefiles' in repo.requirements and
25149
3f0744eeaeaf cleanup: use __builtins__.any instead of util.any
Augie Fackler <augie@google.com>
parents: 24631
diff changeset
   398
            any(shortnameslash in f[0] for f in repo.store.datafiles())):
17659
ae57920ac188 largefiles: enable islfilesrepo() prior to a commit (issue3541)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17270
diff changeset
   399
        return True
ae57920ac188 largefiles: enable islfilesrepo() prior to a commit (issue3541)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17270
diff changeset
   400
25149
3f0744eeaeaf cleanup: use __builtins__.any instead of util.any
Augie Fackler <augie@google.com>
parents: 24631
diff changeset
   401
    return any(openlfdirstate(repo.ui, repo, False))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   402
15333
f37b71fec602 largefiles: py2.4 doesn't have BaseException
Matt Mackall <mpm@selenic.com>
parents: 15320
diff changeset
   403
class storeprotonotcapable(Exception):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   404
    def __init__(self, storetypes):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   405
        self.storetypes = storetypes
16103
3e1efb458e8b largefiles: only cache largefiles in new heads
Na'Tosha Bard <natosha@unity3d.com>
parents: 16066
diff changeset
   406
16120
47ee41fcf42b largefiles: optimize update speed by only updating changed largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 16103
diff changeset
   407
def getstandinsstate(repo):
47ee41fcf42b largefiles: optimize update speed by only updating changed largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 16103
diff changeset
   408
    standins = []
47ee41fcf42b largefiles: optimize update speed by only updating changed largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 16103
diff changeset
   409
    matcher = getstandinmatcher(repo)
18154
93c697d9c158 largefiles: remove trivial portability wrappers
Mads Kiilerich <madski@unity3d.com>
parents: 18153
diff changeset
   410
    for standin in repo.dirstate.walk(matcher, [], False, False):
16120
47ee41fcf42b largefiles: optimize update speed by only updating changed largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 16103
diff changeset
   411
        lfile = splitstandin(standin)
18300
745bc16ccef2 largefiles: fix update from a merge with removed files
Mads Kiilerich <madski@unity3d.com>
parents: 18299
diff changeset
   412
        try:
745bc16ccef2 largefiles: fix update from a merge with removed files
Mads Kiilerich <madski@unity3d.com>
parents: 18299
diff changeset
   413
            hash = readstandin(repo, lfile)
745bc16ccef2 largefiles: fix update from a merge with removed files
Mads Kiilerich <madski@unity3d.com>
parents: 18299
diff changeset
   414
        except IOError:
745bc16ccef2 largefiles: fix update from a merge with removed files
Mads Kiilerich <madski@unity3d.com>
parents: 18299
diff changeset
   415
            hash = None
745bc16ccef2 largefiles: fix update from a merge with removed files
Mads Kiilerich <madski@unity3d.com>
parents: 18299
diff changeset
   416
        standins.append((lfile, hash))
16120
47ee41fcf42b largefiles: optimize update speed by only updating changed largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 16103
diff changeset
   417
    return standins
16245
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   418
22095
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   419
def synclfdirstate(repo, lfdirstate, lfile, normallookup):
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   420
    lfstandin = standin(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   421
    if lfstandin in repo.dirstate:
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   422
        stat = repo.dirstate._map[lfstandin]
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   423
        state, mtime = stat[0], stat[3]
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   424
    else:
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   425
        state, mtime = '?', -1
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   426
    if state == 'n':
26627
832c98d79587 largefiles: better handling of merge of largefiles that not are available
Mads Kiilerich <madski@unity3d.com>
parents: 26587
diff changeset
   427
        if (normallookup or mtime < 0 or
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   428
            not repo.wvfs.exists(lfile)):
22095
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   429
            # state 'n' doesn't ensure 'clean' in this case
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   430
            lfdirstate.normallookup(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   431
        else:
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   432
            lfdirstate.normal(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   433
    elif state == 'm':
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   434
        lfdirstate.normallookup(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   435
    elif state == 'r':
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   436
        lfdirstate.remove(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   437
    elif state == 'a':
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   438
        lfdirstate.add(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   439
    elif state == '?':
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   440
        lfdirstate.drop(lfile)
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21917
diff changeset
   441
23184
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   442
def markcommitted(orig, ctx, node):
24336
c9f4ef967a1d largefiles: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24158
diff changeset
   443
    repo = ctx.repo()
23184
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   444
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   445
    orig(node)
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   446
23273
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   447
    # ATTENTION: "ctx.files()" may differ from "repo[node].files()"
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   448
    # because files coming from the 2nd parent are omitted in the latter.
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   449
    #
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   450
    # The former should be used to get targets of "synclfdirstate",
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   451
    # because such files:
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   452
    # - are marked as "a" by "patch.patch()" (e.g. via transplant), and
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   453
    # - have to be marked as "n" after commit, but
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   454
    # - aren't listed in "repo[node].files()"
236c978bceca largefiles: avoid redundant "updatelfiles" invocation in "overridetransplant"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23188
diff changeset
   455
23184
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   456
    lfdirstate = openlfdirstate(repo.ui, repo)
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   457
    for f in ctx.files():
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   458
        if isstandin(f):
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   459
            lfile = splitstandin(f)
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   460
            synclfdirstate(repo, lfdirstate, lfile, False)
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   461
    lfdirstate.write()
3100d1cbce32 largefiles: factor out procedures to update lfdirstate for post-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23039
diff changeset
   462
23276
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23274
diff changeset
   463
    # As part of committing, copy all of the largefiles into the cache.
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23274
diff changeset
   464
    copyalltostore(repo, node)
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23274
diff changeset
   465
16245
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   466
def getlfilestoupdate(oldstandins, newstandins):
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   467
    changedstandins = set(oldstandins).symmetric_difference(set(newstandins))
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   468
    filelist = []
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   469
    for f in changedstandins:
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   470
        if f[0] not in filelist:
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   471
            filelist.append(f[0])
a18ad914aa21 largefiles: move calculation of largefiles for updating to utility function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16166
diff changeset
   472
    return filelist
21042
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   473
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   474
def getlfilestoupload(repo, missing, addfunc):
23892
f2b6f37d537b largefiles: show progress when checking standin hashes in outgoing changesets
Mads Kiilerich <madski@unity3d.com>
parents: 23657
diff changeset
   475
    for i, n in enumerate(missing):
f2b6f37d537b largefiles: show progress when checking standin hashes in outgoing changesets
Mads Kiilerich <madski@unity3d.com>
parents: 23657
diff changeset
   476
        repo.ui.progress(_('finding outgoing largefiles'), i,
28464
6e34690230c0 largefiles: use revisions as a ui.progress unit
Anton Shestakov <av6@dwimlabs.net>
parents: 27947
diff changeset
   477
            unit=_('revisions'), total=len(missing))
21042
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   478
        parents = [p for p in repo.changelog.parents(n) if p != node.nullid]
23657
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   479
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   480
        oldlfstatus = repo.lfstatus
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   481
        repo.lfstatus = False
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   482
        try:
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   483
            ctx = repo[n]
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   484
        finally:
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   485
            repo.lfstatus = oldlfstatus
95f238cafb32 largefiles: ensure that the standin files are available in getlfilestoupload()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23543
diff changeset
   486
21042
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   487
        files = set(ctx.files())
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   488
        if len(parents) == 2:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   489
            mc = ctx.manifest()
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   490
            mp1 = ctx.parents()[0].manifest()
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   491
            mp2 = ctx.parents()[1].manifest()
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   492
            for f in mp1:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   493
                if f not in mc:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   494
                    files.add(f)
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   495
            for f in mp2:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   496
                if f not in mc:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   497
                    files.add(f)
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   498
            for f in mc:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   499
                if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   500
                    files.add(f)
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   501
        for fn in files:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   502
            if isstandin(fn) and fn in ctx:
32b3331f18eb largefiles: centralize the logic to get outgoing largefiles
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19089
diff changeset
   503
                addfunc(fn, ctx[fn].data().strip())
23892
f2b6f37d537b largefiles: show progress when checking standin hashes in outgoing changesets
Mads Kiilerich <madski@unity3d.com>
parents: 23657
diff changeset
   504
    repo.ui.progress(_('finding outgoing largefiles'), None)
23185
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   505
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   506
def updatestandinsbymatch(repo, match):
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   507
    '''Update standins in the working directory according to specified match
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   508
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   509
    This returns (possibly modified) ``match`` object to be used for
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   510
    subsequent commit process.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   511
    '''
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   512
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   513
    ui = repo.ui
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   514
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   515
    # Case 1: user calls commit with no specific files or
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   516
    # include/exclude patterns: refresh and commit all files that
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   517
    # are "dirty".
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   518
    if match is None or match.always():
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   519
        # Spend a bit of time here to get a list of files we know
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   520
        # are modified so we can compare only against those.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   521
        # It can cost a lot of time (several seconds)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   522
        # otherwise to update all standins if the largefiles are
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   523
        # large.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   524
        lfdirstate = openlfdirstate(ui, repo)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   525
        dirtymatch = match_.always(repo.root, repo.getcwd())
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   526
        unsure, s = lfdirstate.status(dirtymatch, [], False, False,
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   527
                                      False)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   528
        modifiedfiles = unsure + s.modified + s.added + s.removed
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   529
        lfiles = listlfiles(repo)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   530
        # this only loops through largefiles that exist (not
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   531
        # removed/renamed)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   532
        for lfile in lfiles:
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   533
            if lfile in modifiedfiles:
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   534
                if repo.wvfs.exists(standin(lfile)):
23185
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   535
                    # this handles the case where a rebase is being
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   536
                    # performed and the working copy is not updated
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   537
                    # yet.
28560
bfbd3f02b442 largefiles: replace invocation of os.path module by vfs in lfutil.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   538
                    if repo.wvfs.exists(lfile):
23185
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   539
                        updatestandin(repo,
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   540
                            standin(lfile))
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   541
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   542
        return match
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   543
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   544
    lfiles = listlfiles(repo)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   545
    match._files = repo._subdirlfs(match.files(), lfiles)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   546
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   547
    # Case 2: user calls commit with specified patterns: refresh
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   548
    # any matching big files.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   549
    smatcher = composestandinmatcher(repo, match)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   550
    standins = repo.dirstate.walk(smatcher, [], False, False)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   551
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   552
    # No matching big files: get out of the way and pass control to
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   553
    # the usual commit() method.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   554
    if not standins:
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   555
        return match
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   556
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   557
    # Refresh all matching big files.  It's possible that the
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   558
    # commit will end up failing, in which case the big files will
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   559
    # stay refreshed.  No harm done: the user modified them and
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   560
    # asked to commit them, so sooner or later we're going to
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   561
    # refresh the standins.  Might as well leave them refreshed.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   562
    lfdirstate = openlfdirstate(ui, repo)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   563
    for fstandin in standins:
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   564
        lfile = splitstandin(fstandin)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   565
        if lfdirstate[lfile] != 'r':
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   566
            updatestandin(repo, fstandin)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   567
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   568
    # Cook up a new matcher that only matches regular files or
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   569
    # standins corresponding to the big files requested by the
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   570
    # user.  Have to modify _files to prevent commit() from
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   571
    # complaining "not tracked" for big files.
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   572
    match = copy.copy(match)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   573
    origmatchfn = match.matchfn
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   574
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   575
    # Check both the list of largefiles and the list of
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   576
    # standins because if a largefile was removed, it
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   577
    # won't be in the list of largefiles at this point
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   578
    match._files += sorted(standins)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   579
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   580
    actualfiles = []
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   581
    for f in match._files:
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   582
        fstandin = standin(f)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   583
26817
b68797f244e4 largefiles: fix explicit commit of normal/largefile switch
Mads Kiilerich <madski@unity3d.com>
parents: 26749
diff changeset
   584
        # For largefiles, only one of the normal and standin should be
27942
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   585
        # committed (except if one of them is a remove).  In the case of a
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   586
        # standin removal, drop the normal file if it is unknown to dirstate.
26817
b68797f244e4 largefiles: fix explicit commit of normal/largefile switch
Mads Kiilerich <madski@unity3d.com>
parents: 26749
diff changeset
   587
        # Thus, skip plain largefile names but keep the standin.
27942
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   588
        if f in lfiles or fstandin in standins:
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   589
            if repo.dirstate[fstandin] != 'r':
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   590
                if repo.dirstate[f] != 'r':
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   591
                    continue
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   592
            elif repo.dirstate[f] == '?':
eb1135d5e688 largefiles: fix an explicit largefile commit after a remove (issue4969)
Matt Harbison <matt_harbison@yahoo.com>
parents: 27903
diff changeset
   593
                continue
23185
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   594
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   595
        actualfiles.append(f)
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   596
    match._files = actualfiles
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   597
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   598
    def matchfn(f):
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   599
        if origmatchfn(f):
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   600
            return f not in lfiles
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   601
        else:
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   602
            return f in standins
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   603
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   604
    match.matchfn = matchfn
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   605
9870173e0b48 largefiles: factor out procedures to update standins for pre-committing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23184
diff changeset
   606
    return match
23187
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   607
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   608
class automatedcommithook(object):
23543
4dd8a6a1240d spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23276
diff changeset
   609
    '''Stateful hook to update standins at the 1st commit of resuming
23187
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   610
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   611
    For efficiency, updating standins in the working directory should
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   612
    be avoided while automated committing (like rebase, transplant and
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   613
    so on), because they should be updated before committing.
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   614
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   615
    But the 1st commit of resuming automated committing (e.g. ``rebase
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   616
    --continue``) should update them, because largefiles may be
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   617
    modified manually.
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   618
    '''
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   619
    def __init__(self, resuming):
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   620
        self.resuming = resuming
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   621
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   622
    def __call__(self, repo, match):
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   623
        if self.resuming:
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   624
            self.resuming = False # avoids updating at subsequent commits
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   625
            return updatestandinsbymatch(repo, match)
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   626
        else:
f726b05ecfe6 largefiles: update standins only at the 1st commit of "hg rebase --continue"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23185
diff changeset
   627
            return match
23188
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   628
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   629
def getstatuswriter(ui, repo, forcibly=None):
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   630
    '''Return the function to write largefiles specific status out
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   631
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   632
    If ``forcibly`` is ``None``, this returns the last element of
23543
4dd8a6a1240d spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23276
diff changeset
   633
    ``repo._lfstatuswriters`` as "default" writer function.
23188
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   634
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   635
    Otherwise, this returns the function to always write out (or
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   636
    ignore if ``not forcibly``) status.
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   637
    '''
24158
d414c28db84d largefiles: access to specific fields only if largefiles enabled (issue4547)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23892
diff changeset
   638
    if forcibly is None and util.safehasattr(repo, '_largefilesenabled'):
23188
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   639
        return repo._lfstatuswriters[-1]
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   640
    else:
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   641
        if forcibly:
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   642
            return ui.status # forcibly WRITE OUT
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   643
        else:
94ac64bcf6fe largefiles: introduce "_lfstatuswriters" to customize status reporting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23187
diff changeset
   644
            return lambda *msg, **opts: None # forcibly IGNORE