hgext/largefiles/overrides.py
author Greg Ward <greg@gerg.ca>
Tue, 11 Oct 2011 21:11:01 -0400
changeset 15227 a7686abf73a6
parent 15224 7c604d8c7e83
child 15229 89e19ca2a90e
permissions -rw-r--r--
largefiles: factor out lfutil.getminsize()
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
'''Overridden Mercurial commands and functions for the largefiles extension'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
import os
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    12
import copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    14
from mercurial import hg, commands, util, cmdutil, match as match_, node, \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    15
        archival, error, merge
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    17
from mercurial.node import hex
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    18
from hgext import rebase
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    19
import lfutil
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    20
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    21
try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    22
    from mercurial import scmutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    23
except ImportError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    24
    pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    25
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    26
import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    27
import lfcommands
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    28
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    29
def installnormalfilesmatchfn(manifest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    30
    '''overrides scmutil.match so that the matcher it returns will ignore all
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    31
    largefiles'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    32
    oldmatch = None # for the closure
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    33
    def override_match(repo, pats=[], opts={}, globbed=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    34
            default='relpath'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    35
        match = oldmatch(repo, pats, opts, globbed, default)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    36
        m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    37
        notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    38
                manifest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    39
        m._files = filter(notlfile, m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    40
        m._fmap = set(m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    41
        orig_matchfn = m.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    42
        m.matchfn = lambda f: notlfile(f) and orig_matchfn(f) or None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    43
        return m
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    44
    oldmatch = installmatchfn(override_match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    45
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    46
def installmatchfn(f):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
    47
    oldmatch = scmutil.match
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    48
    setattr(f, 'oldmatch', oldmatch)
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
    49
    scmutil.match = f
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    50
    return oldmatch
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    51
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    52
def restorematchfn():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    53
    '''restores scmutil.match to what it was before installnormalfilesmatchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    54
    was called.  no-op if scmutil.match is its original function.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    55
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    56
    Note that n calls to installnormalfilesmatchfn will require n calls to
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    57
    restore matchfn to reverse'''
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
    58
    scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    59
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    60
# -- Wrappers: modify existing commands --------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    61
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    62
# Add works by going through the files that the user wanted to add
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    63
# and checking if they should be added as lfiles. Then making a new
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    64
# matcher which matches only the normal files and running the original
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    65
# version of add.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    66
def override_add(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    67
    large = opts.pop('large', None)
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    68
    lfsize = lfutil.getminsize(
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    69
        ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    70
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    71
    lfmatcher = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    72
    if os.path.exists(repo.wjoin(lfutil.shortname)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    73
        lfpats = ui.config(lfutil.longname, 'patterns', default=())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    74
        if lfpats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    75
            lfpats = lfpats.split(' ')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    76
            lfmatcher = match_.match(repo.root, '', list(lfpats))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    77
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    78
    lfnames = []
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
    79
    m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    80
    m.bad = lambda x, y: None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    81
    wctx = repo[None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    82
    for f in repo.walk(m):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
        exact = m.exact(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    84
        lfile = lfutil.standin(f) in wctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    85
        nfile = f in wctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    86
        exists = lfile or nfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    87
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    88
        # Don't warn the user when they attempt to add a normal tracked file.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    89
        # The normal add code will do that for us.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    90
        if exact and exists:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    91
            if lfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    92
                ui.warn(_('%s already a largefile\n') % f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    93
            continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    94
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    95
        if exact or not exists:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    96
            if large or (lfsize and os.path.getsize(repo.wjoin(f)) >= \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    97
                    lfsize * 1024 * 1024) or (lfmatcher and lfmatcher(f)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    98
                lfnames.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
                if ui.verbose or not exact:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   100
                    ui.status(_('adding %s as a largefile\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   102
    bad = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   103
    standins = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   104
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
    # Need to lock otherwise there could be a race condition inbetween when
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   106
    # standins are created and added to the repo
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
        if not opts.get('dry_run'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   110
            lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
            for f in lfnames:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
                standinname = lfutil.standin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   113
                lfutil.writestandin(repo, standinname, hash='',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   114
                    executable=lfutil.getexecutable(repo.wjoin(f)))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   115
                standins.append(standinname)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   116
                if lfdirstate[f] == 'r':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   117
                    lfdirstate.normallookup(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   118
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   119
                    lfdirstate.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   120
            lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   121
            bad += [lfutil.splitstandin(f) for f in lfutil.repo_add(repo,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   122
                standins) if f in m.files()]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   123
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   124
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   125
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   126
    installnormalfilesmatchfn(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   127
    result = orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   128
    restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   129
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   130
    return (result == 1 or bad) and 1 or 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   131
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   132
def override_remove(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   133
    manifest = repo[None].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   134
    installnormalfilesmatchfn(manifest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   135
    orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   136
    restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   137
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   138
    after, force = opts.get('after'), opts.get('force')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   139
    if not pats and not after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   140
        raise util.Abort(_('no files specified'))
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   141
    m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   142
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   143
        repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   144
        s = repo.status(match=m, clean=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   145
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   146
        repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   147
    modified, added, deleted, clean = [[f for f in list if lfutil.standin(f) \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   148
        in manifest] for list in [s[0], s[1], s[3], s[6]]]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   149
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   150
    def warn(files, reason):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   151
        for f in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   152
            ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   153
                    % (m.rel(f), reason))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   154
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   155
    if force:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   156
        remove, forget = modified + deleted + clean, added
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   157
    elif after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   158
        remove, forget = deleted, []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   159
        warn(modified + added + clean, _('still exists'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   160
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   161
        remove, forget = deleted + clean, []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   162
        warn(modified, _('is modified'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   163
        warn(added, _('has been marked for add'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   164
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   165
    for f in sorted(remove + forget):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   166
        if ui.verbose or not m.exact(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   167
            ui.status(_('removing %s\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   169
    # Need to lock because standin files are deleted then removed from the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   170
    # repository and we could race inbetween.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   171
    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   172
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   173
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   174
        for f in remove:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   175
            if not after:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   176
                os.unlink(repo.wjoin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   177
                currentdir = os.path.split(f)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   178
                while currentdir and not os.listdir(repo.wjoin(currentdir)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   179
                    os.rmdir(repo.wjoin(currentdir))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   180
                    currentdir = os.path.split(currentdir)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   181
            lfdirstate.remove(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   182
        lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   183
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   184
        forget = [lfutil.standin(f) for f in forget]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   185
        remove = [lfutil.standin(f) for f in remove]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   186
        lfutil.repo_forget(repo, forget)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   187
        lfutil.repo_remove(repo, remove, unlink=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   188
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   189
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   190
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   191
def override_status(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   192
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   193
        repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   194
        return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   195
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   196
        repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   197
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   198
def override_log(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   199
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   200
        repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   201
        orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   202
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   203
        repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   204
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   205
def override_verify(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   206
    large = opts.pop('large', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   207
    all = opts.pop('lfa', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   208
    contents = opts.pop('lfc', False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   209
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   210
    result = orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   211
    if large:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   212
        result = result or lfcommands.verifylfiles(ui, repo, all, contents)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   213
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   214
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   215
# Override needs to refresh standins so that update's normal merge
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   216
# will go through properly. Then the other update hook (overriding repo.update)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   217
# will get the new files. Filemerge is also overriden so that the merge
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   218
# will merge standins correctly.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   219
def override_update(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   220
    lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   221
    s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   222
        False, False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   223
    (unsure, modified, added, removed, missing, unknown, ignored, clean) = s
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   224
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   225
    # Need to lock between the standins getting updated and their lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   226
    # getting updated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   227
    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   228
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   229
        if opts['check']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   230
            mod = len(modified) > 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   231
            for lfile in unsure:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   232
                standin = lfutil.standin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   233
                if repo['.'][standin].data().strip() != \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   234
                        lfutil.hashfile(repo.wjoin(lfile)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   235
                    mod = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   236
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   237
                    lfdirstate.normal(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   238
            lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   239
            if mod:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   240
                raise util.Abort(_('uncommitted local changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   241
        # XXX handle removed differently
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   242
        if not opts['clean']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   243
            for lfile in unsure + modified + added:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   244
                lfutil.updatestandin(repo, lfutil.standin(lfile))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   245
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   246
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   247
    return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   248
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   249
# Override filemerge to prompt the user about how they wish to merge lfiles.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   250
# This will handle identical edits, and copy/rename + edit without prompting
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   251
# the user.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   252
def override_filemerge(origfn, repo, mynode, orig, fcd, fco, fca):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   253
    # Use better variable names here. Because this is a wrapper we cannot
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   254
    # change the variable names in the function declaration.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   255
    fcdest, fcother, fcancestor = fcd, fco, fca
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   256
    if not lfutil.isstandin(orig):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   257
        return origfn(repo, mynode, orig, fcdest, fcother, fcancestor)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   258
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   259
        if not fcother.cmp(fcdest): # files identical?
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   260
            return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   261
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   262
        # backwards, use working dir parent as ancestor
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   263
        if fcancestor == fcother:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   264
            fcancestor = fcdest.parents()[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   265
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   266
        if orig != fcother.path():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   267
            repo.ui.status(_('merging %s and %s to %s\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   268
                           % (lfutil.splitstandin(orig),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   269
                              lfutil.splitstandin(fcother.path()),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   270
                              lfutil.splitstandin(fcdest.path())))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   271
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   272
            repo.ui.status(_('merging %s\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   273
                           % lfutil.splitstandin(fcdest.path()))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   274
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   275
        if fcancestor.path() != fcother.path() and fcother.data() == \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   276
                fcancestor.data():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   277
            return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   278
        if fcancestor.path() != fcdest.path() and fcdest.data() == \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   279
                fcancestor.data():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   280
            repo.wwrite(fcdest.path(), fcother.data(), fcother.flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   281
            return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   282
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   283
        if repo.ui.promptchoice(_('largefile %s has a merge conflict\n'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   284
                             'keep (l)ocal or take (o)ther?') %
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   285
                             lfutil.splitstandin(orig),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   286
                             (_('&Local'), _('&Other')), 0) == 0:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   287
            return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   288
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   289
            repo.wwrite(fcdest.path(), fcother.data(), fcother.flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   290
            return 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   291
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   292
# Copy first changes the matchers to match standins instead of lfiles.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   293
# Then it overrides util.copyfile in that function it checks if the destination
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   294
# lfile already exists. It also keeps a list of copied files so that the lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   295
# can be copied and the dirstate updated.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   296
def override_copy(orig, ui, repo, pats, opts, rename=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   297
    # doesn't remove lfile on rename
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   298
    if len(pats) < 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   299
        # this isn't legal, let the original function deal with it
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   300
        return orig(ui, repo, pats, opts, rename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   301
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   302
    def makestandin(relpath):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   303
        path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   304
        return os.path.join(os.path.relpath('.', repo.getcwd()),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   305
            lfutil.standin(path))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   306
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   307
    fullpats = scmutil.expandpats(pats)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   308
    dest = fullpats[-1]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   309
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   310
    if os.path.isdir(dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   311
        if not os.path.isdir(makestandin(dest)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   312
            os.makedirs(makestandin(dest))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   313
    # This could copy both lfiles and normal files in one command, but we don't
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   314
    # want to do that first replace their matcher to only match normal files
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   315
    # and run it then replace it to just match lfiles and run it again
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   316
    nonormalfiles = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   317
    nolfiles = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   318
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   319
        installnormalfilesmatchfn(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   320
        result = orig(ui, repo, pats, opts, rename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   321
    except util.Abort, e:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   322
        if str(e) != 'no files to copy':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   323
            raise e
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   324
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   325
            nonormalfiles = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   326
        result = 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   327
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   328
        restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   329
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   330
    # The first rename can cause our current working directory to be removed.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   331
    # In that case there is nothing left to copy/rename so just quit.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   332
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   333
        repo.getcwd()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   334
    except OSError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   335
        return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   336
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   337
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   338
        # When we call orig below it creates the standins but we don't add them
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   339
        # to the dir state until later so lock during that time.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   340
        wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   341
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   342
        manifest = repo[None].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   343
        oldmatch = None # for the closure
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   344
        def override_match(repo, pats=[], opts={}, globbed=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   345
                default='relpath'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   346
            newpats = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   347
            # The patterns were previously mangled to add the standin
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   348
            # directory; we need to remove that now
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   349
            for pat in pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   350
                if match_.patkind(pat) is None and lfutil.shortname in pat:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   351
                    newpats.append(pat.replace(lfutil.shortname, ''))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   352
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   353
                    newpats.append(pat)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   354
            match = oldmatch(repo, newpats, opts, globbed, default)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   355
            m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   356
            lfile = lambda f: lfutil.standin(f) in manifest
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   357
            m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   358
            m._fmap = set(m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   359
            orig_matchfn = m.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   360
            m.matchfn = lambda f: lfutil.isstandin(f) and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   361
                lfile(lfutil.splitstandin(f)) and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   362
                orig_matchfn(lfutil.splitstandin(f)) or None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   363
            return m
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   364
        oldmatch = installmatchfn(override_match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   365
        listpats = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   366
        for pat in pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   367
            if match_.patkind(pat) is not None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   368
                listpats.append(pat)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   369
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   370
                listpats.append(makestandin(pat))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   371
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   372
        try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   373
            origcopyfile = util.copyfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   374
            copiedfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   375
            def override_copyfile(src, dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   376
                if lfutil.shortname in src and lfutil.shortname in dest:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   377
                    destlfile = dest.replace(lfutil.shortname, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   378
                    if not opts['force'] and os.path.exists(destlfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   379
                        raise IOError('',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   380
                            _('destination largefile already exists'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   381
                copiedfiles.append((src, dest))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   382
                origcopyfile(src, dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   383
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   384
            util.copyfile = override_copyfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   385
            result += orig(ui, repo, listpats, opts, rename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   386
        finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   387
            util.copyfile = origcopyfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   388
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   389
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   390
        for (src, dest) in copiedfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   391
            if lfutil.shortname in src and lfutil.shortname in dest:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   392
                srclfile = src.replace(lfutil.shortname, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   393
                destlfile = dest.replace(lfutil.shortname, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   394
                destlfiledir = os.path.dirname(destlfile) or '.'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   395
                if not os.path.isdir(destlfiledir):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   396
                    os.makedirs(destlfiledir)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   397
                if rename:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   398
                    os.rename(srclfile, destlfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   399
                    lfdirstate.remove(os.path.relpath(srclfile,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   400
                        repo.root))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   401
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   402
                    util.copyfile(srclfile, destlfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   403
                lfdirstate.add(os.path.relpath(destlfile,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   404
                    repo.root))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   405
        lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   406
    except util.Abort, e:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   407
        if str(e) != 'no files to copy':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   408
            raise e
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   409
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   410
            nolfiles = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   411
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   412
        restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   413
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   414
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   415
    if nolfiles and nonormalfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   416
        raise util.Abort(_('no files to copy'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   417
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   418
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   419
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   420
# When the user calls revert, we have to be careful to not revert any changes
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   421
# to other lfiles accidentally.  This means we have to keep track of the lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   422
# that are being reverted so we only pull down the necessary lfiles.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   423
#
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   424
# Standins are only updated (to match the hash of lfiles) before commits.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   425
# Update the standins then run the original revert (changing the matcher to hit
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   426
# standins instead of lfiles). Based on the resulting standins update the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   427
# lfiles. Then return the standins to their proper state
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   428
def override_revert(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   429
    # Because we put the standins in a bad state (by updating them) and then
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   430
    # return them to a correct state we need to lock to prevent others from
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   431
    # changing them in their incorrect state.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   432
    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   433
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   434
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   435
        (modified, added, removed, missing, unknown, ignored, clean) = \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   436
            lfutil.lfdirstate_status(lfdirstate, repo, repo['.'].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   437
        for lfile in modified:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   438
            lfutil.updatestandin(repo, lfutil.standin(lfile))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   439
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   440
        try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   441
            ctx = repo[opts.get('rev')]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   442
            oldmatch = None # for the closure
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   443
            def override_match(ctxorrepo, pats=[], opts={}, globbed=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   444
                    default='relpath'):
15169
aa262fff87ac largefile: fix up hasattr usage
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   445
                if util.safehasattr(ctxorrepo, 'match'):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   446
                    ctx0 = ctxorrepo
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   447
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   448
                    ctx0 = ctxorrepo[None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   449
                match = oldmatch(ctxorrepo, pats, opts, globbed, default)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   450
                m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   451
                def tostandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   452
                    if lfutil.standin(f) in ctx0 or lfutil.standin(f) in ctx:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   453
                        return lfutil.standin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   454
                    elif lfutil.standin(f) in repo[None]:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   455
                        return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   456
                    return f
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   457
                m._files = [tostandin(f) for f in m._files]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   458
                m._files = [f for f in m._files if f is not None]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   459
                m._fmap = set(m._files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   460
                orig_matchfn = m.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   461
                def matchfn(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   462
                    if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   463
                        # We need to keep track of what lfiles are being
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   464
                        # matched so we know which ones to update later
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   465
                        # (otherwise we revert changes to other lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   466
                        # accidentally).  This is repo specific, so duckpunch
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   467
                        # the repo object to keep the list of lfiles for us
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   468
                        # later.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   469
                        if orig_matchfn(lfutil.splitstandin(f)) and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   470
                                (f in repo[None] or f in ctx):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   471
                            lfileslist = getattr(repo, '_lfilestoupdate', [])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   472
                            lfileslist.append(lfutil.splitstandin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   473
                            repo._lfilestoupdate = lfileslist
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   474
                            return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   475
                        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   476
                            return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   477
                    return orig_matchfn(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   478
                m.matchfn = matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   479
                return m
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   480
            oldmatch = installmatchfn(override_match)
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   481
            scmutil.match
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   482
            matches = override_match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   483
            orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   484
        finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   485
            restorematchfn()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   486
        lfileslist = getattr(repo, '_lfilestoupdate', [])
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
   487
        lfcommands.updatelfiles(ui, repo, filelist=lfileslist,
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
   488
                                printmessage=False)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   489
        # Empty out the lfiles list so we start fresh next time
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   490
        repo._lfilestoupdate = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   491
        for lfile in modified:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   492
            if lfile in lfileslist:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   493
                if os.path.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   494
                        in repo['.']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   495
                    lfutil.writestandin(repo, lfutil.standin(lfile),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   496
                        repo['.'][lfile].data().strip(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   497
                        'x' in repo['.'][lfile].flags())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   498
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   499
        for lfile in added:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   500
            standin = lfutil.standin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   501
            if standin not in ctx and (standin in matches or opts.get('all')):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   502
                if lfile in lfdirstate:
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   503
                    lfdirstate.drop(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   504
                util.unlinkpath(repo.wjoin(standin))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   505
        lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   506
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   507
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   508
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   509
def hg_update(orig, repo, node):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   510
    result = orig(repo, node)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   511
    # XXX check if it worked first
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   512
    lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   513
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   514
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   515
def hg_clean(orig, repo, node, show_stats=True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   516
    result = orig(repo, node, show_stats)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   517
    lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   518
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   519
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   520
def hg_merge(orig, repo, node, force=None, remind=True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   521
    result = orig(repo, node, force, remind)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   522
    lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   523
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   524
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   525
# When we rebase a repository with remotely changed lfiles, we need
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   526
# to take some extra care so that the lfiles are correctly updated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   527
# in the working copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   528
def override_pull(orig, ui, repo, source=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   529
    if opts.get('rebase', False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   530
        repo._isrebasing = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   531
        try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   532
            if opts.get('update'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   533
                 del opts['update']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   534
                 ui.debug('--update and --rebase are not compatible, ignoring '
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   535
                          'the update flag\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   536
            del opts['rebase']
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   537
            cmdutil.bailifchanged(repo)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   538
            revsprepull = len(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   539
            origpostincoming = commands.postincoming
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   540
            def _dummy(*args, **kwargs):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   541
                pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   542
            commands.postincoming = _dummy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   543
            repo.lfpullsource = source
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   544
            if not source:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   545
                source = 'default'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   546
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   547
                result = commands.pull(ui, repo, source, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   548
            finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   549
                commands.postincoming = origpostincoming
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   550
            revspostpull = len(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   551
            if revspostpull > revsprepull:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   552
                result = result or rebase.rebase(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   553
        finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   554
            repo._isrebasing = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   555
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   556
        repo.lfpullsource = source
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   557
        if not source:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   558
            source = 'default'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   559
        result = orig(ui, repo, source, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   560
    return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   561
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   562
def override_rebase(orig, ui, repo, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   563
    repo._isrebasing = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   564
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   565
        orig(ui, repo, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   566
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   567
        repo._isrebasing = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   568
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   569
def override_archive(orig, repo, dest, node, kind, decode=True, matchfn=None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   570
            prefix=None, mtime=None, subrepos=None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   571
    # No need to lock because we are only reading history and lfile caches
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   572
    # neither of which are modified
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   573
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   574
    lfcommands.cachelfiles(repo.ui, repo, node)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   575
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   576
    if kind not in archival.archivers:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   577
        raise util.Abort(_("unknown archive type '%s'") % kind)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   578
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   579
    ctx = repo[node]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   580
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   581
    if kind == 'files':
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   582
        if prefix:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   583
            raise util.Abort(
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   584
                _('cannot give prefix when archiving to files'))
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   585
    else:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   586
        prefix = archival.tidyprefix(dest, kind, prefix)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   587
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   588
    def write(name, mode, islink, getdata):
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   589
        if matchfn and not matchfn(name):
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   590
            return
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   591
        data = getdata()
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   592
        if decode:
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   593
            data = repo.wwritedata(name, data)
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   594
        archiver.addfile(prefix + name, mode, islink, data)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   595
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   596
    archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   597
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   598
    if repo.ui.configbool("ui", "archivemeta", True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   599
        def metadata():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   600
            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   601
                hex(repo.changelog.node(0)), hex(node), ctx.branch())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   602
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   603
            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   604
                           if repo.tagtype(t) == 'global')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   605
            if not tags:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   606
                repo.ui.pushbuffer()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   607
                opts = {'template': '{latesttag}\n{latesttagdistance}',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   608
                        'style': '', 'patch': None, 'git': None}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   609
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   610
                ltags, dist = repo.ui.popbuffer().split('\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   611
                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   612
                tags += 'latesttagdistance: %s\n' % dist
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   613
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   614
            return base + tags
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   615
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   616
        write('.hg_archival.txt', 0644, False, metadata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   617
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   618
    for f in ctx:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   619
        ff = ctx.flags(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   620
        getdata = ctx[f].data
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   621
        if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   622
            path = lfutil.findfile(repo, getdata().strip())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   623
            f = lfutil.splitstandin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   624
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   625
            def getdatafn():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   626
                try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   627
                    fd = open(path, 'rb')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   628
                    return fd.read()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   629
                finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   630
                    fd.close()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   631
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   632
            getdata = getdatafn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   633
        write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   634
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   635
    if subrepos:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   636
        for subpath in ctx.substate:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   637
            sub = ctx.sub(subpath)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   638
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   639
                sub.archive(repo.ui, archiver, prefix)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   640
            except TypeError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   641
                sub.archive(archiver, prefix)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   642
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   643
    archiver.done()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   644
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   645
# If a lfile is modified the change is not reflected in its standin until a
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   646
# commit.  cmdutil.bailifchanged raises an exception if the repo has
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   647
# uncommitted changes.  Wrap it to also check if lfiles were changed. This is
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   648
# used by bisect and backout.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   649
def override_bailifchanged(orig, repo):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   650
    orig(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   651
    repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   652
    modified, added, removed, deleted = repo.status()[:4]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   653
    repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   654
    if modified or added or removed or deleted:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   655
        raise util.Abort(_('outstanding uncommitted changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   656
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   657
# Fetch doesn't use cmdutil.bail_if_changed so override it to add the check
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   658
def override_fetch(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   659
    repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   660
    modified, added, removed, deleted = repo.status()[:4]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   661
    repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   662
    if modified or added or removed or deleted:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   663
        raise util.Abort(_('outstanding uncommitted changes'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   664
    return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   665
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   666
def override_forget(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   667
    installnormalfilesmatchfn(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   668
    orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   669
    restorematchfn()
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   670
    m = scmutil.match(repo[None], pats, opts)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   671
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   672
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   673
        repo.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   674
        s = repo.status(match=m, clean=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   675
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   676
        repo.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   677
    forget = sorted(s[0] + s[1] + s[3] + s[6])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   678
    forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   679
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   680
    for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   681
        if lfutil.standin(f) not in repo.dirstate and not \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   682
                os.path.isdir(m.rel(lfutil.standin(f))):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   683
            ui.warn(_('not removing %s: file is already untracked\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   684
                    % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   685
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   686
    for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   687
        if ui.verbose or not m.exact(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   688
            ui.status(_('removing %s\n') % m.rel(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   689
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   690
    # Need to lock because standin files are deleted then removed from the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   691
    # repository and we could race inbetween.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   692
    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   693
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   694
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   695
        for f in forget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   696
            if lfdirstate[f] == 'a':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   697
                lfdirstate.drop(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   698
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   699
                lfdirstate.remove(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   700
        lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   701
        lfutil.repo_remove(repo, [lfutil.standin(f) for f in forget],
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   702
            unlink=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   703
    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   704
        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   705
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   706
def getoutgoinglfiles(ui, repo, dest=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   707
    dest = ui.expandpath(dest or 'default-push', dest or 'default')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   708
    dest, branches = hg.parseurl(dest, opts.get('branch'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   709
    revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   710
    if revs:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   711
        revs = [repo.lookup(rev) for rev in revs]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   712
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   713
    remoteui = hg.remoteui
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   714
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   715
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   716
        remote = hg.repository(remoteui(repo, opts), dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   717
    except error.RepoError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   718
        return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   719
    o = lfutil.findoutgoing(repo, remote, False)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   720
    if not o:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   721
        return None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   722
    o = repo.changelog.nodesbetween(o, revs)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   723
    if opts.get('newest_first'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   724
        o.reverse()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   725
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   726
    toupload = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   727
    for n in o:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   728
        parents = [p for p in repo.changelog.parents(n) if p != node.nullid]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   729
        ctx = repo[n]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   730
        files = set(ctx.files())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   731
        if len(parents) == 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   732
            mc = ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   733
            mp1 = ctx.parents()[0].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   734
            mp2 = ctx.parents()[1].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   735
            for f in mp1:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   736
                if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   737
                        files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   738
            for f in mp2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   739
                if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   740
                    files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   741
            for f in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   742
                if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   743
                    files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   744
        toupload = toupload.union(set([f for f in files if lfutil.isstandin(f)\
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   745
            and f in ctx]))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   746
    return toupload
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   747
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   748
def override_outgoing(orig, ui, repo, dest=None, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   749
    orig(ui, repo, dest, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   750
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   751
    if opts.pop('large', None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   752
        toupload = getoutgoinglfiles(ui, repo, dest, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   753
        if toupload is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   754
            ui.status(_('largefiles: No remote repo\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   755
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   756
            ui.status(_('largefiles to upload:\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   757
            for file in toupload:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   758
                ui.status(lfutil.splitstandin(file) + '\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   759
            ui.status('\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   760
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   761
def override_summary(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   762
    orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   763
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   764
    if opts.pop('large', None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   765
        toupload = getoutgoinglfiles(ui, repo, None, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   766
        if toupload is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   767
            ui.status(_('largefiles: No remote repo\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   768
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   769
            ui.status(_('largefiles: %d to upload\n') % len(toupload))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   770
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   771
def override_addremove(orig, ui, repo, *pats, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   772
    # Check if the parent or child has lfiles if they do don't allow it.  If
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   773
    # there is a symlink in the manifest then getting the manifest throws an
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   774
    # exception catch it and let addremove deal with it. This happens in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   775
    # Mercurial's test test-addremove-symlink
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   776
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   777
        manifesttip = set(repo['tip'].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   778
    except util.Abort:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   779
        manifesttip = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   780
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   781
        manifestworking = set(repo[None].manifest())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   782
    except util.Abort:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   783
        manifestworking = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   784
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   785
    # Manifests are only iterable so turn them into sets then union
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   786
    for file in manifesttip.union(manifestworking):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   787
        if file.startswith(lfutil.shortname):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   788
            raise util.Abort(
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   789
                _('addremove cannot be run on a repo with largefiles'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   790
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   791
    return orig(ui, repo, *pats, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   792
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   793
# Calling purge with --all will cause the lfiles to be deleted.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   794
# Override repo.status to prevent this from happening.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   795
def override_purge(orig, ui, repo, *dirs, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   796
    oldstatus = repo.status
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   797
    def override_status(node1='.', node2=None, match=None, ignored=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   798
                        clean=False, unknown=False, listsubrepos=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   799
        r = oldstatus(node1, node2, match, ignored, clean, unknown,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   800
                      listsubrepos)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   801
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   802
        modified, added, removed, deleted, unknown, ignored, clean = r
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   803
        unknown = [f for f in unknown if lfdirstate[f] == '?']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   804
        ignored = [f for f in ignored if lfdirstate[f] == '?']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   805
        return modified, added, removed, deleted, unknown, ignored, clean
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   806
    repo.status = override_status
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   807
    orig(ui, repo, *dirs, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   808
    repo.status = oldstatus
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   809
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   810
def override_rollback(orig, ui, repo, **opts):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   811
    result = orig(ui, repo, **opts)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   812
    merge.update(repo, node=None, branchmerge=False, force=True,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   813
        partial=lfutil.isstandin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   814
    lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   815
    lfiles = lfutil.listlfiles(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   816
    oldlfiles = lfutil.listlfiles(repo, repo[None].parents()[0].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   817
    for file in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   818
        if file in oldlfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   819
            lfdirstate.normallookup(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   820
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   821
            lfdirstate.add(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   822
    lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   823
    return result