mercurial/context.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Thu, 01 May 2014 14:07:04 -0700
branchstable
changeset 21217 2195ac506c6a
parent 21203 9f12d8665c7b
child 21238 25d6fdc0294a
permissions -rw-r--r--
revset: directly use __contains__ instead of a lambda We get rid of lambda in a bunch of other place. This is equivalent and much faster. (no new timing as this is the same change as three other changesets)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# context.py - changeset and file context objects for mercurial
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4417
diff changeset
     3
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10262
diff changeset
     6
# GNU General Public License version 2 or any later version.
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
     8
from node import nullid, nullrev, short, hex, bin
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
     9
from i18n import _
20984
f4a87d1ee1aa context: remove unused filectx.ancestor
Mads Kiilerich <madski@unity3d.com>
parents: 20400
diff changeset
    10
import mdiff, error, util, scmutil, subrepo, patch, encoding, phases
14669
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
    11
import match as matchmod
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
    12
import os, errno, stat
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17427
diff changeset
    13
import obsolete as obsmod
18252
3f1552c6bf71 context: retrieve hidden from filteredrevs
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18211
diff changeset
    14
import repoview
20400
f0137d994c83 context: add a getfileset() method so fewer things need fileset directly
Augie Fackler <raf@durin42.com>
parents: 20292
diff changeset
    15
import fileset
3122
da85145d4571 filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents: 2859
diff changeset
    16
8207
dd8d5be57d65 util: take propertycache from context.py
Matt Mackall <mpm@selenic.com>
parents: 8157
diff changeset
    17
propertycache = util.propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
    18
19537
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    19
class basectx(object):
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    20
    """A basectx object represents the common logic for its children:
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    21
    changectx: read-only context that is already present in the repo,
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    22
    workingctx: a context that represents the working directory and can
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    23
                be committed,
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    24
    memctx: a context that represents changes in-memory and can also
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    25
            be committed."""
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    26
    def __new__(cls, repo, changeid='', *args, **kwargs):
19538
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    27
        if isinstance(changeid, basectx):
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    28
            return changeid
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    29
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    30
        o = super(basectx, cls).__new__(cls)
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    31
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    32
        o._repo = repo
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    33
        o._rev = nullrev
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    34
        o._node = nullid
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    35
049d6b5a4a59 basectx: return a copied context if changeid is already a basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19537
diff changeset
    36
        return o
19537
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
    37
19540
7b864da00e21 basectx: move __str__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19539
diff changeset
    38
    def __str__(self):
7b864da00e21 basectx: move __str__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19539
diff changeset
    39
        return short(self.node())
7b864da00e21 basectx: move __str__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19539
diff changeset
    40
19545
5af7045b0b18 basectx: move __int__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19544
diff changeset
    41
    def __int__(self):
5af7045b0b18 basectx: move __int__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19544
diff changeset
    42
        return self.rev()
5af7045b0b18 basectx: move __int__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19544
diff changeset
    43
19546
a45cf68dd9a2 basectx: move __repr__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19545
diff changeset
    44
    def __repr__(self):
a45cf68dd9a2 basectx: move __repr__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19545
diff changeset
    45
        return "<%s %s>" % (type(self).__name__, str(self))
a45cf68dd9a2 basectx: move __repr__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19545
diff changeset
    46
19547
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    47
    def __eq__(self, other):
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    48
        try:
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    49
            return type(self) == type(other) and self._rev == other._rev
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    50
        except AttributeError:
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    51
            return False
0537c0cfd87c basectx: move __eq__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19546
diff changeset
    52
19548
730fdcaa791d basectx: move __ne__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19547
diff changeset
    53
    def __ne__(self, other):
730fdcaa791d basectx: move __ne__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19547
diff changeset
    54
        return not (self == other)
730fdcaa791d basectx: move __ne__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19547
diff changeset
    55
19550
0c8ad779eb36 basectx: move __contains__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19549
diff changeset
    56
    def __contains__(self, key):
0c8ad779eb36 basectx: move __contains__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19549
diff changeset
    57
        return key in self._manifest
0c8ad779eb36 basectx: move __contains__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19549
diff changeset
    58
19551
e07c69145724 basectx: move __getitem__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19550
diff changeset
    59
    def __getitem__(self, key):
e07c69145724 basectx: move __getitem__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19550
diff changeset
    60
        return self.filectx(key)
e07c69145724 basectx: move __getitem__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19550
diff changeset
    61
19552
6b76070c4b54 basectx: move __iter__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19551
diff changeset
    62
    def __iter__(self):
6b76070c4b54 basectx: move __iter__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19551
diff changeset
    63
        for f in sorted(self._manifest):
6b76070c4b54 basectx: move __iter__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19551
diff changeset
    64
            yield f
6b76070c4b54 basectx: move __iter__ from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19551
diff changeset
    65
19549
78155484ae34 basectx: move substate from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19548
diff changeset
    66
    @propertycache
78155484ae34 basectx: move substate from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19548
diff changeset
    67
    def substate(self):
78155484ae34 basectx: move substate from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19548
diff changeset
    68
        return subrepo.state(self, self._repo.ui)
78155484ae34 basectx: move substate from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19548
diff changeset
    69
19541
421d49f2f8e2 basectx: move rev from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19540
diff changeset
    70
    def rev(self):
421d49f2f8e2 basectx: move rev from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19540
diff changeset
    71
        return self._rev
19542
bd95621a2d56 basectx: move node from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19541
diff changeset
    72
    def node(self):
bd95621a2d56 basectx: move node from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19541
diff changeset
    73
        return self._node
19543
18f4951222f4 basectx: move hex from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19542
diff changeset
    74
    def hex(self):
19544
74924fa3236d basectx: change _node to node() in hex
Sean Farley <sean.michael.farley@gmail.com>
parents: 19543
diff changeset
    75
        return hex(self.node())
19553
64a99d972b9e basectx: move manifest from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19552
diff changeset
    76
    def manifest(self):
64a99d972b9e basectx: move manifest from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19552
diff changeset
    77
        return self._manifest
19554
98f8875f4baa basectx: move phasestr from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19553
diff changeset
    78
    def phasestr(self):
98f8875f4baa basectx: move phasestr from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19553
diff changeset
    79
        return phases.phasenames[self.phase()]
19555
613b70fedc4e basectx: move mutable from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19554
diff changeset
    80
    def mutable(self):
613b70fedc4e basectx: move mutable from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19554
diff changeset
    81
        return self.phase() > phases.public
19541
421d49f2f8e2 basectx: move rev from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19540
diff changeset
    82
20400
f0137d994c83 context: add a getfileset() method so fewer things need fileset directly
Augie Fackler <raf@durin42.com>
parents: 20292
diff changeset
    83
    def getfileset(self, expr):
f0137d994c83 context: add a getfileset() method so fewer things need fileset directly
Augie Fackler <raf@durin42.com>
parents: 20292
diff changeset
    84
        return fileset.getfileset(self, expr)
f0137d994c83 context: add a getfileset() method so fewer things need fileset directly
Augie Fackler <raf@durin42.com>
parents: 20292
diff changeset
    85
19734
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    86
    def obsolete(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    87
        """True if the changeset is obsolete"""
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    88
        return self.rev() in obsmod.getrevs(self._repo, 'obsolete')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    89
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    90
    def extinct(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    91
        """True if the changeset is extinct"""
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    92
        return self.rev() in obsmod.getrevs(self._repo, 'extinct')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    93
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    94
    def unstable(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    95
        """True if the changeset is not obsolete but it's ancestor are"""
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    96
        return self.rev() in obsmod.getrevs(self._repo, 'unstable')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    97
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    98
    def bumped(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
    99
        """True if the changeset try to be a successor of a public changeset
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   100
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   101
        Only non-public and non-obsolete changesets may be bumped.
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   102
        """
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   103
        return self.rev() in obsmod.getrevs(self._repo, 'bumped')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   104
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   105
    def divergent(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   106
        """Is a successors of a changeset with multiple possible successors set
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   107
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   108
        Only non-public and non-obsolete changesets may be divergent.
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   109
        """
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   110
        return self.rev() in obsmod.getrevs(self._repo, 'divergent')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   111
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   112
    def troubled(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   113
        """True if the changeset is either unstable, bumped or divergent"""
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   114
        return self.unstable() or self.bumped() or self.divergent()
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   115
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   116
    def troubles(self):
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   117
        """return the list of troubles affecting this changesets.
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   118
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   119
        Troubles are returned as strings. possible values are:
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   120
        - unstable,
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   121
        - bumped,
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   122
        - divergent.
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   123
        """
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   124
        troubles = []
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   125
        if self.unstable():
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   126
            troubles.append('unstable')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   127
        if self.bumped():
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   128
            troubles.append('bumped')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   129
        if self.divergent():
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   130
            troubles.append('divergent')
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   131
        return troubles
e61c6138fa33 context: move evolution functions from changectx to basectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19733
diff changeset
   132
19556
732ee7fff35a basectx: move parents from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19555
diff changeset
   133
    def parents(self):
732ee7fff35a basectx: move parents from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19555
diff changeset
   134
        """return contexts for each parent changeset"""
732ee7fff35a basectx: move parents from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19555
diff changeset
   135
        return self._parents
732ee7fff35a basectx: move parents from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19555
diff changeset
   136
19557
9f57ebf0cce8 basectx: move p1 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19556
diff changeset
   137
    def p1(self):
9f57ebf0cce8 basectx: move p1 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19556
diff changeset
   138
        return self._parents[0]
9f57ebf0cce8 basectx: move p1 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19556
diff changeset
   139
19558
d0448e9d4554 basectx: move p2 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19557
diff changeset
   140
    def p2(self):
d0448e9d4554 basectx: move p2 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19557
diff changeset
   141
        if len(self._parents) == 2:
d0448e9d4554 basectx: move p2 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19557
diff changeset
   142
            return self._parents[1]
d0448e9d4554 basectx: move p2 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19557
diff changeset
   143
        return changectx(self._repo, -1)
d0448e9d4554 basectx: move p2 from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19557
diff changeset
   144
19559
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   145
    def _fileinfo(self, path):
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   146
        if '_manifest' in self.__dict__:
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   147
            try:
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   148
                return self._manifest[path], self._manifest.flags(path)
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   149
            except KeyError:
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   150
                raise error.ManifestLookupError(self._node, path,
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   151
                                                _('not found in manifest'))
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   152
        if '_manifestdelta' in self.__dict__ or path in self.files():
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   153
            if path in self._manifestdelta:
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   154
                return (self._manifestdelta[path],
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   155
                        self._manifestdelta.flags(path))
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   156
        node, flag = self._repo.manifest.find(self._changeset[0], path)
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   157
        if not node:
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   158
            raise error.ManifestLookupError(self._node, path,
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   159
                                            _('not found in manifest'))
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   160
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   161
        return node, flag
80ad9fe22e18 basectx: move _fileinfo from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19558
diff changeset
   162
19560
f256e1108053 basectx: move filenode from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19559
diff changeset
   163
    def filenode(self, path):
f256e1108053 basectx: move filenode from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19559
diff changeset
   164
        return self._fileinfo(path)[0]
f256e1108053 basectx: move filenode from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19559
diff changeset
   165
19561
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   166
    def flags(self, path):
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   167
        try:
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   168
            return self._fileinfo(path)[1]
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   169
        except error.LookupError:
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   170
            return ''
7806e63598b0 basectx: move flags from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19560
diff changeset
   171
19562
389d7767630d basectx: move sub from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19561
diff changeset
   172
    def sub(self, path):
389d7767630d basectx: move sub from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19561
diff changeset
   173
        return subrepo.subrepo(self, path)
389d7767630d basectx: move sub from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19561
diff changeset
   174
19563
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   175
    def match(self, pats=[], include=None, exclude=None, default='glob'):
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   176
        r = self._repo
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   177
        return matchmod.match(r.root, r.getcwd(), pats,
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   178
                              include, exclude, default,
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   179
                              auditor=r.auditor, ctx=self)
87503cd824fa basectx: move match from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19562
diff changeset
   180
19564
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   181
    def diff(self, ctx2=None, match=None, **opts):
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   182
        """Returns a diff generator for the given contexts and matcher"""
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   183
        if ctx2 is None:
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   184
            ctx2 = self.p1()
19568
f58235d85d6b basectx: remove unnecessary check of instance
Sean Farley <sean.michael.farley@gmail.com>
parents: 19567
diff changeset
   185
        if ctx2 is not None:
19564
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   186
            ctx2 = self._repo[ctx2]
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   187
        diffopts = patch.diffopts(self._repo.ui, opts)
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   188
        return patch.diff(self._repo, ctx2.node(), self.node(),
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   189
                          match=match, opts=diffopts)
f0ed47b73d37 basectx: move diff from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19563
diff changeset
   190
19565
bd1580a9c133 basectx: move _dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19564
diff changeset
   191
    @propertycache
bd1580a9c133 basectx: move _dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19564
diff changeset
   192
    def _dirs(self):
bd1580a9c133 basectx: move _dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19564
diff changeset
   193
        return scmutil.dirs(self._manifest)
bd1580a9c133 basectx: move _dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19564
diff changeset
   194
19566
54817c774d38 basectx: move dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19565
diff changeset
   195
    def dirs(self):
54817c774d38 basectx: move dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19565
diff changeset
   196
        return self._dirs
54817c774d38 basectx: move dirs from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19565
diff changeset
   197
19567
49b128e50e84 basectx: move dirty from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19566
diff changeset
   198
    def dirty(self):
49b128e50e84 basectx: move dirty from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19566
diff changeset
   199
        return False
49b128e50e84 basectx: move dirty from changectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19566
diff changeset
   200
20035
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   201
def makememctx(repo, parents, text, user, date, branch, files, store,
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   202
               editor=None):
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   203
    def getfilectx(repo, memctx, path):
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   204
        data, (islink, isexec), copied = store.getfile(path)
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   205
        return memfilectx(path, data, islink=islink, isexec=isexec,
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   206
                                  copied=copied)
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   207
    extra = {}
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   208
    if branch:
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   209
        extra['branch'] = encoding.fromlocal(branch)
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   210
    ctx =  memctx(repo, parents, text, files, getfilectx, user,
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   211
                          date, extra)
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   212
    if editor:
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   213
        ctx._text = editor(repo, ctx, [])
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   214
    return ctx
cd79d9ab5e42 makememctx: move from patch to context to break import cycle
Augie Fackler <raf@durin42.com>
parents: 19951
diff changeset
   215
19537
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
   216
class changectx(basectx):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   217
    """A changecontext object makes access to data related to a particular
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19902
diff changeset
   218
    changeset convenient. It represents a read-only context already present in
19537
6e3e8575276d basectx: add an empty class that will be used as a parent of all contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19314
diff changeset
   219
    the repo."""
6741
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
   220
    def __init__(self, repo, changeid=''):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   221
        """changeid is a revision number, node, or tag"""
19539
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   222
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   223
        # since basectx.__new__ already took care of copying the object, we
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   224
        # don't need to do anything in __init__, so we just exit here
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   225
        if isinstance(changeid, basectx):
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   226
            return
79671c46bb46 changectx: if passing a basectx then exit __init__ immediately
Sean Farley <sean.michael.farley@gmail.com>
parents: 19538
diff changeset
   227
6741
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
   228
        if changeid == '':
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
   229
            changeid = '.'
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   230
        self._repo = repo
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   231
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   232
        if isinstance(changeid, int):
18084
ee3b5fb648c7 clfilter: ensure context raise RepoLookupError when the revision is filtered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18072
diff changeset
   233
            try:
ee3b5fb648c7 clfilter: ensure context raise RepoLookupError when the revision is filtered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18072
diff changeset
   234
                self._node = repo.changelog.node(changeid)
ee3b5fb648c7 clfilter: ensure context raise RepoLookupError when the revision is filtered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18072
diff changeset
   235
            except IndexError:
ee3b5fb648c7 clfilter: ensure context raise RepoLookupError when the revision is filtered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18072
diff changeset
   236
                raise error.RepoLookupError(
ee3b5fb648c7 clfilter: ensure context raise RepoLookupError when the revision is filtered
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18072
diff changeset
   237
                    _("unknown revision '%s'") % changeid)
7367
ad0eb8762458 context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
   238
            self._rev = changeid
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   239
            return
16760
ac89a23ca814 context: grudging accept longs in constructor
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
   240
        if isinstance(changeid, long):
ac89a23ca814 context: grudging accept longs in constructor
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
   241
            changeid = str(changeid)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   242
        if changeid == '.':
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   243
            self._node = repo.dirstate.p1()
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   244
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   245
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   246
        if changeid == 'null':
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   247
            self._node = nullid
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   248
            self._rev = nullrev
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   249
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   250
        if changeid == 'tip':
18464
a2e9fe93d9ea changectx: fix the handling of `tip`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18423
diff changeset
   251
            self._node = repo.changelog.tip()
a2e9fe93d9ea changectx: fix the handling of `tip`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18423
diff changeset
   252
            self._rev = repo.changelog.rev(self._node)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   253
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   254
        if len(changeid) == 20:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   255
            try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   256
                self._node = changeid
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   257
                self._rev = repo.changelog.rev(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   258
                return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   259
            except LookupError:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   260
                pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   261
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   262
        try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   263
            r = int(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   264
            if str(r) != changeid:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   265
                raise ValueError
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   266
            l = len(repo.changelog)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   267
            if r < 0:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   268
                r += l
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   269
            if r < 0 or r >= l:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   270
                raise ValueError
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   271
            self._rev = r
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   272
            self._node = repo.changelog.node(r)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   273
            return
18423
5d6ee2494f63 clfilter: stronger detection of filtered changeset in changectx.__init__
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18382
diff changeset
   274
        except (ValueError, OverflowError, IndexError):
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   275
            pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   276
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   277
        if len(changeid) == 40:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   278
            try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   279
                self._node = bin(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   280
                self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   281
                return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   282
            except (TypeError, LookupError):
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   283
                pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   284
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   285
        if changeid in repo._bookmarks:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   286
            self._node = repo._bookmarks[changeid]
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   287
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   288
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   289
        if changeid in repo._tagscache.tags:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   290
            self._node = repo._tagscache.tags[changeid]
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   291
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   292
            return
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   293
        try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   294
            self._node = repo.branchtip(changeid)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   295
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   296
            return
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   297
        except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   298
            pass
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   299
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   300
        self._node = repo.changelog._partialmatch(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   301
        if self._node is not None:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   302
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   303
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   304
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   305
        # lookup failed
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   306
        # check if it might have come from damaged dirstate
18005
aba3c161bcc6 clfilter: prevent unwanted warning about filtered parents as unknown
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17832
diff changeset
   307
        #
aba3c161bcc6 clfilter: prevent unwanted warning about filtered parents as unknown
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17832
diff changeset
   308
        # XXX we could avoid the unfiltered if we had a recognizable exception
aba3c161bcc6 clfilter: prevent unwanted warning about filtered parents as unknown
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17832
diff changeset
   309
        # for filtered changeset access
aba3c161bcc6 clfilter: prevent unwanted warning about filtered parents as unknown
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17832
diff changeset
   310
        if changeid in repo.unfiltered().dirstate.parents():
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   311
            raise error.Abort(_("working directory has unknown parent '%s'!")
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   312
                              % short(changeid))
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   313
        try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   314
            if len(changeid) == 20:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   315
                changeid = hex(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   316
        except TypeError:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   317
            pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   318
        raise error.RepoLookupError(
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   319
            _("unknown revision '%s'") % changeid)
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   320
6469
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   321
    def __hash__(self):
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   322
        try:
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   323
            return hash(self._rev)
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   324
        except AttributeError:
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   325
            return id(self)
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   326
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   327
    def __nonzero__(self):
3578
3b4e00cba57a Define and use nullrev (revision of nullid) instead of -1.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3454
diff changeset
   328
        return self._rev != nullrev
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   329
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   330
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   331
    def _changeset(self):
16377
f8ce254e514f context: use rev for changelog lookup
Matt Mackall <mpm@selenic.com>
parents: 16376
diff changeset
   332
        return self._repo.changelog.read(self.rev())
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   333
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   334
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   335
    def _manifest(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   336
        return self._repo.manifest.read(self._changeset[0])
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   337
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   338
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   339
    def _manifestdelta(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   340
        return self._repo.manifest.readdelta(self._changeset[0])
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   341
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   342
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   343
    def _parents(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   344
        p = self._repo.changelog.parentrevs(self._rev)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   345
        if p[1] == nullrev:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   346
            p = p[:-1]
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   347
        return [changectx(self._repo, x) for x in p]
3215
931288cf58a7 contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents: 3214
diff changeset
   348
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   349
    def changeset(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   350
        return self._changeset
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   351
    def manifestnode(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   352
        return self._changeset[0]
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   353
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   354
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   355
        return self._changeset[1]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   356
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   357
        return self._changeset[2]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   358
    def files(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   359
        return self._changeset[3]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   360
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   361
        return self._changeset[4]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   362
    def branch(self):
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
   363
        return encoding.tolocal(self._changeset[5].get("branch"))
16720
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   364
    def closesbranch(self):
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   365
        return 'close' in self._changeset[5]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   366
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   367
        return self._changeset[5]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   368
    def tags(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   369
        return self._repo.nodetags(self._node)
13384
caa561759538 context: add method to return all bookmarks pointing to a node
David Soria Parra <dsp@php.net>
parents: 13235
diff changeset
   370
    def bookmarks(self):
caa561759538 context: add method to return all bookmarks pointing to a node
David Soria Parra <dsp@php.net>
parents: 13235
diff changeset
   371
        return self._repo.nodebookmarks(self._node)
15421
405ca90df2b1 phases: add a phase method to context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 15337
diff changeset
   372
    def phase(self):
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16610
diff changeset
   373
        return self._repo._phasecache.phase(self._repo, self._rev)
14644
f3a40fd7008c hidden: Add ``hidden`` method for context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14528
diff changeset
   374
    def hidden(self):
18382
f3b21beb9802 filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents: 18364
diff changeset
   375
        return self._rev in repoview.filterrevs(self._repo, 'visible')
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   376
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   377
    def children(self):
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   378
        """return contexts for each child changeset"""
2627
b779319a532b context.py: self.repo is not defined, change to self._repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2566
diff changeset
   379
        c = self._repo.changelog.children(self._node)
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   380
        return [changectx(self._repo, x) for x in c]
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   381
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   382
    def ancestors(self):
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16761
diff changeset
   383
        for a in self._repo.changelog.ancestors([self._rev]):
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   384
            yield changectx(self._repo, a)
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   385
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   386
    def descendants(self):
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
   387
        for d in self._repo.changelog.descendants([self._rev]):
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   388
            yield changectx(self._repo, d)
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   389
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
   390
    def filectx(self, path, fileid=None, filelog=None):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   391
        """get a file context from this changeset"""
2628
9999a796d389 context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2627
diff changeset
   392
        if fileid is None:
9999a796d389 context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2627
diff changeset
   393
            fileid = self.filenode(path)
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
   394
        return filectx(self._repo, path, fileid=fileid,
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
   395
                       changectx=self, filelog=filelog)
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   396
21203
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   397
    def ancestor(self, c2, warn=False):
3125
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   398
        """
21126
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   399
        return the "best" ancestor context of self and c2
3125
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   400
        """
9843
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   401
        # deal with workingctxs
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   402
        n2 = c2._node
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 13001
diff changeset
   403
        if n2 is None:
9843
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   404
            n2 = c2._parents[0]._node
21125
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   405
        cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   406
        if not cahs:
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   407
            anc = nullid
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   408
        elif len(cahs) == 1:
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   409
            anc = cahs[0]
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   410
        else:
21126
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   411
            for r in self._repo.ui.configlist('merge', 'preferancestor'):
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   412
                ctx = changectx(self._repo, r)
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   413
                anc = ctx.node()
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   414
                if anc in cahs:
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   415
                    break
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   416
            else:
99b5eaf372a7 context: introduce merge.preferancestor for controlling which ancestor to pick
Mads Kiilerich <madski@unity3d.com>
parents: 21125
diff changeset
   417
                anc = self._repo.changelog.ancestor(self._node, n2)
21203
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   418
            if warn:
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   419
                self._repo.ui.status(
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   420
                    (_("note: using %s as ancestor of %s and %s\n") %
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   421
                     (short(anc), short(self._node), short(n2))) +
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   422
                    ''.join(_("      alternatively, use --config "
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   423
                              "merge.preferancestor=%s\n") %
9f12d8665c7b ancestor: silence multiple ancestor warning outside of merge (issue4234)
Matt Mackall <mpm@selenic.com>
parents: 21126
diff changeset
   424
                            short(n) for n in sorted(cahs) if n != anc))
21125
e94e90a4526e context: tell when .ancestor picks one of multiple common ancestors heads
Mads Kiilerich <madski@unity3d.com>
parents: 21114
diff changeset
   425
        return changectx(self._repo, anc)
3125
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   426
17626
3a524b647897 context: add "descendant()" to changectx for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17469
diff changeset
   427
    def descendant(self, other):
3a524b647897 context: add "descendant()" to changectx for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17469
diff changeset
   428
        """True if other is descendant of this changeset"""
3a524b647897 context: add "descendant()" to changectx for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17469
diff changeset
   429
        return self._repo.changelog.descendant(self._rev, other._rev)
3a524b647897 context: add "descendant()" to changectx for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17469
diff changeset
   430
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   431
    def walk(self, match):
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   432
        fset = set(match.files())
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   433
        # for dirstate.walk, files=['.'] means "walk the whole tree".
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   434
        # follow that here, too
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   435
        fset.discard('.')
20292
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   436
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   437
        # avoid the entire walk if we're only looking for specific files
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   438
        if fset and not match.anypats():
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   439
            if util.all([fn in self for fn in fset]):
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   440
                for fn in sorted(fset):
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   441
                    if match(fn):
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   442
                        yield fn
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   443
                raise StopIteration
8dc254198a8f changectx: increase perf of walk function
Durham Goode <durham@fb.com>
parents: 20236
diff changeset
   444
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   445
        for fn in self:
16145
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   446
            if fn in fset:
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   447
                # specified pattern is the exact name
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   448
                fset.remove(fn)
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   449
            if match(fn):
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   450
                yield fn
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   451
        for fn in sorted(fset):
16145
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   452
            if fn in self._dirs:
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   453
                # specified pattern is a directory
616c2e278f18 context: use 'changectx.dirs()' in 'walk()' for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16143
diff changeset
   454
                continue
21114
a63958bcf63a context: remove redundant handling of match.bad return value
Mads Kiilerich <madski@unity3d.com>
parents: 20984
diff changeset
   455
            match.bad(fn, _('no such file in rev %s') % self)
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   456
19572
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   457
class basefilectx(object):
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   458
    """A filecontext object represents the common logic for its children:
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   459
    filectx: read-only access to a filerevision that is already present
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   460
             in the repo,
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   461
    workingfilectx: a filecontext that represents files from the working
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   462
                    directory,
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   463
    memfilectx: a filecontext that represents files in-memory."""
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   464
    def __new__(cls, repo, path, *args, **kwargs):
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   465
        return super(basefilectx, cls).__new__(cls)
c19f46b904b9 basefilectx: add an empty class that will be used as a parent of file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19571
diff changeset
   466
19573
dffad92ab709 basefilectx: move _filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19572
diff changeset
   467
    @propertycache
dffad92ab709 basefilectx: move _filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19572
diff changeset
   468
    def _filelog(self):
dffad92ab709 basefilectx: move _filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19572
diff changeset
   469
        return self._repo.file(self._path)
dffad92ab709 basefilectx: move _filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19572
diff changeset
   470
19574
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   471
    @propertycache
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   472
    def _changeid(self):
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   473
        if '_changeid' in self.__dict__:
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   474
            return self._changeid
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   475
        elif '_changectx' in self.__dict__:
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   476
            return self._changectx.rev()
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   477
        else:
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   478
            return self._filelog.linkrev(self._filerev)
a01436798988 basefilectx: move _changeid from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19573
diff changeset
   479
19575
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   480
    @propertycache
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   481
    def _filenode(self):
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   482
        if '_fileid' in self.__dict__:
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   483
            return self._filelog.lookup(self._fileid)
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   484
        else:
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   485
            return self._changectx.filenode(self._path)
5a868137b830 basefilectx: move _filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19574
diff changeset
   486
19576
18bbd8a3abf3 basefilectx: move _filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19575
diff changeset
   487
    @propertycache
18bbd8a3abf3 basefilectx: move _filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19575
diff changeset
   488
    def _filerev(self):
18bbd8a3abf3 basefilectx: move _filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19575
diff changeset
   489
        return self._filelog.rev(self._filenode)
18bbd8a3abf3 basefilectx: move _filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19575
diff changeset
   490
19577
b52d572a2177 basefilectx: move _repopath from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19576
diff changeset
   491
    @propertycache
b52d572a2177 basefilectx: move _repopath from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19576
diff changeset
   492
    def _repopath(self):
b52d572a2177 basefilectx: move _repopath from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19576
diff changeset
   493
        return self._path
b52d572a2177 basefilectx: move _repopath from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19576
diff changeset
   494
19578
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   495
    def __nonzero__(self):
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   496
        try:
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   497
            self._filenode
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   498
            return True
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   499
        except error.LookupError:
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   500
            # file is missing
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   501
            return False
2c149635c2c5 basefilectx: move __nonzero__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19577
diff changeset
   502
19579
964844d64ef8 basefilectx: move __str__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19578
diff changeset
   503
    def __str__(self):
19660
86ce68c1ccb8 basefilectx: use basectx __str__ instead of duplicating logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 19659
diff changeset
   504
        return "%s@%s" % (self.path(), self._changectx)
19579
964844d64ef8 basefilectx: move __str__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19578
diff changeset
   505
19580
e86a594ab11f basefilectx: move __repr__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19579
diff changeset
   506
    def __repr__(self):
e86a594ab11f basefilectx: move __repr__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19579
diff changeset
   507
        return "<%s %s>" % (type(self).__name__, str(self))
e86a594ab11f basefilectx: move __repr__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19579
diff changeset
   508
19581
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   509
    def __hash__(self):
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   510
        try:
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   511
            return hash((self._path, self._filenode))
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   512
        except AttributeError:
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   513
            return id(self)
fe50d21be01a basefilectx: move __hash__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19580
diff changeset
   514
19582
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   515
    def __eq__(self, other):
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   516
        try:
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   517
            return (type(self) == type(other) and self._path == other._path
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   518
                    and self._filenode == other._filenode)
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   519
        except AttributeError:
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   520
            return False
bda1d48bb07f basefilectx: move __eq__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19581
diff changeset
   521
19583
e5074d82afc9 basefilectx: move __ne__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19582
diff changeset
   522
    def __ne__(self, other):
e5074d82afc9 basefilectx: move __ne__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19582
diff changeset
   523
        return not (self == other)
e5074d82afc9 basefilectx: move __ne__ from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19582
diff changeset
   524
19584
fe300e63c28c basefilectx: move filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19583
diff changeset
   525
    def filerev(self):
fe300e63c28c basefilectx: move filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19583
diff changeset
   526
        return self._filerev
19585
8e553cd6071e basefilectx: move filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19584
diff changeset
   527
    def filenode(self):
8e553cd6071e basefilectx: move filenode from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19584
diff changeset
   528
        return self._filenode
19586
43f9ed2f64b1 basefilectx: move flags from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19585
diff changeset
   529
    def flags(self):
43f9ed2f64b1 basefilectx: move flags from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19585
diff changeset
   530
        return self._changectx.flags(self._path)
19587
b1c344ebd8e4 basefilectx: move filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19586
diff changeset
   531
    def filelog(self):
b1c344ebd8e4 basefilectx: move filelog from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19586
diff changeset
   532
        return self._filelog
19588
a192fff6c97d basefilectx: move rev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19587
diff changeset
   533
    def rev(self):
a192fff6c97d basefilectx: move rev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19587
diff changeset
   534
        return self._changeid
19589
6a9043fa06d0 basefilectx: move linkrev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19588
diff changeset
   535
    def linkrev(self):
6a9043fa06d0 basefilectx: move linkrev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19588
diff changeset
   536
        return self._filelog.linkrev(self._filerev)
19590
90994b176bc1 basefilectx: move node from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19589
diff changeset
   537
    def node(self):
90994b176bc1 basefilectx: move node from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19589
diff changeset
   538
        return self._changectx.node()
19591
04fbc85f870a basefilectx: move hex from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19590
diff changeset
   539
    def hex(self):
04fbc85f870a basefilectx: move hex from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19590
diff changeset
   540
        return self._changectx.hex()
19592
1cdb3b3df4df basefilectx: move user from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19591
diff changeset
   541
    def user(self):
1cdb3b3df4df basefilectx: move user from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19591
diff changeset
   542
        return self._changectx.user()
19593
e3c241c89350 basefilectx: move date from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19592
diff changeset
   543
    def date(self):
e3c241c89350 basefilectx: move date from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19592
diff changeset
   544
        return self._changectx.date()
19594
1c030c24e196 basefilectx: move files from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19593
diff changeset
   545
    def files(self):
1c030c24e196 basefilectx: move files from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19593
diff changeset
   546
        return self._changectx.files()
19595
bb6fd06975a6 basefilectx: move description from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19594
diff changeset
   547
    def description(self):
bb6fd06975a6 basefilectx: move description from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19594
diff changeset
   548
        return self._changectx.description()
19596
9bc3d0dea371 basefilectx: move branch from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19595
diff changeset
   549
    def branch(self):
9bc3d0dea371 basefilectx: move branch from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19595
diff changeset
   550
        return self._changectx.branch()
19597
837bc86370f0 basefilectx: move extra from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19596
diff changeset
   551
    def extra(self):
837bc86370f0 basefilectx: move extra from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19596
diff changeset
   552
        return self._changectx.extra()
19598
e8ef893a3150 basefilectx: move phase from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19597
diff changeset
   553
    def phase(self):
e8ef893a3150 basefilectx: move phase from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19597
diff changeset
   554
        return self._changectx.phase()
19599
66d83efac20a basefilectx: move phasestr from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19598
diff changeset
   555
    def phasestr(self):
66d83efac20a basefilectx: move phasestr from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19598
diff changeset
   556
        return self._changectx.phasestr()
19600
12cdff44fdc4 basefilectx: move manifest from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19599
diff changeset
   557
    def manifest(self):
12cdff44fdc4 basefilectx: move manifest from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19599
diff changeset
   558
        return self._changectx.manifest()
19601
f284907631f5 basefilectx: move changectx from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19600
diff changeset
   559
    def changectx(self):
f284907631f5 basefilectx: move changectx from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19600
diff changeset
   560
        return self._changectx
19584
fe300e63c28c basefilectx: move filerev from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19583
diff changeset
   561
19602
018ee491a6be basefilectx: move path from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19601
diff changeset
   562
    def path(self):
018ee491a6be basefilectx: move path from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19601
diff changeset
   563
        return self._path
018ee491a6be basefilectx: move path from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19601
diff changeset
   564
19603
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   565
    def isbinary(self):
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   566
        try:
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   567
            return util.binary(self.data())
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   568
        except IOError:
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   569
            return False
a92302f48a56 basefilectx: move isbinary from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19602
diff changeset
   570
19604
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   571
    def cmp(self, fctx):
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   572
        """compare with other file context
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   573
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   574
        returns True if different than fctx.
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   575
        """
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   576
        if (fctx._filerev is None
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   577
            and (self._repo._encodefilterpats
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   578
                 # if file data starts with '\1\n', empty metadata block is
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   579
                 # prepended, which adds 4 bytes to filelog.size().
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   580
                 or self.size() - 4 == fctx.size())
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   581
            or self.size() == fctx.size()):
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   582
            return self._filelog.cmp(self._filenode, fctx.data())
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   583
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   584
        return True
ef7c47e4002f basefilectx: move cmp from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19603
diff changeset
   585
19605
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   586
    def parents(self):
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   587
        p = self._path
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   588
        fl = self._filelog
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   589
        pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)]
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   590
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   591
        r = self._filelog.renamed(self._filenode)
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   592
        if r:
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   593
            pl[0] = (r[0], r[1], None)
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   594
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   595
        return [filectx(self._repo, p, fileid=n, filelog=l)
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   596
                for p, n, l in pl if n != nullid]
cf7322cb1c13 basefilectx: move parents from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19604
diff changeset
   597
19606
284f91230c07 basefilectx: move p1 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19605
diff changeset
   598
    def p1(self):
284f91230c07 basefilectx: move p1 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19605
diff changeset
   599
        return self.parents()[0]
284f91230c07 basefilectx: move p1 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19605
diff changeset
   600
19607
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   601
    def p2(self):
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   602
        p = self.parents()
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   603
        if len(p) == 2:
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   604
            return p[1]
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   605
        return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
056a949799ac basefilectx: move p2 from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19606
diff changeset
   606
15528
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   607
    def annotate(self, follow=False, linenumber=None, diffopts=None):
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   608
        '''returns a list of tuples of (ctx, line) for each line
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   609
        in the file, where ctx is the filectx of the node where
4856
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   610
        that line was last changed.
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   611
        This returns tuples of ((ctx, linenumber), line) for each line,
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   612
        if "linenumber" parameter is NOT "None".
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   613
        In such tuples, linenumber means one at the first appearance
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   614
        in the managed file.
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   615
        To reduce annotation cost,
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   616
        this returns fixed value(False is used) as linenumber,
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   617
        if "linenumber" parameter is "False".'''
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   618
4856
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   619
        def decorate_compat(text, rev):
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   620
            return ([rev] * len(text.splitlines()), text)
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   621
4856
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   622
        def without_linenumber(text, rev):
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   623
            return ([(rev, False)] * len(text.splitlines()), text)
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   624
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   625
        def with_linenumber(text, rev):
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   626
            size = len(text.splitlines())
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   627
            return ([(rev, i) for i in xrange(1, size + 1)], text)
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   628
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   629
        decorate = (((linenumber is None) and decorate_compat) or
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   630
                    (linenumber and with_linenumber) or
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   631
                    without_linenumber)
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   632
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   633
        def pair(parent, child):
15528
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   634
            blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts,
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   635
                                     refine=True)
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   636
            for (a1, a2, b1, b2), t in blocks:
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   637
                # Changed blocks ('!') or blocks made only of blank lines ('~')
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   638
                # belong to the child.
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   639
                if t == '=':
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   640
                    child[0][b1:b2] = parent[0][a1:a2]
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   641
            return child
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   642
9097
431462bd8478 fix memory usage of revlog caches by limiting cache size [issue1639]
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   643
        getlog = util.lrucachefunc(lambda x: self._repo.file(x))
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   644
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   645
        def parents(f):
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   646
            pl = f.parents()
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   647
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   648
            # Don't return renamed parents if we aren't following.
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   649
            if not follow:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   650
                pl = [p for p in pl if p.path() == f.path()]
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   651
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   652
            # renamed filectx won't have a filelog yet, so set it
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   653
            # from the cache to save time
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   654
            for p in pl:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   655
                if not '_filelog' in p.__dict__:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   656
                    p._filelog = getlog(p.path())
3146
e69a0cbe268e filectx.annotate: return filectx for each line instead of rev
Brendan Cully <brendan@kublai.com>
parents: 3144
diff changeset
   657
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   658
            return pl
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   659
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   660
        # use linkrev to find the first changeset where self appeared
5811
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   661
        if self.rev() != self.linkrev():
19314
bc82abe500a9 filectx: remove dependencies on filerev
Durham Goode <durham@fb.com>
parents: 19292
diff changeset
   662
            base = self.filectx(self.filenode())
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   663
        else:
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   664
            base = self
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   665
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   666
        # This algorithm would prefer to be recursive, but Python is a
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   667
        # bit recursion-hostile. Instead we do an iterative
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   668
        # depth-first search.
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   669
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   670
        visit = [base]
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   671
        hist = {}
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   672
        pcache = {}
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   673
        needed = {base: 1}
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   674
        while visit:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   675
            f = visit[-1]
18993
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   676
            pcached = f in pcache
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   677
            if not pcached:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   678
                pcache[f] = parents(f)
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   679
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   680
            ready = True
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   681
            pl = pcache[f]
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   682
            for p in pl:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   683
                if p not in hist:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   684
                    ready = False
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   685
                    visit.append(p)
18993
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   686
                if not pcached:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   687
                    needed[p] = needed.get(p, 0) + 1
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   688
            if ready:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   689
                visit.pop()
18992
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   690
                reusable = f in hist
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   691
                if reusable:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   692
                    curr = hist[f]
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   693
                else:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   694
                    curr = decorate(f.data(), f)
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   695
                for p in pl:
18992
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   696
                    if not reusable:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   697
                        curr = pair(hist[p], curr)
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   698
                    if needed[p] == 1:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   699
                        del hist[p]
19061
36067f5baf24 annotate: discard refcount of discarded annotation for memory efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18993
diff changeset
   700
                        del needed[p]
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   701
                    else:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   702
                        needed[p] -= 1
6762
f67d1468ac50 util: add sort helper
Matt Mackall <mpm@selenic.com>
parents: 6760
diff changeset
   703
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   704
                hist[f] = curr
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   705
                pcache[f] = []
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   706
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   707
        return zip(hist[base][0], hist[base][1].splitlines(True))
3124
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   708
19610
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   709
    def ancestors(self, followfirst=False):
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   710
        visit = {}
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   711
        c = self
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   712
        cut = followfirst and 1 or None
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   713
        while True:
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   714
            for parent in c.parents()[:cut]:
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   715
                visit[(parent.rev(), parent.node())] = parent
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   716
            if not visit:
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   717
                break
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   718
            c = visit.pop(max(visit))
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   719
            yield c
0670422d58c6 basefilectx: move ancestors from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19609
diff changeset
   720
19608
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   721
class filectx(basefilectx):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   722
    """A filecontext object makes access to data related to a particular
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   723
       filerevision convenient."""
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   724
    def __init__(self, repo, path, changeid=None, fileid=None,
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   725
                 filelog=None, changectx=None):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   726
        """changeid can be a changeset revision, node, or tag.
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   727
           fileid can be a file revision or node."""
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   728
        self._repo = repo
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   729
        self._path = path
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   730
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   731
        assert (changeid is not None
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   732
                or fileid is not None
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   733
                or changectx is not None), \
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   734
                ("bad args: changeid=%r, fileid=%r, changectx=%r"
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   735
                 % (changeid, fileid, changectx))
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   736
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   737
        if filelog is not None:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   738
            self._filelog = filelog
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   739
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   740
        if changeid is not None:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   741
            self._changeid = changeid
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   742
        if changectx is not None:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   743
            self._changectx = changectx
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   744
        if fileid is not None:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   745
            self._fileid = fileid
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   746
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   747
    @propertycache
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   748
    def _changectx(self):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   749
        try:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   750
            return changectx(self._repo, self._changeid)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   751
        except error.RepoLookupError:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   752
            # Linkrev may point to any revision in the repository.  When the
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   753
            # repository is filtered this may lead to `filectx` trying to build
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   754
            # `changectx` for filtered revision. In such case we fallback to
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   755
            # creating `changectx` on the unfiltered version of the reposition.
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   756
            # This fallback should not be an issue because `changectx` from
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   757
            # `filectx` are not used in complex operations that care about
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   758
            # filtering.
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   759
            #
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   760
            # This fallback is a cheap and dirty fix that prevent several
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   761
            # crashes. It does not ensure the behavior is correct. However the
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   762
            # behavior was not correct before filtering either and "incorrect
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   763
            # behavior" is seen as better as "crash"
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   764
            #
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   765
            # Linkrevs have several serious troubles with filtering that are
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   766
            # complicated to solve. Proper handling of the issue here should be
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   767
            # considered when solving linkrev issue are on the table.
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   768
            return changectx(self._repo.unfiltered(), self._changeid)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   769
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   770
    def filectx(self, fileid):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   771
        '''opens an arbitrary revision of the file without
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   772
        opening a new filelog'''
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   773
        return filectx(self._repo, self._path, fileid=fileid,
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   774
                       filelog=self._filelog)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   775
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   776
    def data(self):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   777
        return self._filelog.read(self._filenode)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   778
    def size(self):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   779
        return self._filelog.size(self._filerev)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   780
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   781
    def renamed(self):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   782
        """check if file was actually renamed in this changeset revision
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   783
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   784
        If rename logged in file revision, we report copy for changeset only
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   785
        if file revisions linkrev points back to the changeset in question
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   786
        or both changeset parents contain different file revisions.
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   787
        """
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   788
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   789
        renamed = self._filelog.renamed(self._filenode)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   790
        if not renamed:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   791
            return renamed
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   792
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   793
        if self.rev() == self.linkrev():
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   794
            return renamed
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   795
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   796
        name = self.path()
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   797
        fnode = self._filenode
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   798
        for p in self._changectx.parents():
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   799
            try:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   800
                if fnode == p.filenode(name):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   801
                    return None
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   802
            except error.LookupError:
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   803
                pass
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   804
        return renamed
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   805
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   806
    def children(self):
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   807
        # hard for renames
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   808
        c = self._filelog.children(self._filenode)
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   809
        return [filectx(self._repo, self._path, fileid=x,
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   810
                        filelog=self._filelog) for x in c]
896193a9cab4 basefilectx: move annotate from filectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19607
diff changeset
   811
19733
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
   812
class committablectx(basectx):
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
   813
    """A committablectx object provides common functionality for a context that
19664
61dcb2aa7378 commitablectx: add a class that will be used as a parent of mutable contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19663
diff changeset
   814
    wants the ability to commit, e.g. workingctx or memctx."""
61dcb2aa7378 commitablectx: add a class that will be used as a parent of mutable contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19663
diff changeset
   815
    def __init__(self, repo, text="", user=None, date=None, extra=None,
61dcb2aa7378 commitablectx: add a class that will be used as a parent of mutable contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19663
diff changeset
   816
                 changes=None):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   817
        self._repo = repo
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   818
        self._rev = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   819
        self._node = None
6709
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   820
        self._text = text
6718
4386a7706828 Fix commit date (issue1193)
Christian Ebert <blacktrash@gmx.net>
parents: 6715
diff changeset
   821
        if date:
6709
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   822
            self._date = util.parsedate(date)
6817
cf319797d61c minor status fixups
Matt Mackall <mpm@selenic.com>
parents: 6809
diff changeset
   823
        if user:
cf319797d61c minor status fixups
Matt Mackall <mpm@selenic.com>
parents: 6809
diff changeset
   824
            self._user = user
6707
02bad34230a2 localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6705
diff changeset
   825
        if changes:
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   826
            self._status = list(changes[:4])
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   827
            self._unknown = changes[4]
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   828
            self._ignored = changes[5]
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   829
            self._clean = changes[6]
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   830
        else:
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   831
            self._unknown = None
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   832
            self._ignored = None
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   833
            self._clean = None
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   834
6708
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   835
        self._extra = {}
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   836
        if extra:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   837
            self._extra = extra.copy()
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   838
        if 'branch' not in self._extra:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   839
            try:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
   840
                branch = encoding.fromlocal(self._repo.dirstate.branch())
6708
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   841
            except UnicodeDecodeError:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   842
                raise util.Abort(_('branch name not in UTF-8!'))
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   843
            self._extra['branch'] = branch
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   844
        if self._extra['branch'] == '':
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   845
            self._extra['branch'] = 'default'
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   846
19666
09459edfb48b commitablectx: move __str__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19665
diff changeset
   847
    def __str__(self):
09459edfb48b commitablectx: move __str__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19665
diff changeset
   848
        return str(self._parents[0]) + "+"
09459edfb48b commitablectx: move __str__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19665
diff changeset
   849
19667
40040e4015f9 commitablectx: move __nonzero__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19666
diff changeset
   850
    def __nonzero__(self):
40040e4015f9 commitablectx: move __nonzero__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19666
diff changeset
   851
        return True
40040e4015f9 commitablectx: move __nonzero__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19666
diff changeset
   852
19668
9d56a3359011 commitablectx: move __contains__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19667
diff changeset
   853
    def __contains__(self, key):
9d56a3359011 commitablectx: move __contains__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19667
diff changeset
   854
        return self._repo.dirstate[key] not in "?r"
9d56a3359011 commitablectx: move __contains__ from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19667
diff changeset
   855
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   856
    def _buildflagfunc(self):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   857
        # Create a fallback function for getting file flags when the
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   858
        # filesystem doesn't support them
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   859
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   860
        copiesget = self._repo.dirstate.copies().get
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   861
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   862
        if len(self._parents) < 2:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   863
            # when we have one parent, it's easy: copy from parent
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   864
            man = self._parents[0].manifest()
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   865
            def func(f):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   866
                f = copiesget(f, f)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   867
                return man.flags(f)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   868
        else:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   869
            # merges are tricky: we try to reconstruct the unstored
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   870
            # result from the merge (issue1802)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   871
            p1, p2 = self._parents
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   872
            pa = p1.ancestor(p2)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   873
            m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   874
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   875
            def func(f):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   876
                f = copiesget(f, f) # may be wrong for merges with copies
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   877
                fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   878
                if fl1 == fl2:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   879
                    return fl1
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   880
                if fl1 == fla:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   881
                    return fl2
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   882
                if fl2 == fla:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   883
                    return fl1
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   884
                return '' # punt for conflicts
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   885
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   886
        return func
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   887
19670
6ac735fbea50 commitablectx: move _flagfunc from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19669
diff changeset
   888
    @propertycache
6ac735fbea50 commitablectx: move _flagfunc from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19669
diff changeset
   889
    def _flagfunc(self):
6ac735fbea50 commitablectx: move _flagfunc from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19669
diff changeset
   890
        return self._repo.dirstate.flagfunc(self._buildflagfunc)
6ac735fbea50 commitablectx: move _flagfunc from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19669
diff changeset
   891
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   892
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   893
    def _manifest(self):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   894
        """generate a manifest corresponding to the working directory"""
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   895
3218
8d4855fd9d7b merge: use new working context object in update
Matt Mackall <mpm@selenic.com>
parents: 3217
diff changeset
   896
        man = self._parents[0].manifest().copy()
10921
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   897
        if len(self._parents) > 1:
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   898
            man2 = self.p2().manifest()
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   899
            def getman(f):
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   900
                if f in man:
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   901
                    return man
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   902
                return man2
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   903
        else:
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   904
            getman = lambda f: man
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   905
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   906
        copied = self._repo.dirstate.copies()
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   907
        ff = self._flagfunc
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   908
        modified, added, removed, deleted = self._status
16094
0776a6cababe merge: don't use unknown()
Matt Mackall <mpm@selenic.com>
parents: 15912
diff changeset
   909
        for i, l in (("a", added), ("m", modified)):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   910
            for f in l:
10921
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   911
                orig = copied.get(f, f)
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   912
                man[f] = getman(orig).get(orig, nullid) + i
3823
676b75547d13 context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents: 3715
diff changeset
   913
                try:
6743
86e8187b721a simplify flag handling
Matt Mackall <mpm@selenic.com>
parents: 6742
diff changeset
   914
                    man.set(f, ff(f))
3823
676b75547d13 context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents: 3715
diff changeset
   915
                except OSError:
676b75547d13 context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents: 3715
diff changeset
   916
                    pass
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   917
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   918
        for f in deleted + removed:
3325
50a18815e3f0 Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 3313
diff changeset
   919
            if f in man:
50a18815e3f0 Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 3313
diff changeset
   920
                del man[f]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   921
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   922
        return man
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   923
19672
375986c02539 commitablectx: move _status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19671
diff changeset
   924
    @propertycache
375986c02539 commitablectx: move _status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19671
diff changeset
   925
    def _status(self):
375986c02539 commitablectx: move _status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19671
diff changeset
   926
        return self._repo.status()[:4]
375986c02539 commitablectx: move _status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19671
diff changeset
   927
19674
ec5b2e2b947f commitablectx: move _user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19673
diff changeset
   928
    @propertycache
ec5b2e2b947f commitablectx: move _user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19673
diff changeset
   929
    def _user(self):
ec5b2e2b947f commitablectx: move _user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19673
diff changeset
   930
        return self._repo.ui.username()
ec5b2e2b947f commitablectx: move _user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19673
diff changeset
   931
19676
103525f36337 commitablectx: move _date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19675
diff changeset
   932
    @propertycache
103525f36337 commitablectx: move _date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19675
diff changeset
   933
    def _date(self):
103525f36337 commitablectx: move _date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19675
diff changeset
   934
        return util.makedate()
103525f36337 commitablectx: move _date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19675
diff changeset
   935
19673
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   936
    def status(self, ignored=False, clean=False, unknown=False):
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   937
        """Explicit status query
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   938
        Unless this method is used to query the working copy status, the
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   939
        _status property will implicitly read the status using its default
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   940
        arguments."""
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   941
        stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown)
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   942
        self._unknown = self._ignored = self._clean = None
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   943
        if unknown:
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   944
            self._unknown = stat[4]
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   945
        if ignored:
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   946
            self._ignored = stat[5]
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   947
        if clean:
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   948
            self._clean = stat[6]
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   949
        self._status = stat[:4]
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   950
        return stat
53a3a8d38301 commitablectx: move status from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19672
diff changeset
   951
19675
84249d49f37c commitablectx: move user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19674
diff changeset
   952
    def user(self):
84249d49f37c commitablectx: move user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19674
diff changeset
   953
        return self._user or self._repo.ui.username()
19677
e11415510352 commitablectx: move date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19676
diff changeset
   954
    def date(self):
e11415510352 commitablectx: move date from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19676
diff changeset
   955
        return self._date
19678
897c2dbc0256 commitablectx: move description from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19677
diff changeset
   956
    def description(self):
897c2dbc0256 commitablectx: move description from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19677
diff changeset
   957
        return self._text
19679
f21804f1582e commitablectx: move files from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19678
diff changeset
   958
    def files(self):
f21804f1582e commitablectx: move files from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19678
diff changeset
   959
        return sorted(self._status[0] + self._status[1] + self._status[2])
19675
84249d49f37c commitablectx: move user from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19674
diff changeset
   960
19680
fc33fcfa08f2 commitablectx: move modified from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19679
diff changeset
   961
    def modified(self):
fc33fcfa08f2 commitablectx: move modified from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19679
diff changeset
   962
        return self._status[0]
19681
cfc4ae65023f commitablectx: move added from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19680
diff changeset
   963
    def added(self):
cfc4ae65023f commitablectx: move added from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19680
diff changeset
   964
        return self._status[1]
19682
42ffc7f31acf commitablectx: move removed from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19681
diff changeset
   965
    def removed(self):
42ffc7f31acf commitablectx: move removed from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19681
diff changeset
   966
        return self._status[2]
19683
6336f35ed77d commitablectx: move deleted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19682
diff changeset
   967
    def deleted(self):
6336f35ed77d commitablectx: move deleted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19682
diff changeset
   968
        return self._status[3]
19684
36cd2a7fa3f7 commitablectx: move unknown from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19683
diff changeset
   969
    def unknown(self):
36cd2a7fa3f7 commitablectx: move unknown from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19683
diff changeset
   970
        assert self._unknown is not None  # must call status first
36cd2a7fa3f7 commitablectx: move unknown from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19683
diff changeset
   971
        return self._unknown
19685
e4088cec976b commitablectx: move ignored from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19684
diff changeset
   972
    def ignored(self):
e4088cec976b commitablectx: move ignored from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19684
diff changeset
   973
        assert self._ignored is not None  # must call status first
e4088cec976b commitablectx: move ignored from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19684
diff changeset
   974
        return self._ignored
19686
e189c8ff33d3 commitablectx: move clean from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19685
diff changeset
   975
    def clean(self):
e189c8ff33d3 commitablectx: move clean from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19685
diff changeset
   976
        assert self._clean is not None  # must call status first
e189c8ff33d3 commitablectx: move clean from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19685
diff changeset
   977
        return self._clean
19687
54b3b4821bfb commitablectx: move branch from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19686
diff changeset
   978
    def branch(self):
54b3b4821bfb commitablectx: move branch from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19686
diff changeset
   979
        return encoding.tolocal(self._extra['branch'])
19688
21e1068109a7 commitablectx: move closesbranch from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19687
diff changeset
   980
    def closesbranch(self):
21e1068109a7 commitablectx: move closesbranch from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19687
diff changeset
   981
        return 'close' in self._extra
19689
8dbb66f339f3 commitablectx: move extra from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19688
diff changeset
   982
    def extra(self):
8dbb66f339f3 commitablectx: move extra from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19688
diff changeset
   983
        return self._extra
19680
fc33fcfa08f2 commitablectx: move modified from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19679
diff changeset
   984
19690
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   985
    def tags(self):
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   986
        t = []
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   987
        for p in self.parents():
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   988
            t.extend(p.tags())
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   989
        return t
65ff9fd67d8d commitablectx: move tags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19689
diff changeset
   990
19691
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   991
    def bookmarks(self):
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   992
        b = []
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   993
        for p in self.parents():
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   994
            b.extend(p.bookmarks())
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   995
        return b
33ae2052d924 commitablectx: move bookmarks from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19690
diff changeset
   996
19692
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
   997
    def phase(self):
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
   998
        phase = phases.draft # default phase to draft
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
   999
        for p in self.parents():
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
  1000
            phase = max(phase, p.phase())
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
  1001
        return phase
594f4d2b0ce9 commitablectx: move phase from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19691
diff changeset
  1002
19693
56ba14d4bc02 commitablectx: move hidden from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19692
diff changeset
  1003
    def hidden(self):
56ba14d4bc02 commitablectx: move hidden from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19692
diff changeset
  1004
        return False
56ba14d4bc02 commitablectx: move hidden from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19692
diff changeset
  1005
19694
ba4c01c34df9 commitablectx: move children from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19693
diff changeset
  1006
    def children(self):
ba4c01c34df9 commitablectx: move children from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19693
diff changeset
  1007
        return []
ba4c01c34df9 commitablectx: move children from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19693
diff changeset
  1008
19695
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1009
    def flags(self, path):
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1010
        if '_manifest' in self.__dict__:
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1011
            try:
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1012
                return self._manifest.flags(path)
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1013
            except KeyError:
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1014
                return ''
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1015
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1016
        try:
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1017
            return self._flagfunc(path)
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1018
        except OSError:
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1019
            return ''
6c52adcaba0e commitablectx: move flags from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19694
diff changeset
  1020
19696
210cc42a8ac2 commitablectx: move ancestor from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19695
diff changeset
  1021
    def ancestor(self, c2):
210cc42a8ac2 commitablectx: move ancestor from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19695
diff changeset
  1022
        """return the ancestor context of self and c2"""
210cc42a8ac2 commitablectx: move ancestor from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19695
diff changeset
  1023
        return self._parents[0].ancestor(c2) # punt on two parents for now
210cc42a8ac2 commitablectx: move ancestor from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19695
diff changeset
  1024
19697
8c95e74857c6 commitablectx: move walk from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19696
diff changeset
  1025
    def walk(self, match):
8c95e74857c6 commitablectx: move walk from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19696
diff changeset
  1026
        return sorted(self._repo.dirstate.walk(match, sorted(self.substate),
8c95e74857c6 commitablectx: move walk from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19696
diff changeset
  1027
                                               True, False))
8c95e74857c6 commitablectx: move walk from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19696
diff changeset
  1028
19698
8d4a8f4eb404 commitablectx: move ancestors from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19697
diff changeset
  1029
    def ancestors(self):
8d4a8f4eb404 commitablectx: move ancestors from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19697
diff changeset
  1030
        for a in self._repo.changelog.ancestors(
8d4a8f4eb404 commitablectx: move ancestors from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19697
diff changeset
  1031
            [p.rev() for p in self._parents]):
8d4a8f4eb404 commitablectx: move ancestors from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19697
diff changeset
  1032
            yield changectx(self._repo, a)
8d4a8f4eb404 commitablectx: move ancestors from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19697
diff changeset
  1033
19699
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1034
    def markcommitted(self, node):
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1035
        """Perform post-commit cleanup necessary after committing this ctx
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1036
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1037
        Specifically, this updates backing stores this working context
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1038
        wraps to reflect the fact that the changes reflected by this
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1039
        workingctx have been committed.  For example, it marks
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1040
        modified and added files as normal in the dirstate.
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1041
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1042
        """
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1043
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1044
        for f in self.modified() + self.added():
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1045
            self._repo.dirstate.normal(f)
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1046
        for f in self.removed():
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1047
            self._repo.dirstate.drop(f)
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1048
        self._repo.dirstate.setparents(node)
9fbc193b2358 commitablectx: move markcommitted from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19698
diff changeset
  1049
19700
8f48f5969b47 commitablectx: move dirs from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19699
diff changeset
  1050
    def dirs(self):
8f48f5969b47 commitablectx: move dirs from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19699
diff changeset
  1051
        return self._repo.dirstate.dirs()
8f48f5969b47 commitablectx: move dirs from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19699
diff changeset
  1052
19733
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
  1053
class workingctx(committablectx):
19671
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1054
    """A workingctx object makes access to data related to
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1055
    the current working directory convenient.
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1056
    date - any valid date string or (unixtime, offset), or None.
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1057
    user - username string, or None.
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1058
    extra - a dictionary of extra values, or None.
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1059
    changes - a list of file lists as returned by localrepo.status()
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1060
               or None to use the repository status.
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1061
    """
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1062
    def __init__(self, repo, text="", user=None, date=None, extra=None,
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1063
                 changes=None):
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1064
        super(workingctx, self).__init__(repo, text, user, date, extra, changes)
367e95bba6e8 commitablectx: move _manifest from workingctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19670
diff changeset
  1065
14129
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1066
    def __iter__(self):
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1067
        d = self._repo.dirstate
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1068
        for f in d:
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1069
            if d[f] != 'r':
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1070
                yield f
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
  1071
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
  1072
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1073
    def _parents(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1074
        p = self._repo.dirstate.parents()
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1075
        if p[1] == nullid:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1076
            p = p[:-1]
17330
32e9d63d9ba6 context: simplify workingctx._parents
Patrick Mezard <patrick@mezard.eu>
parents: 17207
diff changeset
  1077
        return [changectx(self._repo, x) for x in p]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1078
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
  1079
    def filectx(self, path, filelog=None):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1080
        """get a file context from the working directory"""
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
  1081
        return workingfilectx(self._repo, path, workingctx=self,
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
  1082
                              filelog=filelog)
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1083
16491
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1084
    def dirty(self, missing=False, merge=True, branch=True):
8717
e8de59577257 context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents: 8528
diff changeset
  1085
        "check whether a working directory is modified"
11110
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1086
        # check subrepos first
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18252
diff changeset
  1087
        for s in sorted(self.substate):
11110
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1088
            if self.sub(s).dirty():
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1089
                return True
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1090
        # check current working dir
16491
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1091
        return ((merge and self.p2()) or
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1092
                (branch and self.branch() != self.p1().branch()) or
8717
e8de59577257 context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents: 8528
diff changeset
  1093
                self.modified() or self.added() or self.removed() or
e8de59577257 context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents: 8528
diff changeset
  1094
                (missing and self.deleted()))
e8de59577257 context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents: 8528
diff changeset
  1095
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1096
    def add(self, list, prefix=""):
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1097
        join = lambda f: os.path.join(prefix, f)
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1098
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1099
        ui, ds = self._repo.ui, self._repo.dirstate
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1100
        try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1101
            rejected = []
19900
7c21e3398931 context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19734
diff changeset
  1102
            lstat = self._repo.wvfs.lstat
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1103
            for f in list:
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13877
diff changeset
  1104
                scmutil.checkportable(ui, join(f))
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1105
                try:
19900
7c21e3398931 context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19734
diff changeset
  1106
                    st = lstat(f)
14004
97ed99d1f419 eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents: 13962
diff changeset
  1107
                except OSError:
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1108
                    ui.warn(_("%s does not exist!\n") % join(f))
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1109
                    rejected.append(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1110
                    continue
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1111
                if st.st_size > 10000000:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1112
                    ui.warn(_("%s: up to %d MB of RAM may be required "
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1113
                              "to manage this file\n"
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1114
                              "(use 'hg revert %s' to cancel the "
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1115
                              "pending addition)\n")
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1116
                              % (f, 3 * st.st_size // 1000000, join(f)))
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1117
                if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1118
                    ui.warn(_("%s not added: only files and symlinks "
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1119
                              "supported currently\n") % join(f))
19900
7c21e3398931 context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19734
diff changeset
  1120
                    rejected.append(f)
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1121
                elif ds[f] in 'amn':
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1122
                    ui.warn(_("%s already tracked!\n") % join(f))
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1123
                elif ds[f] == 'r':
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1124
                    ds.normallookup(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1125
                else:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1126
                    ds.add(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1127
            return rejected
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1128
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1129
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1130
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1131
    def forget(self, files, prefix=""):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1132
        join = lambda f: os.path.join(prefix, f)
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1133
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1134
        try:
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1135
            rejected = []
14435
5f6090e559fa context: make forget work like commands.forget
Matt Mackall <mpm@selenic.com>
parents: 14434
diff changeset
  1136
            for f in files:
16111
131d1a09108a context: make workingctx.forget() really warn about untracked files
Patrick Mezard <patrick@mezard.eu>
parents: 15912
diff changeset
  1137
                if f not in self._repo.dirstate:
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1138
                    self._repo.ui.warn(_("%s not tracked!\n") % join(f))
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1139
                    rejected.append(f)
16111
131d1a09108a context: make workingctx.forget() really warn about untracked files
Patrick Mezard <patrick@mezard.eu>
parents: 15912
diff changeset
  1140
                elif self._repo.dirstate[f] != 'a':
131d1a09108a context: make workingctx.forget() really warn about untracked files
Patrick Mezard <patrick@mezard.eu>
parents: 15912
diff changeset
  1141
                    self._repo.dirstate.remove(f)
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1142
                else:
14434
cc8c09855d19 dirstate: rename forget to drop
Matt Mackall <mpm@selenic.com>
parents: 14429
diff changeset
  1143
                    self._repo.dirstate.drop(f)
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1144
            return rejected
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1145
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1146
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1147
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1148
    def undelete(self, list):
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1149
        pctxs = self.parents()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1150
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1151
        try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1152
            for f in list:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1153
                if self._repo.dirstate[f] != 'r':
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1154
                    self._repo.ui.warn(_("%s not removed!\n") % f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1155
                else:
12360
4ae3e5dffa60 context: fix filectx.undelete() (issue2388)
Patrick Mezard <pmezard@gmail.com>
parents: 12344
diff changeset
  1156
                    fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f]
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1157
                    t = fctx.data()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1158
                    self._repo.wwrite(f, t, fctx.flags())
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1159
                    self._repo.dirstate.normal(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1160
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1161
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1162
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1163
    def copy(self, source, dest):
19902
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1164
        try:
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1165
            st = self._repo.wvfs.lstat(dest)
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1166
        except OSError, err:
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1167
            if err.errno != errno.ENOENT:
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1168
                raise
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1169
            self._repo.ui.warn(_("%s does not exist!\n") % dest)
19902
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1170
            return
12a8bdd97b4f context: use "vfs.lstat()" to examine target path instead of "os.path.*"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19901
diff changeset
  1171
        if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1172
            self._repo.ui.warn(_("copy failed: %s is not a file or a "
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1173
                                 "symbolic link\n") % dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1174
        else:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1175
            wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1176
            try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1177
                if self._repo.dirstate[dest] in '?r':
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1178
                    self._repo.dirstate.add(dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1179
                self._repo.dirstate.copy(source, dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1180
            finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1181
                wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1182
19733
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
  1183
class committablefilectx(basefilectx):
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
  1184
    """A committablefilectx provides common functionality for a file context
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
  1185
    that wants the ability to commit, e.g. workingfilectx or memfilectx."""
19701
f0f8380ec516 commitablefilectx: add a class that will be used for mutable file contexts
Sean Farley <sean.michael.farley@gmail.com>
parents: 19700
diff changeset
  1186
    def __init__(self, repo, path, filelog=None, ctx=None):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1187
        self._repo = repo
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1188
        self._path = path
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1189
        self._changeid = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1190
        self._filerev = self._filenode = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1191
19149
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
  1192
        if filelog is not None:
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1193
            self._filelog = filelog
19702
d25fdd4c2fd1 commitablefilectx: move __init__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19701
diff changeset
  1194
        if ctx:
d25fdd4c2fd1 commitablefilectx: move __init__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19701
diff changeset
  1195
            self._changectx = ctx
d25fdd4c2fd1 commitablefilectx: move __init__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19701
diff changeset
  1196
19703
d2936bec530b commitablefilectx: move __nonzero__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19702
diff changeset
  1197
    def __nonzero__(self):
d2936bec530b commitablefilectx: move __nonzero__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19702
diff changeset
  1198
        return True
d2936bec530b commitablefilectx: move __nonzero__ from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19702
diff changeset
  1199
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1200
    def parents(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1201
        '''return parent filectxs, following copies if necessary'''
8528
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1202
        def filenode(ctx, path):
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1203
            return ctx._manifest.get(path, nullid)
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1204
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1205
        path = self._path
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1206
        fl = self._filelog
8528
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1207
        pcl = self._changectx._parents
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1208
        renamed = self.renamed()
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1209
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1210
        if renamed:
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1211
            pl = [renamed + (None,)]
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1212
        else:
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1213
            pl = [(path, filenode(pcl[0], path), fl)]
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1214
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1215
        for pc in pcl[1:]:
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1216
            pl.append((path, filenode(pc, path), fl))
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1217
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
  1218
        return [filectx(self._repo, p, fileid=n, filelog=l)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1219
                for p, n, l in pl if n != nullid]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1220
19705
79792c8ea6da commitablefilectx: move children from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19704
diff changeset
  1221
    def children(self):
79792c8ea6da commitablefilectx: move children from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19704
diff changeset
  1222
        return []
79792c8ea6da commitablefilectx: move children from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19704
diff changeset
  1223
19733
51988f008df3 context: use correct spelling of committable
Sean Farley <sean.michael.farley@gmail.com>
parents: 19705
diff changeset
  1224
class workingfilectx(committablefilectx):
19704
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1225
    """A workingfilectx object makes access to data related to a particular
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1226
       file in the working directory convenient."""
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1227
    def __init__(self, repo, path, filelog=None, workingctx=None):
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1228
        super(workingfilectx, self).__init__(repo, path, filelog, workingctx)
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1229
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1230
    @propertycache
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1231
    def _changectx(self):
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1232
        return workingctx(self._repo)
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1233
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1234
    def data(self):
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1235
        return self._repo.wread(self._path)
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1236
    def renamed(self):
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1237
        rp = self._repo.dirstate.copied(self._path)
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1238
        if not rp:
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1239
            return None
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1240
        return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
bad0bd99ac96 commitablefilectx: move parents from workingfilectx
Sean Farley <sean.michael.farley@gmail.com>
parents: 19703
diff changeset
  1241
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1242
    def size(self):
19901
4d3ce1646dfc context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19900
diff changeset
  1243
        return self._repo.wvfs.lstat(self._path).st_size
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1244
    def date(self):
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1245
        t, tz = self._changectx.date()
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1246
        try:
19901
4d3ce1646dfc context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19900
diff changeset
  1247
            return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz)
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1248
        except OSError, err:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1249
            if err.errno != errno.ENOENT:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1250
                raise
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1251
            return (t, tz)
3310
0e370798eebf context: add cmp for filectxs
Matt Mackall <mpm@selenic.com>
parents: 3302
diff changeset
  1252
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
  1253
    def cmp(self, fctx):
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
  1254
        """compare with other file context
11539
a463e3c50212 cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11538
diff changeset
  1255
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
  1256
        returns True if different than fctx.
11539
a463e3c50212 cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11538
diff changeset
  1257
        """
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 17424
diff changeset
  1258
        # fctx should be a filectx (not a workingfilectx)
11703
55a2af02e45c context: reuse filecontext.cmp in workingfilecontext.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11702
diff changeset
  1259
        # invert comparison to reuse the same code path
55a2af02e45c context: reuse filecontext.cmp in workingfilecontext.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11702
diff changeset
  1260
        return fctx.cmp(self)
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1261
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1262
class memctx(object):
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1263
    """Use memctx to perform in-memory commits via localrepo.commitctx().
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1264
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1265
    Revision information is supplied at initialization time while
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1266
    related files data and is made available through a callback
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1267
    mechanism.  'repo' is the current localrepo, 'parents' is a
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1268
    sequence of two parent revisions identifiers (pass None for every
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1269
    missing parent), 'text' is the commit message and 'files' lists
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1270
    names of files touched by the revision (normalized and relative to
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1271
    repository root).
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1272
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1273
    filectxfn(repo, memctx, path) is a callable receiving the
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1274
    repository, the current memctx object and the normalized path of
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1275
    requested file, relative to repository root. It is fired by the
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1276
    commit function for every file in 'files', but calls order is
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1277
    undefined. If the file is available in the revision being
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1278
    committed (updated or added), filectxfn returns a memfilectx
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1279
    object. If the file was removed, filectxfn raises an
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1280
    IOError. Moved files are represented by marking the source file
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1281
    removed and the new file added with copy information (see
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1282
    memfilectx).
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1283
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1284
    user receives the committer name and defaults to current
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1285
    repository username, date is the commit date in any format
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1286
    supported by util.parsedate() and defaults to current date, extra
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1287
    is a dictionary of metadata or is left empty.
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1288
    """
6721
521c6c6f3b9b kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6718
diff changeset
  1289
    def __init__(self, repo, parents, text, files, filectxfn, user=None,
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1290
                 date=None, extra=None):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1291
        self._repo = repo
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1292
        self._rev = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1293
        self._node = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1294
        self._text = text
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1295
        self._date = date and util.parsedate(date) or util.makedate()
6809
89ec85aa6cc3 context: trigger missing username warning only when necessary
Patrick Mezard <pmezard@gmail.com>
parents: 6772
diff changeset
  1296
        self._user = user
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1297
        parents = [(p or nullid) for p in parents]
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1298
        p1, p2 = parents
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6744
diff changeset
  1299
        self._parents = [changectx(self._repo, p) for p in (p1, p2)]
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8207
diff changeset
  1300
        files = sorted(set(files))
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1301
        self._status = [files, [], [], [], []]
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1302
        self._filectxfn = filectxfn
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1303
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1304
        self._extra = extra and extra.copy() or {}
14528
0bd69e37fd20 memctx: simplify constructor
Patrick Mezard <pmezard@gmail.com>
parents: 14518
diff changeset
  1305
        if self._extra.get('branch', '') == '':
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1306
            self._extra['branch'] = 'default'
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1307
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1308
    def __str__(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1309
        return str(self._parents[0]) + "+"
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1310
6763
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1311
    def __int__(self):
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1312
        return self._rev
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1313
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1314
    def __nonzero__(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1315
        return True
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1316
8401
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1317
    def __getitem__(self, key):
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1318
        return self.filectx(key)
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1319
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1320
    def p1(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1321
        return self._parents[0]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1322
    def p2(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1323
        return self._parents[1]
8406
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
  1324
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1325
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1326
        return self._user or self._repo.ui.username()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1327
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1328
        return self._date
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1329
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1330
        return self._text
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1331
    def files(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1332
        return self.modified()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1333
    def modified(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1334
        return self._status[0]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1335
    def added(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1336
        return self._status[1]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1337
    def removed(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1338
        return self._status[2]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1339
    def deleted(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1340
        return self._status[3]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1341
    def unknown(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1342
        return self._status[4]
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
  1343
    def ignored(self):
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
  1344
        return self._status[5]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1345
    def clean(self):
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
  1346
        return self._status[6]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1347
    def branch(self):
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
  1348
        return encoding.tolocal(self._extra['branch'])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1349
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1350
        return self._extra
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1351
    def flags(self, f):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1352
        return self[f].flags()
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1353
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1354
    def parents(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1355
        """return contexts for each parent changeset"""
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1356
        return self._parents
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1357
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1358
    def filectx(self, path, filelog=None):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1359
        """get a file context from the working directory"""
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1360
        return self._filectxfn(self._repo, self, path)
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1361
11151
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1362
    def commit(self):
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1363
        """commit context to the repo"""
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1364
        return self._repo.commitctx(self)
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1365
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1366
class memfilectx(object):
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1367
    """memfilectx represents an in-memory file to commit.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1368
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1369
    See memctx for more details.
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1370
    """
11151
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1371
    def __init__(self, path, data, islink=False, isexec=False, copied=None):
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1372
        """
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1373
        path is the normalized file path relative to repository root.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1374
        data is the file content as a string.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1375
        islink is True if the file is a symbolic link.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1376
        isexec is True if the file is executable.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1377
        copied is the source file path if current file was copied in the
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1378
        revision being committed, or None."""
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1379
        self._path = path
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1380
        self._data = data
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1381
        self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1382
        self._copied = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1383
        if copied:
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1384
            self._copied = (copied, nullid)
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1385
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1386
    def __nonzero__(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1387
        return True
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1388
    def __str__(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1389
        return "%s@%s" % (self.path(), self._changectx)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1390
    def path(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1391
        return self._path
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1392
    def data(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1393
        return self._data
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1394
    def flags(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1395
        return self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1396
    def isexec(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1397
        return 'x' in self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1398
    def islink(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1399
        return 'l' in self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1400
    def renamed(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1401
        return self._copied