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