hgext/largefiles/reposetup.py
author Greg Ward <greg@gerg.ca>
Sun, 16 Oct 2011 10:29:51 -0400
branchstable
changeset 15305 683f417fa538
parent 15255 7ab05d752405
child 15312 8d862e7b96d4
permissions -rw-r--r--
largefiles: tidy imports - no need to defensively import scmutil - remove duplicate - unwrap non-long line
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
'''setup for largefiles repositories: reposetup'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
import copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
import types
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    12
import os
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
import re
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    14
15305
683f417fa538 largefiles: tidy imports
Greg Ward <greg@gerg.ca>
parents: 15255
diff changeset
    15
from mercurial import context, error, manifest, match as match_, node, util
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    17
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    18
import lfcommands
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    19
import proto
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    20
import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    21
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    22
def reposetup(ui, repo):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    23
    # wire repositories should be given new wireproto functions but not the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    24
    # other largefiles modifications
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    25
    if not repo.local():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    26
        return proto.wirereposetup(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    27
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    28
    for name in ('status', 'commitctx', 'commit', 'push'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    29
        method = getattr(repo, name)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    30
        #if not (isinstance(method, types.MethodType) and
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    31
        #        method.im_func is repo.__class__.commitctx.im_func):
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
    32
        if (isinstance(method, types.FunctionType) and
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
    33
            method.func_name == 'wrap'):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    34
            ui.warn(_('largefiles: repo method %r appears to have already been'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    35
                    ' wrapped by another extension: '
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    36
                    'largefiles may behave incorrectly\n')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    37
                    % name)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    38
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    39
    class lfiles_repo(repo.__class__):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    40
        lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    41
        def status_nolfiles(self, *args, **kwargs):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    42
            return super(lfiles_repo, self).status(*args, **kwargs)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    43
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    44
        # When lfstatus is set, return a context that gives the names
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    45
        # of largefiles instead of their corresponding standins and
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    46
        # identifies the largefiles as always binary, regardless of
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    47
        # their actual contents.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    48
        def __getitem__(self, changeid):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    49
            ctx = super(lfiles_repo, self).__getitem__(changeid)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    50
            if self.lfstatus:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    51
                class lfiles_manifestdict(manifest.manifestdict):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    52
                    def __contains__(self, filename):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    53
                        if super(lfiles_manifestdict,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    54
                                self).__contains__(filename):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    55
                            return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    56
                        return super(lfiles_manifestdict,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    57
                            self).__contains__(lfutil.shortname+'/' + filename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    58
                class lfiles_ctx(ctx.__class__):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    59
                    def files(self):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    60
                        filenames = super(lfiles_ctx, self).files()
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
    61
                        return [re.sub('^\\'+lfutil.shortname+'/', '',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
    62
                                       filename) for filename in filenames]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    63
                    def manifest(self):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    64
                        man1 = super(lfiles_ctx, self).manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    65
                        man1.__class__ = lfiles_manifestdict
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    66
                        return man1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    67
                    def filectx(self, path, fileid=None, filelog=None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    68
                        try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    69
                            result = super(lfiles_ctx, self).filectx(path,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    70
                                fileid, filelog)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    71
                        except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    72
                            # Adding a null character will cause Mercurial to
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    73
                            # identify this as a binary file.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    74
                            result = super(lfiles_ctx, self).filectx(
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    75
                                lfutil.shortname + '/' + path, fileid,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    76
                                filelog)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    77
                            olddata = result.data
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    78
                            result.data = lambda: olddata() + '\0'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    79
                        return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    80
                ctx.__class__ = lfiles_ctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    81
            return ctx
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    82
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
        # Figure out the status of big files and insert them into the
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    84
        # appropriate list in the result. Also removes standin files
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    85
        # from the listing. Revert to the original status if
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
    86
        # self.lfstatus is False.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    87
        def status(self, node1='.', node2=None, match=None, ignored=False,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    88
                clean=False, unknown=False, listsubrepos=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    89
            listignored, listclean, listunknown = ignored, clean, unknown
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    90
            if not self.lfstatus:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    91
                try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    92
                    return super(lfiles_repo, self).status(node1, node2, match,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    93
                        listignored, listclean, listunknown, listsubrepos)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    94
                except TypeError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    95
                    return super(lfiles_repo, self).status(node1, node2, match,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    96
                        listignored, listclean, listunknown)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    97
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    98
                # some calls in this function rely on the old version of status
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
                self.lfstatus = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   100
                if isinstance(node1, context.changectx):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
                    ctx1 = node1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   102
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   103
                    ctx1 = repo[node1]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   104
                if isinstance(node2, context.changectx):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
                    ctx2 = node2
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   106
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
                    ctx2 = repo[node2]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
                working = ctx2.rev() is None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
                parentworking = working and ctx1 == self['.']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   110
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
                def inctx(file, ctx):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
                    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   113
                        if ctx.rev() is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   114
                            return file in ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   115
                        ctx[file]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   116
                        return True
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   117
                    except KeyError:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   118
                        return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   119
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   120
                if match is None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   121
                    match = match_.always(self.root, self.getcwd())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   122
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   123
                # Create a copy of match that matches standins instead
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   124
                # of largefiles.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   125
                def tostandin(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   126
                    if inctx(lfutil.standin(file), ctx2):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   127
                        return lfutil.standin(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   128
                    return file
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   129
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   130
                m = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   131
                m._files = [tostandin(f) for f in m._files]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   132
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   133
                # get ignored, clean, and unknown but remove them
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   134
                # later if they were not asked for
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   135
                try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   136
                    result = super(lfiles_repo, self).status(node1, node2, m,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   137
                        True, True, True, listsubrepos)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   138
                except TypeError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   139
                    result = super(lfiles_repo, self).status(node1, node2, m,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   140
                        True, True, True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   141
                if working:
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   142
                    # hold the wlock while we read largefiles and
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   143
                    # update the lfdirstate
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   144
                    wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   145
                    try:
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   146
                        # Any non-largefiles that were explicitly listed must be
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   147
                        # taken out or lfdirstate.status will report an error.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   148
                        # The status of these files was already computed using
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   149
                        # super's status.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   150
                        lfdirstate = lfutil.openlfdirstate(ui, self)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   151
                        match._files = [f for f in match._files if f in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   152
                            lfdirstate]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   153
                        s = lfdirstate.status(match, [], listignored,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   154
                                listclean, listunknown)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   155
                        (unsure, modified, added, removed, missing, unknown,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   156
                                ignored, clean) = s
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   157
                        if parentworking:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   158
                            for lfile in unsure:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   159
                                if ctx1[lfutil.standin(lfile)].data().strip() \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   160
                                        != lfutil.hashfile(self.wjoin(lfile)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   161
                                    modified.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   162
                                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   163
                                    clean.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   164
                                    lfdirstate.normal(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   165
                            lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   166
                        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   167
                            tocheck = unsure + modified + added + clean
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   168
                            modified, added, clean = [], [], []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   169
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   170
                            for lfile in tocheck:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   171
                                standin = lfutil.standin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   172
                                if inctx(standin, ctx1):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   173
                                    if ctx1[standin].data().strip() != \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   174
                                            lfutil.hashfile(self.wjoin(lfile)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   175
                                        modified.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   176
                                    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   177
                                        clean.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   178
                                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   179
                                    added.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   180
                    finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   181
                        wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   182
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   183
                    for standin in ctx1.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   184
                        if not lfutil.isstandin(standin):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   185
                            continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   186
                        lfile = lfutil.splitstandin(standin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   187
                        if not match(lfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   188
                            continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   189
                        if lfile not in lfdirstate:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   190
                            removed.append(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   191
                    # Handle unknown and ignored differently
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   192
                    lfiles = (modified, added, removed, missing, [], [], clean)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   193
                    result = list(result)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   194
                    # Unknown files
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   195
                    result[4] = [f for f in unknown
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   196
                                 if (repo.dirstate[f] == '?' and
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   197
                                     not lfutil.isstandin(f))]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   198
                    # Ignored files must be ignored by both the dirstate and
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   199
                    # lfdirstate
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   200
                    result[5] = set(ignored).intersection(set(result[5]))
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   201
                    # combine normal files and largefiles
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   202
                    normals = [[fn for fn in filelist
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   203
                                if not lfutil.isstandin(fn)]
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   204
                               for filelist in result]
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   205
                    result = [sorted(list1 + list2)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   206
                              for (list1, list2) in zip(normals, lfiles)]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   207
                else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   208
                    def toname(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   209
                        if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   210
                            return lfutil.splitstandin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   211
                        return f
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   212
                    result = [[toname(f) for f in items] for items in result]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   213
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   214
                if not listunknown:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   215
                    result[4] = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   216
                if not listignored:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   217
                    result[5] = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   218
                if not listclean:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   219
                    result[6] = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   220
                self.lfstatus = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   221
                return result
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   222
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   223
        # As part of committing, copy all of the largefiles into the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   224
        # cache.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   225
        def commitctx(self, *args, **kwargs):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   226
            node = super(lfiles_repo, self).commitctx(*args, **kwargs)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   227
            ctx = self[node]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   228
            for filename in ctx.files():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   229
                if lfutil.isstandin(filename) and filename in ctx.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   230
                    realfile = lfutil.splitstandin(filename)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   231
                    lfutil.copytocache(self, ctx.node(), realfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   232
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   233
            return node
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   234
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   235
        # Before commit, largefile standins have not had their
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   236
        # contents updated to reflect the hash of their largefile.
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   237
        # Do that here.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   238
        def commit(self, text="", user=None, date=None, match=None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   239
                force=False, editor=False, extra={}):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   240
            orig = super(lfiles_repo, self).commit
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   241
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   242
            wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   243
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   244
                if getattr(repo, "_isrebasing", False):
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   245
                    # We have to take the time to pull down the new
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   246
                    # largefiles now. Otherwise if we are rebasing,
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   247
                    # any largefiles that were modified in the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   248
                    # destination changesets get overwritten, either
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   249
                    # by the rebase or in the first commit after the
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   250
                    # rebase.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   251
                    lfcommands.updatelfiles(repo.ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   252
                # Case 1: user calls commit with no specific files or
15250
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   253
                # include/exclude patterns: refresh and commit all files that
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   254
                # are "dirty".
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   255
                if ((match is None) or
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   256
                    (not match.anypats() and not match.files())):
15250
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   257
                    # Spend a bit of time here to get a list of files we know
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   258
                    # are modified so we can compare only against those.
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   259
                    # It can cost a lot of time (several seconds)
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   260
                    # otherwise to update all standins if the largefiles are
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   261
                    # large.
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   262
                    lfdirstate = lfutil.openlfdirstate(ui, self)
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   263
                    dirtymatch = match_.always(repo.root, repo.getcwd())
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   264
                    s = lfdirstate.status(dirtymatch, [], False, False, False)
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   265
                    modifiedfiles = []
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   266
                    for i in s:
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   267
                        modifiedfiles.extend(i)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   268
                    lfiles = lfutil.listlfiles(self)
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   269
                    # this only loops through largefiles that exist (not
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   270
                    # removed/renamed)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   271
                    for lfile in lfiles:
15250
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   272
                        if lfile in modifiedfiles:
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   273
                            if os.path.exists(self.wjoin(lfutil.standin(lfile))):
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   274
                                # this handles the case where a rebase is being
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   275
                                # performed and the working copy is not updated
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   276
                                # yet.
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   277
                                if os.path.exists(self.wjoin(lfile)):
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   278
                                    lfutil.updatestandin(self,
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   279
                                        lfutil.standin(lfile))
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   280
                                    lfdirstate.normal(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   281
                    for lfile in lfdirstate:
15250
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   282
                        if lfile in modifiedfiles:
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   283
                            if not os.path.exists(
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   284
                                    repo.wjoin(lfutil.standin(lfile))):
f172292cd416 largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents: 15224
diff changeset
   285
                                lfdirstate.drop(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   286
                    lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   287
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   288
                    return orig(text=text, user=user, date=date, match=match,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   289
                                    force=force, editor=editor, extra=extra)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   290
15253
67d010779907 largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   291
                for f in match.files():
67d010779907 largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   292
                    if lfutil.isstandin(f):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   293
                        raise util.Abort(
15253
67d010779907 largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   294
                            _('file "%s" is a largefile standin') % f,
67d010779907 largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   295
                            hint=('commit the largefile itself instead'))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   296
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   297
                # Case 2: user calls commit with specified patterns: refresh
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   298
                # any matching big files.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   299
                smatcher = lfutil.composestandinmatcher(self, match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   300
                standins = lfutil.dirstate_walk(self.dirstate, smatcher)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   301
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   302
                # No matching big files: get out of the way and pass control to
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   303
                # the usual commit() method.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   304
                if not standins:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   305
                    return orig(text=text, user=user, date=date, match=match,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   306
                                    force=force, editor=editor, extra=extra)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   307
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   308
                # Refresh all matching big files.  It's possible that the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   309
                # commit will end up failing, in which case the big files will
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   310
                # stay refreshed.  No harm done: the user modified them and
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   311
                # asked to commit them, so sooner or later we're going to
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   312
                # refresh the standins.  Might as well leave them refreshed.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   313
                lfdirstate = lfutil.openlfdirstate(ui, self)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   314
                for standin in standins:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   315
                    lfile = lfutil.splitstandin(standin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   316
                    if lfdirstate[lfile] <> 'r':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   317
                        lfutil.updatestandin(self, standin)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   318
                        lfdirstate.normal(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   319
                    else:
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15171
diff changeset
   320
                        lfdirstate.drop(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   321
                lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   322
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   323
                # Cook up a new matcher that only matches regular files or
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   324
                # standins corresponding to the big files requested by the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   325
                # user.  Have to modify _files to prevent commit() from
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   326
                # complaining "not tracked" for big files.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   327
                lfiles = lfutil.listlfiles(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   328
                match = copy.copy(match)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   329
                orig_matchfn = match.matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   330
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   331
                # Check both the list of largefiles and the list of
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   332
                # standins because if a largefile was removed, it
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   333
                # won't be in the list of largefiles at this point
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   334
                match._files += sorted(standins)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   335
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   336
                actualfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   337
                for f in match._files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   338
                    fstandin = lfutil.standin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   339
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   340
                    # ignore known largefiles and standins
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   341
                    if f in lfiles or fstandin in standins:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   342
                        continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   343
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   344
                    # append directory separator to avoid collisions
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   345
                    if not fstandin.endswith(os.sep):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   346
                        fstandin += os.sep
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   347
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   348
                    # prevalidate matching standin directories
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   349
                    if lfutil.any_(st for st in match._files
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   350
                                   if st.startswith(fstandin)):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   351
                        continue
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   352
                    actualfiles.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   353
                match._files = actualfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   354
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   355
                def matchfn(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   356
                    if orig_matchfn(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   357
                        return f not in lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   358
                    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   359
                        return f in standins
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   360
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   361
                match.matchfn = matchfn
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   362
                return orig(text=text, user=user, date=date, match=match,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   363
                                force=force, editor=editor, extra=extra)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   364
            finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   365
                wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   366
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   367
        def push(self, remote, force=False, revs=None, newbranch=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   368
            o = lfutil.findoutgoing(repo, remote, force)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   369
            if o:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   370
                toupload = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   371
                o = repo.changelog.nodesbetween(o, revs)[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   372
                for n in o:
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   373
                    parents = [p for p in repo.changelog.parents(n)
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   374
                               if p != node.nullid]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   375
                    ctx = repo[n]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   376
                    files = set(ctx.files())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   377
                    if len(parents) == 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   378
                        mc = ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   379
                        mp1 = ctx.parents()[0].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   380
                        mp2 = ctx.parents()[1].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   381
                        for f in mp1:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   382
                            if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   383
                                files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   384
                        for f in mp2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   385
                            if f not in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   386
                                files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   387
                        for f in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   388
                            if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   389
                                    None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   390
                                files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   391
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   392
                    toupload = toupload.union(
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   393
                        set([ctx[f].data().strip()
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   394
                             for f in files
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15254
diff changeset
   395
                             if lfutil.isstandin(f) and f in ctx]))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   396
                lfcommands.uploadlfiles(ui, self, remote, toupload)
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15171
diff changeset
   397
            return super(lfiles_repo, self).push(remote, force, revs,
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15171
diff changeset
   398
                newbranch)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   399
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   400
    repo.__class__ = lfiles_repo
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   401
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   402
    def checkrequireslfiles(ui, repo, **kwargs):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   403
        if 'largefiles' not in repo.requirements and lfutil.any_(
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   404
                lfutil.shortname+'/' in f[0] for f in repo.store.datafiles()):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   405
            # workaround bug in Mercurial 1.9 whereby requirements is
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15250
diff changeset
   406
            # a list on newly-cloned repos
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   407
            repo.requirements = set(repo.requirements)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   408
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   409
            repo.requirements |= set(['largefiles'])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   410
            repo._writerequirements()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   411
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   412
    checkrequireslfiles(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   413
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   414
    ui.setconfig('hooks', 'changegroup.lfiles', checkrequireslfiles)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   415
    ui.setconfig('hooks', 'commit.lfiles', checkrequireslfiles)