mercurial/context.py
author Sean Farley <sean.michael.farley@gmail.com>
Sat, 13 Jul 2013 19:59:21 -0500
changeset 19537 6e3e8575276d
parent 19314 bc82abe500a9
child 19538 049d6b5a4a59
permissions -rw-r--r--
basectx: add an empty class that will be used as a parent of all contexts At the moment, there is no simple way to check if an object is a context because there is no common parent class. If there were, we could use 'isinstance' everywhere. Simply having memctx inherit from workingctx or changectx would allow the use of 'isinstance' but that could lead to some confusing situations of reading the code since we have three distinct concepts of a context: - changectx represents a changeset *already* in the repo, and is therefore immutable - workingctx represents changes on disk in the working directory - memctx represents changes solely in memory which may or may not be on disk Therefore, I propose refactoring context.py to have all three contexts inherit from a parent class 'basectx'.
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 _
15818
57241845a4bb phases: store phase values in constant instead of using raw integer
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15738
diff changeset
    10
import ancestor, mdiff, error, util, scmutil, subrepo, patch, encoding, phases
16602
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
    11
import copies
14669
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
    12
import match as matchmod
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
    13
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
    14
import obsolete as obsmod
18252
3f1552c6bf71 context: retrieve hidden from filteredrevs
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18211
diff changeset
    15
import repoview
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):
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
    27
        return super(basectx, cls).__new__(cls)
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
    28
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
    29
class changectx(basectx):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
    """A changecontext object makes access to data related to a particular
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
    31
    changeset convenient. It represents a read-only context already presnt in
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
    32
    the repo."""
6741
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
    33
    def __init__(self, repo, changeid=''):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
        """changeid is a revision number, node, or tag"""
6741
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
    35
        if changeid == '':
5918e2b79859 context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents: 6737
diff changeset
    36
            changeid = '.'
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
        self._repo = repo
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    38
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    39
        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
    40
            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
    41
                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
    42
            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
    43
                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
    44
                    _("unknown revision '%s'") % changeid)
7367
ad0eb8762458 context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7361
diff changeset
    45
            self._rev = changeid
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    46
            return
16760
ac89a23ca814 context: grudging accept longs in constructor
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
    47
        if isinstance(changeid, long):
ac89a23ca814 context: grudging accept longs in constructor
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
    48
            changeid = str(changeid)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    49
        if changeid == '.':
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    50
            self._node = repo.dirstate.p1()
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    51
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    52
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    53
        if changeid == 'null':
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    54
            self._node = nullid
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    55
            self._rev = nullrev
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    56
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    57
        if changeid == 'tip':
18464
a2e9fe93d9ea changectx: fix the handling of `tip`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18423
diff changeset
    58
            self._node = repo.changelog.tip()
a2e9fe93d9ea changectx: fix the handling of `tip`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18423
diff changeset
    59
            self._rev = repo.changelog.rev(self._node)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    60
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    61
        if len(changeid) == 20:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    62
            try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    63
                self._node = changeid
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    64
                self._rev = repo.changelog.rev(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    65
                return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    66
            except LookupError:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    67
                pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    68
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    69
        try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    70
            r = int(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    71
            if str(r) != changeid:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    72
                raise ValueError
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    73
            l = len(repo.changelog)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    74
            if r < 0:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    75
                r += l
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    76
            if r < 0 or r >= l:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    77
                raise ValueError
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    78
            self._rev = r
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    79
            self._node = repo.changelog.node(r)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    80
            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
    81
        except (ValueError, OverflowError, IndexError):
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    82
            pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    83
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    84
        if len(changeid) == 40:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    85
            try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    86
                self._node = bin(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    87
                self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    88
                return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    89
            except (TypeError, LookupError):
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    90
                pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    91
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    92
        if changeid in repo._bookmarks:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    93
            self._node = repo._bookmarks[changeid]
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    94
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    95
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    96
        if changeid in repo._tagscache.tags:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    97
            self._node = repo._tagscache.tags[changeid]
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    98
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
    99
            return
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   100
        try:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   101
            self._node = repo.branchtip(changeid)
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   102
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   103
            return
16719
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   104
        except error.RepoLookupError:
e7bf09acd410 localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   105
            pass
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   106
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   107
        self._node = repo.changelog._partialmatch(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   108
        if self._node is not None:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   109
            self._rev = repo.changelog.rev(self._node)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   110
            return
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   111
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   112
        # lookup failed
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   113
        # 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
   114
        #
aba3c161bcc6 clfilter: prevent unwanted warning about filtered parents as unknown
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17832
diff changeset
   115
        # 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
   116
        # 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
   117
        if changeid in repo.unfiltered().dirstate.parents():
16376
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   118
            raise error.Abort(_("working directory has unknown parent '%s'!")
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   119
                              % short(changeid))
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   120
        try:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   121
            if len(changeid) == 20:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   122
                changeid = hex(changeid)
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   123
        except TypeError:
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   124
            pass
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   125
        raise error.RepoLookupError(
d3908c911d5e context: internalize lookup logic
Matt Mackall <mpm@selenic.com>
parents: 16373
diff changeset
   126
            _("unknown revision '%s'") % changeid)
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   127
3166
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   128
    def __str__(self):
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   129
        return short(self.node())
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   130
6763
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
   131
    def __int__(self):
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
   132
        return self.rev()
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
   133
3151
6719b3dd7d50 context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents: 3150
diff changeset
   134
    def __repr__(self):
3216
d865390c1781 context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents: 3215
diff changeset
   135
        return "<changectx %s>" % str(self)
3151
6719b3dd7d50 context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents: 3150
diff changeset
   136
6469
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   137
    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
   138
        try:
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   139
            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
   140
        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
   141
            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
   142
3165
e78185746554 Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents: 3152
diff changeset
   143
    def __eq__(self, other):
3715
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   144
        try:
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   145
            return self._rev == other._rev
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   146
        except AttributeError:
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   147
            return False
3165
e78185746554 Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents: 3152
diff changeset
   148
4748
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   149
    def __ne__(self, other):
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   150
        return not (self == other)
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   151
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   152
    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
   153
        return self._rev != nullrev
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   154
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   155
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   156
    def _changeset(self):
16377
f8ce254e514f context: use rev for changelog lookup
Matt Mackall <mpm@selenic.com>
parents: 16376
diff changeset
   157
        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
   158
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   159
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   160
    def _manifest(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   161
        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
   162
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   163
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   164
    def _manifestdelta(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   165
        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
   166
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   167
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   168
    def _parents(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   169
        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
   170
        if p[1] == nullrev:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   171
            p = p[:-1]
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   172
        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
   173
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents: 8717
diff changeset
   174
    @propertycache
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents: 8717
diff changeset
   175
    def substate(self):
11775
a8614c5a5e9a subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents: 11703
diff changeset
   176
        return subrepo.state(self, self._repo.ui)
8812
859f841937d0 subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents: 8717
diff changeset
   177
4909
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   178
    def __contains__(self, key):
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   179
        return key in self._manifest
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   180
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   181
    def __getitem__(self, key):
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   182
        return self.filectx(key)
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   183
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   184
    def __iter__(self):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8207
diff changeset
   185
        for f in sorted(self._manifest):
5485
8c0756f7b18b Fix context iterator.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5439
diff changeset
   186
            yield f
4909
1fd7a99d98f6 context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents: 4889
diff changeset
   187
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   188
    def changeset(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   189
        return self._changeset
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   190
    def manifest(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   191
        return self._manifest
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   192
    def manifestnode(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   193
        return self._changeset[0]
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   194
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   195
    def rev(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   196
        return self._rev
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   197
    def node(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   198
        return self._node
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   199
    def hex(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   200
        return hex(self._node)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   201
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   202
        return self._changeset[1]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   203
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   204
        return self._changeset[2]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   205
    def files(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   206
        return self._changeset[3]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   207
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   208
        return self._changeset[4]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   209
    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
   210
        return encoding.tolocal(self._changeset[5].get("branch"))
16720
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   211
    def closesbranch(self):
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   212
        return 'close' in self._changeset[5]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   213
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   214
        return self._changeset[5]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   215
    def tags(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   216
        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
   217
    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
   218
        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
   219
    def phase(self):
16657
b6081c2c4647 phases: introduce phasecache
Patrick Mezard <patrick@mezard.eu>
parents: 16610
diff changeset
   220
        return self._repo._phasecache.phase(self._repo, self._rev)
15822
d523b6e7ad26 phases: add a phasestr method on context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15818
diff changeset
   221
    def phasestr(self):
d523b6e7ad26 phases: add a phasestr method on context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15818
diff changeset
   222
        return phases.phasenames[self.phase()]
15703
2a48422e27f6 phases: add a mutable boolean property on context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15528
diff changeset
   223
    def mutable(self):
16359
a1b6a63f9f39 context: make changectx.mutable() benefit from .phase() logic
Patrick Mezard <patrick@mezard.eu>
parents: 16145
diff changeset
   224
        return self.phase() > phases.public
14644
f3a40fd7008c hidden: Add ``hidden`` method for context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 14528
diff changeset
   225
    def hidden(self):
18382
f3b21beb9802 filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents: 18364
diff changeset
   226
        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
   227
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   228
    def parents(self):
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   229
        """return contexts for each parent changeset"""
6742
2d54e7c1e69d context: clean up parents()
Matt Mackall <mpm@selenic.com>
parents: 6741
diff changeset
   230
        return self._parents
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   231
8406
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   232
    def p1(self):
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   233
        return self._parents[0]
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   234
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   235
    def p2(self):
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   236
        if len(self._parents) == 2:
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   237
            return self._parents[1]
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   238
        return changectx(self._repo, -1)
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
   239
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   240
    def children(self):
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   241
        """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
   242
        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
   243
        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
   244
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   245
    def ancestors(self):
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16761
diff changeset
   246
        for a in self._repo.changelog.ancestors([self._rev]):
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   247
            yield changectx(self._repo, a)
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   248
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   249
    def descendants(self):
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
   250
        for d in self._repo.changelog.descendants([self._rev]):
6876
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   251
            yield changectx(self._repo, d)
077f1e637cd8 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 6846
diff changeset
   252
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17055
diff changeset
   253
    def obsolete(self):
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17055
diff changeset
   254
        """True if the changeset is obsolete"""
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17792
diff changeset
   255
        return self.rev() in obsmod.getrevs(self._repo, 'obsolete')
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17055
diff changeset
   256
17173
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   257
    def extinct(self):
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   258
        """True if the changeset is extinct"""
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17792
diff changeset
   259
        return self.rev() in obsmod.getrevs(self._repo, 'extinct')
17173
c621f84dbb35 obsolete: compute extinct changesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17171
diff changeset
   260
17171
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17118
diff changeset
   261
    def unstable(self):
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17118
diff changeset
   262
        """True if the changeset is not obsolete but it's ancestor are"""
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17792
diff changeset
   263
        return self.rev() in obsmod.getrevs(self._repo, 'unstable')
17171
9c750c3e4fac obsolete: compute unstable changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17118
diff changeset
   264
17832
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   265
    def bumped(self):
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   266
        """True if the changeset try to be a successor of a public changeset
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   267
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   268
        Only non-public and non-obsolete changesets may be bumped.
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   269
        """
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   270
        return self.rev() in obsmod.getrevs(self._repo, 'bumped')
82f1fe0308bd context: add a `bumped` method to `changectx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17825
diff changeset
   271
18072
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   272
    def divergent(self):
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   273
        """Is a successors of a changeset with multiple possible successors set
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   274
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   275
        Only non-public and non-obsolete changesets may be divergent.
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   276
        """
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   277
        return self.rev() in obsmod.getrevs(self._repo, 'divergent')
03604f46d48a obsolete: add a divergent method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18036
diff changeset
   278
18160
dc526561111c obsolete: introduce a troubled method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18084
diff changeset
   279
    def troubled(self):
dc526561111c obsolete: introduce a troubled method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18084
diff changeset
   280
        """True if the changeset is either unstable, bumped or divergent"""
dc526561111c obsolete: introduce a troubled method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18084
diff changeset
   281
        return self.unstable() or self.bumped() or self.divergent()
dc526561111c obsolete: introduce a troubled method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18084
diff changeset
   282
18161
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   283
    def troubles(self):
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   284
        """return the list of troubles affecting this changesets.
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   285
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   286
        Troubles are returned as strings. possible values are:
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   287
        - unstable,
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   288
        - bumped,
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   289
        - divergent.
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   290
        """
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   291
        troubles = []
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   292
        if self.unstable():
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   293
            troubles.append('unstable')
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   294
        if self.bumped():
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   295
            troubles.append('bumped')
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   296
        if self.divergent():
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   297
            troubles.append('divergent')
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   298
        return troubles
5b117f82cbdb obsolete: introduce a troubles method on context
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18160
diff changeset
   299
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   300
    def _fileinfo(self, path):
3336
e44eadc92ec4 context: check self.__dict__ instead of using hasattr
Brendan Cully <brendan@kublai.com>
parents: 3313
diff changeset
   301
        if '_manifest' in self.__dict__:
3242
1539f788e913 Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents: 3241
diff changeset
   302
            try:
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   303
                return self._manifest[path], self._manifest.flags(path)
3242
1539f788e913 Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents: 3241
diff changeset
   304
            except KeyError:
18855
50c922c1b514 hgweb: show correct error message for i18n environment
Takumi IINO <trot.thunder@gmail.com>
parents: 18464
diff changeset
   305
                raise error.ManifestLookupError(self._node, path,
50c922c1b514 hgweb: show correct error message for i18n environment
Takumi IINO <trot.thunder@gmail.com>
parents: 18464
diff changeset
   306
                                                _('not found in manifest'))
3337
b02e60097bbe changectx: search manifest delta for filenode
Brendan Cully <brendan@kublai.com>
parents: 3336
diff changeset
   307
        if '_manifestdelta' in self.__dict__ or path in self.files():
b02e60097bbe changectx: search manifest delta for filenode
Brendan Cully <brendan@kublai.com>
parents: 3336
diff changeset
   308
            if path in self._manifestdelta:
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16657
diff changeset
   309
                return (self._manifestdelta[path],
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16657
diff changeset
   310
                        self._manifestdelta.flags(path))
3215
931288cf58a7 contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents: 3214
diff changeset
   311
        node, flag = self._repo.manifest.find(self._changeset[0], path)
3242
1539f788e913 Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents: 3241
diff changeset
   312
        if not node:
18855
50c922c1b514 hgweb: show correct error message for i18n environment
Takumi IINO <trot.thunder@gmail.com>
parents: 18464
diff changeset
   313
            raise error.ManifestLookupError(self._node, path,
50c922c1b514 hgweb: show correct error message for i18n environment
Takumi IINO <trot.thunder@gmail.com>
parents: 18464
diff changeset
   314
                                            _('not found in manifest'))
3242
1539f788e913 Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents: 3241
diff changeset
   315
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   316
        return node, flag
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   317
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   318
    def filenode(self, path):
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   319
        return self._fileinfo(path)[0]
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   320
6743
86e8187b721a simplify flag handling
Matt Mackall <mpm@selenic.com>
parents: 6742
diff changeset
   321
    def flags(self, path):
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   322
        try:
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   323
            return self._fileinfo(path)[1]
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7516
diff changeset
   324
        except error.LookupError:
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
   325
            return ''
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   326
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
   327
    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
   328
        """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
   329
        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
   330
            fileid = self.filenode(path)
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
   331
        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
   332
                       changectx=self, filelog=filelog)
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   333
3125
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   334
    def ancestor(self, c2):
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   335
        """
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   336
        return the ancestor context of self and c2
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   337
        """
9843
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   338
        # deal with workingctxs
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   339
        n2 = c2._node
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 13001
diff changeset
   340
        if n2 is None:
9843
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   341
            n2 = c2._parents[0]._node
d1043c2ffe6c merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9751
diff changeset
   342
        n = self._repo.changelog.ancestor(self._node, n2)
3125
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   343
        return changectx(self._repo, n)
02b22fefc01f changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents: 3124
diff changeset
   344
17626
3a524b647897 context: add "descendant()" to changectx for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17469
diff changeset
   345
    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
   346
        """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
   347
        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
   348
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   349
    def walk(self, match):
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   350
        fset = set(match.files())
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   351
        # for dirstate.walk, files=['.'] means "walk the whole tree".
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   352
        # follow that here, too
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   353
        fset.discard('.')
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   354
        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
   355
            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
   356
                # 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
   357
                fset.remove(fn)
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   358
            if match(fn):
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   359
                yield fn
8380
a00a4db76a15 context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents: 8312
diff changeset
   360
        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
   361
            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
   362
                # 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
   363
                continue
12067
a4fbbe0fbc38 Lowercase error messages
Martin Geisler <mg@lazybytes.net>
parents: 12030
diff changeset
   364
            if match.bad(fn, _('no such file in rev %s') % self) and match(fn):
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   365
                yield fn
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
   366
8813
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   367
    def sub(self, path):
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   368
        return subrepo.subrepo(self, path)
db3c1ab0e632 commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents: 8812
diff changeset
   369
14669
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
   370
    def match(self, pats=[], include=None, exclude=None, default='glob'):
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
   371
        r = self._repo
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
   372
        return matchmod.match(r.root, r.getcwd(), pats,
14674
1c151b963254 match: allow passing a context object to match core
Matt Mackall <mpm@selenic.com>
parents: 14669
diff changeset
   373
                              include, exclude, default,
1c151b963254 match: allow passing a context object to match core
Matt Mackall <mpm@selenic.com>
parents: 14669
diff changeset
   374
                              auditor=r.auditor, ctx=self)
14669
2d2604adfdd6 context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents: 14644
diff changeset
   375
11106
213ca9ffcddb changectx: change diff() to accept keyword opts
Steve Borho <steve@borho.org>
parents: 11105
diff changeset
   376
    def diff(self, ctx2=None, match=None, **opts):
11097
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   377
        """Returns a diff generator for the given contexts and matcher"""
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   378
        if ctx2 is None:
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   379
            ctx2 = self.p1()
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   380
        if ctx2 is not None and not isinstance(ctx2, changectx):
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   381
            ctx2 = self._repo[ctx2]
11105
6f4543842795 changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents: 11101
diff changeset
   382
        diffopts = patch.diffopts(self._repo.ui, opts)
6f4543842795 changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents: 11101
diff changeset
   383
        return patch.diff(self._repo, ctx2.node(), self.node(),
6f4543842795 changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents: 11101
diff changeset
   384
                          match=match, opts=diffopts)
11097
9651fa5a3cbf context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents: 10969
diff changeset
   385
16143
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   386
    @propertycache
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   387
    def _dirs(self):
18899
d8ff607ef721 scmutil: use new dirs class in dirstate and context
Bryan O'Sullivan <bryano@fb.com>
parents: 18858
diff changeset
   388
        return scmutil.dirs(self._manifest)
16143
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   389
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   390
    def dirs(self):
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   391
        return self._dirs
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
   392
18036
8b846dbc57b6 merge: support calculating merge actions against non-working contexts
David Schleimer <dschleimer@fb.com>
parents: 18005
diff changeset
   393
    def dirty(self):
8b846dbc57b6 merge: support calculating merge actions against non-working contexts
David Schleimer <dschleimer@fb.com>
parents: 18005
diff changeset
   394
        return False
8b846dbc57b6 merge: support calculating merge actions against non-working contexts
David Schleimer <dschleimer@fb.com>
parents: 18005
diff changeset
   395
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   396
class filectx(object):
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   397
    """A filecontext object makes access to data related to a particular
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   398
       filerevision convenient."""
3214
696c656202a0 context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents: 3213
diff changeset
   399
    def __init__(self, repo, path, changeid=None, fileid=None,
696c656202a0 context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents: 3213
diff changeset
   400
                 filelog=None, changectx=None):
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   401
        """changeid can be a changeset revision, node, or tag.
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   402
           fileid can be a file revision or node."""
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   403
        self._repo = repo
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   404
        self._path = path
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   405
3964
2308c39b9521 make it possible to use changectx to create a filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3962
diff changeset
   406
        assert (changeid is not None
2308c39b9521 make it possible to use changectx to create a filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3962
diff changeset
   407
                or fileid is not None
9024
10532b29cdee context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents: 8813
diff changeset
   408
                or changectx is not None), \
10532b29cdee context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents: 8813
diff changeset
   409
                ("bad args: changeid=%r, fileid=%r, changectx=%r"
10532b29cdee context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents: 8813
diff changeset
   410
                 % (changeid, fileid, changectx))
2643
f23973ea3107 fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2629
diff changeset
   411
19149
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
   412
        if filelog is not None:
3124
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   413
            self._filelog = filelog
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   414
5810
124577de40a7 context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents: 5760
diff changeset
   415
        if changeid is not None:
124577de40a7 context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents: 5760
diff changeset
   416
            self._changeid = changeid
124577de40a7 context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents: 5760
diff changeset
   417
        if changectx is not None:
124577de40a7 context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents: 5760
diff changeset
   418
            self._changectx = changectx
124577de40a7 context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents: 5760
diff changeset
   419
        if fileid is not None:
3213
e8199702cf4e Make filectx lazier
Matt Mackall <mpm@selenic.com>
parents: 3209
diff changeset
   420
            self._fileid = fileid
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   421
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   422
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   423
    def _changectx(self):
18211
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   424
        try:
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   425
            return changectx(self._repo, self._changeid)
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   426
        except error.RepoLookupError:
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   427
            # Linkrev may point to any revision in the repository.  When the
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   428
            # repository is filtered this may lead to `filectx` trying to build
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   429
            # `changectx` for filtered revision. In such case we fallback to
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   430
            # creating `changectx` on the unfiltered version of the reposition.
18644
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18464
diff changeset
   431
            # This fallback should not be an issue because `changectx` from
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18464
diff changeset
   432
            # `filectx` are not used in complex operations that care about
18211
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   433
            # filtering.
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   434
            #
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   435
            # This fallback is a cheap and dirty fix that prevent several
18644
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18464
diff changeset
   436
            # crashes. It does not ensure the behavior is correct. However the
18211
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   437
            # behavior was not correct before filtering either and "incorrect
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   438
            # behavior" is seen as better as "crash"
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   439
            #
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   440
            # Linkrevs have several serious troubles with filtering that are
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   441
            # complicated to solve. Proper handling of the issue here should be
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   442
            # considered when solving linkrev issue are on the table.
518c1403838f clfilter: fallback to unfiltered version when linkrev point to filtered history
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18161
diff changeset
   443
            return changectx(self._repo.unfiltered(), self._changeid)
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   444
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   445
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   446
    def _filelog(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   447
        return self._repo.file(self._path)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   448
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   449
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   450
    def _changeid(self):
19149
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
   451
        if '_changeid' in self.__dict__:
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
   452
            return self._changeid
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
   453
        elif '_changectx' in self.__dict__:
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   454
            return self._changectx.rev()
3144
8342ad5abe0b Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents: 3143
diff changeset
   455
        else:
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   456
            return self._filelog.linkrev(self._filerev)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   457
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   458
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   459
    def _filenode(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   460
        if '_fileid' in self.__dict__:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   461
            return self._filelog.lookup(self._fileid)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   462
        else:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   463
            return self._changectx.filenode(self._path)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   464
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   465
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   466
    def _filerev(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   467
        return self._filelog.rev(self._filenode)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   468
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   469
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   470
    def _repopath(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   471
        return self._path
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   472
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   473
    def __nonzero__(self):
3712
1bd70d40ec57 context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3673
diff changeset
   474
        try:
7874
d812029cda85 cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7633
diff changeset
   475
            self._filenode
3712
1bd70d40ec57 context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3673
diff changeset
   476
            return True
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7516
diff changeset
   477
        except error.LookupError:
3712
1bd70d40ec57 context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3673
diff changeset
   478
            # file is missing
1bd70d40ec57 context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3673
diff changeset
   479
            return False
3168
05c588e1803d context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents: 3166
diff changeset
   480
3166
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   481
    def __str__(self):
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   482
        return "%s@%s" % (self.path(), short(self.node()))
ebdb3f616bc0 Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents: 3165
diff changeset
   483
3151
6719b3dd7d50 context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents: 3150
diff changeset
   484
    def __repr__(self):
3216
d865390c1781 context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents: 3215
diff changeset
   485
        return "<filectx %s>" % str(self)
3151
6719b3dd7d50 context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents: 3150
diff changeset
   486
6469
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   487
    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
   488
        try:
10942
6f26ce7ae175 filectx: _fileid isn't normalized, use _filenode instead
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10927
diff changeset
   489
            return hash((self._path, self._filenode))
6469
fb502719c75c python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents: 6286
diff changeset
   490
        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
   491
            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
   492
3165
e78185746554 Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents: 3152
diff changeset
   493
    def __eq__(self, other):
3715
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   494
        try:
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   495
            return (self._path == other._path
10942
6f26ce7ae175 filectx: _fileid isn't normalized, use _filenode instead
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10927
diff changeset
   496
                    and self._filenode == other._filenode)
3715
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   497
        except AttributeError:
6cb3aca69cdc Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents: 3712
diff changeset
   498
            return False
3165
e78185746554 Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents: 3152
diff changeset
   499
4748
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   500
    def __ne__(self, other):
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   501
        return not (self == other)
8808ea7da86b merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents: 4663
diff changeset
   502
3207
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   503
    def filectx(self, fileid):
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   504
        '''opens an arbitrary revision of the file without
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   505
        opening a new filelog'''
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   506
        return filectx(self._repo, self._path, fileid=fileid,
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   507
                       filelog=self._filelog)
0790dce2f3a8 Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents: 3172
diff changeset
   508
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   509
    def filerev(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   510
        return self._filerev
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   511
    def filenode(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   512
        return self._filenode
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   513
    def flags(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   514
        return self._changectx.flags(self._path)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   515
    def filelog(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   516
        return self._filelog
3150
a5e4c8172ace filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents: 3149
diff changeset
   517
    def rev(self):
19288
ec367f203cb5 filectx: refactor filectx.rev() to use filectx._changeid
Durham Goode <durham@fb.com>
parents: 19149
diff changeset
   518
        return self._changeid
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   519
    def linkrev(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   520
        return self._filelog.linkrev(self._filerev)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   521
    def node(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   522
        return self._changectx.node()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   523
    def hex(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   524
        return hex(self.node())
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   525
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   526
        return self._changectx.user()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   527
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   528
        return self._changectx.date()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   529
    def files(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   530
        return self._changectx.files()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   531
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   532
        return self._changectx.description()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   533
    def branch(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   534
        return self._changectx.branch()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   535
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   536
        return self._changectx.extra()
17792
a1c4b21fc1b2 phases: add a phase and phasestr method to file context
Sean Farley <sean.michael.farley@gmail.com>
parents: 17626
diff changeset
   537
    def phase(self):
a1c4b21fc1b2 phases: add a phase and phasestr method to file context
Sean Farley <sean.michael.farley@gmail.com>
parents: 17626
diff changeset
   538
        return self._changectx.phase()
a1c4b21fc1b2 phases: add a phase and phasestr method to file context
Sean Farley <sean.michael.farley@gmail.com>
parents: 17626
diff changeset
   539
    def phasestr(self):
a1c4b21fc1b2 phases: add a phase and phasestr method to file context
Sean Farley <sean.michael.farley@gmail.com>
parents: 17626
diff changeset
   540
        return self._changectx.phasestr()
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   541
    def manifest(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   542
        return self._changectx.manifest()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   543
    def changectx(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   544
        return self._changectx
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   545
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   546
    def data(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   547
        return self._filelog.read(self._filenode)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   548
    def path(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   549
        return self._path
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   550
    def size(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   551
        return self._filelog.size(self._filerev)
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   552
15738
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   553
    def isbinary(self):
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   554
        try:
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   555
            return util.binary(self.data())
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   556
        except IOError:
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   557
            return False
e86dd8dfdea0 context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents: 15707
diff changeset
   558
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
   559
    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
   560
        """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
   561
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
   562
        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
   563
        """
15848
012b285cf643 filectx: fix cmp() of file starting with '\1\n'
Yuya Nishihara <yuya@tcha.org>
parents: 15337
diff changeset
   564
        if (fctx._filerev is None
012b285cf643 filectx: fix cmp() of file starting with '\1\n'
Yuya Nishihara <yuya@tcha.org>
parents: 15337
diff changeset
   565
            and (self._repo._encodefilterpats
012b285cf643 filectx: fix cmp() of file starting with '\1\n'
Yuya Nishihara <yuya@tcha.org>
parents: 15337
diff changeset
   566
                 # if file data starts with '\1\n', empty metadata block is
15872
a3e2b9a1f063 filectx: typo in comment
Christian Ebert <blacktrash@gmx.net>
parents: 15848
diff changeset
   567
                 # prepended, which adds 4 bytes to filelog.size().
15848
012b285cf643 filectx: fix cmp() of file starting with '\1\n'
Yuya Nishihara <yuya@tcha.org>
parents: 15337
diff changeset
   568
                 or self.size() - 4 == fctx.size())
12731
95514b58709d context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents: 12709
diff changeset
   569
            or self.size() == fctx.size()):
95514b58709d context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents: 12709
diff changeset
   570
            return self._filelog.cmp(self._filenode, fctx.data())
12709
4147a292c508 filectx: use ctx.size comparisons to speed up ctx.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12361
diff changeset
   571
12731
95514b58709d context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents: 12709
diff changeset
   572
        return True
3310
0e370798eebf context: add cmp for filectxs
Matt Mackall <mpm@selenic.com>
parents: 3302
diff changeset
   573
5811
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   574
    def renamed(self):
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   575
        """check if file was actually renamed in this changeset revision
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   576
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   577
        If rename logged in file revision, we report copy for changeset only
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   578
        if file revisions linkrev points back to the changeset in question
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   579
        or both changeset parents contain different file revisions.
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   580
        """
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   581
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   582
        renamed = self._filelog.renamed(self._filenode)
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   583
        if not renamed:
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   584
            return renamed
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   585
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   586
        if self.rev() == self.linkrev():
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   587
            return renamed
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   588
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   589
        name = self.path()
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   590
        fnode = self._filenode
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   591
        for p in self._changectx.parents():
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   592
            try:
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   593
                if fnode == p.filenode(name):
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   594
                    return None
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7516
diff changeset
   595
            except error.LookupError:
5811
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   596
                pass
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   597
        return renamed
180a3eee4b75 Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5810
diff changeset
   598
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   599
    def parents(self):
3124
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   600
        p = self._path
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   601
        fl = self._filelog
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   602
        pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)]
3123
4ea58eb3f0c9 filelog: make metadata method private
Matt Mackall <mpm@selenic.com>
parents: 3122
diff changeset
   603
5813
3ef279074c77 context: fix filectx.parents() bug introduced when editing 180a3eee4b75
Patrick Mezard <pmezard@gmail.com>
parents: 5811
diff changeset
   604
        r = self._filelog.renamed(self._filenode)
3122
da85145d4571 filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents: 2859
diff changeset
   605
        if r:
3124
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   606
            pl[0] = (r[0], r[1], None)
4d021b91cb26 filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents: 3123
diff changeset
   607
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   608
        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
   609
                for p, n, l in pl if n != nullid]
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   610
13877
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   611
    def p1(self):
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   612
        return self.parents()[0]
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   613
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   614
    def p2(self):
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   615
        p = self.parents()
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   616
        if len(p) == 2:
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   617
            return p[1]
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   618
        return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
653121e6941f filectx: introduce p1/p2 convenience methods
Matt Mackall <mpm@selenic.com>
parents: 13552
diff changeset
   619
2563
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   620
    def children(self):
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   621
        # hard for renames
482c524dd9ab Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   622
        c = self._filelog.children(self._filenode)
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   623
        return [filectx(self._repo, self._path, fileid=x,
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   624
                        filelog=self._filelog) for x in c]
2566
d8560b458f76 Convert hg annotate to context api
Matt Mackall <mpm@selenic.com>
parents: 2563
diff changeset
   625
15528
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   626
    def annotate(self, follow=False, linenumber=None, diffopts=None):
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   627
        '''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
   628
        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
   629
        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
   630
        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
   631
        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
   632
        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
   633
        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
   634
        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
   635
        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
   636
        if "linenumber" parameter is "False".'''
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   637
4856
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   638
        def decorate_compat(text, rev):
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   639
            return ([rev] * len(text.splitlines()), text)
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   640
4856
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   641
        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
   642
            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
   643
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   644
        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
   645
            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
   646
            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
   647
e45c5120ca27 Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 4748
diff changeset
   648
        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
   649
                    (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
   650
                    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
   651
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   652
        def pair(parent, child):
15528
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   653
            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
   654
                                     refine=True)
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   655
            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
   656
                # 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
   657
                # belong to the child.
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   658
                if t == '=':
a84698badf0b annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents: 15453
diff changeset
   659
                    child[0][b1:b2] = parent[0][a1:a2]
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   660
            return child
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   661
9097
431462bd8478 fix memory usage of revlog caches by limiting cache size [issue1639]
Matt Mackall <mpm@selenic.com>
parents: 8813
diff changeset
   662
        getlog = util.lrucachefunc(lambda x: self._repo.file(x))
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   663
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   664
        def parents(f):
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   665
            pl = f.parents()
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   666
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   667
            # 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
   668
            if not follow:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   669
                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
   670
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   671
            # 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
   672
            # from the cache to save time
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   673
            for p in pl:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   674
                if not '_filelog' in p.__dict__:
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   675
                    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
   676
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 19288
diff changeset
   677
            return pl
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   678
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   679
        # 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
   680
        if self.rev() != self.linkrev():
19314
bc82abe500a9 filectx: remove dependencies on filerev
Durham Goode <durham@fb.com>
parents: 19292
diff changeset
   681
            base = self.filectx(self.filenode())
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   682
        else:
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   683
            base = self
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   684
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   685
        # 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
   686
        # 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
   687
        # depth-first search.
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   688
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   689
        visit = [base]
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   690
        hist = {}
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   691
        pcache = {}
3404
1a437b0f4902 Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   692
        needed = {base: 1}
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   693
        while visit:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   694
            f = visit[-1]
18993
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   695
            pcached = f in pcache
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   696
            if not pcached:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   697
                pcache[f] = parents(f)
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   698
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   699
            ready = True
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   700
            pl = pcache[f]
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   701
            for p in pl:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   702
                if p not in hist:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   703
                    ready = False
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   704
                    visit.append(p)
18993
0fd0612dc855 annotate: increase refcount of each revisions correctly (issue3841)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18992
diff changeset
   705
                if not pcached:
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   706
                    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
   707
            if ready:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   708
                visit.pop()
18992
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   709
                reusable = f in hist
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   710
                if reusable:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   711
                    curr = hist[f]
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   712
                else:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   713
                    curr = decorate(f.data(), f)
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   714
                for p in pl:
18992
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   715
                    if not reusable:
a54ddfae8907 annotate: reuse already calculated annotation
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18986
diff changeset
   716
                        curr = pair(hist[p], curr)
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   717
                    if needed[p] == 1:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   718
                        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
   719
                        del needed[p]
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   720
                    else:
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   721
                        needed[p] -= 1
6762
f67d1468ac50 util: add sort helper
Matt Mackall <mpm@selenic.com>
parents: 6760
diff changeset
   722
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   723
                hist[f] = curr
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   724
                pcache[f] = []
3172
5c93dd0ae413 Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents: 3152
diff changeset
   725
13552
7ab85fec60c3 ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents: 13481
diff changeset
   726
        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
   727
16599
4b73f4ba27ca filectx: make ancestor require actx
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
   728
    def ancestor(self, fc2, actx):
3126
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   729
        """
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   730
        find the common ancestor file context, if any, of self, and fc2
11453
2ee26044d846 context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11303
diff changeset
   731
16599
4b73f4ba27ca filectx: make ancestor require actx
Matt Mackall <mpm@selenic.com>
parents: 16491
diff changeset
   732
        actx must be the changectx of the common ancestor
11453
2ee26044d846 context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11303
diff changeset
   733
        of self's and fc2's respective changesets.
3126
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   734
        """
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   735
9751
f8ca4035a949 filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9750
diff changeset
   736
        # the easy case: no (relevant) renames
f8ca4035a949 filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents: 9750
diff changeset
   737
        if fc2.path() == self.path() and self.path() in actx:
9750
f153af9580fe merge: first part of fix for issue1327
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
   738
            return actx[self.path()]
16601
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   739
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   740
        # the next easiest cases: unambiguous predecessor (name trumps
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   741
        # history)
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   742
        if self.path() in actx and fc2.path() not in actx:
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   743
            return actx[self.path()]
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   744
        if fc2.path() in actx and self.path() not in actx:
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   745
            return actx[fc2.path()]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   746
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   747
        # prime the ancestor cache for the working directory
16601
0c98820be15c filectx: handle some other simple cases for finding merge ancestor
Matt Mackall <mpm@selenic.com>
parents: 16599
diff changeset
   748
        acache = {}
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   749
        for c in (self, fc2):
19314
bc82abe500a9 filectx: remove dependencies on filerev
Durham Goode <durham@fb.com>
parents: 19292
diff changeset
   750
            if c.filenode() is None:
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   751
                pl = [(n.path(), n.filenode()) for n in c.parents()]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   752
                acache[(c._path, None)] = pl
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   753
6286
90a4329a6b4a filectx.ancestor: use fctx._repopath to cache filelogs (issue1035)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6228
diff changeset
   754
        flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog}
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   755
        def parents(vertex):
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   756
            if vertex in acache:
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   757
                return acache[vertex]
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   758
            f, n = vertex
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   759
            if f not in flcache:
3126
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   760
                flcache[f] = self._repo.file(f)
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   761
            fl = flcache[f]
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   762
            pl = [(f, p) for p in fl.parents(n) if p != nullid]
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   763
            re = fl.renamed(n)
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   764
            if re:
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   765
                pl.append(re)
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   766
            acache[vertex] = pl
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   767
            return pl
3126
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   768
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   769
        a, b = (self._path, self._filenode), (fc2._path, fc2._filenode)
18986
2f7186400a07 ancestor: a new algorithm that is faster for nodes near tip
Bryan O'Sullivan <bryano@fb.com>
parents: 18958
diff changeset
   770
        v = ancestor.genericancestor(a, b, parents)
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   771
        if v:
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
   772
            f, n = v
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   773
            return filectx(self._repo, f, fileid=n, filelog=flcache[f])
3126
4bf2e895cf86 filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents: 3125
diff changeset
   774
3135
b1db258e875c Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents: 3134
diff changeset
   775
        return None
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   776
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16151
diff changeset
   777
    def ancestors(self, followfirst=False):
13481
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   778
        visit = {}
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   779
        c = self
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16151
diff changeset
   780
        cut = followfirst and 1 or None
13481
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   781
        while True:
16185
352053e6cd8e context: add followfirst arg to filectx and workingfilectx
Patrick Mezard <patrick@mezard.eu>
parents: 16151
diff changeset
   782
            for parent in c.parents()[:cut]:
13481
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   783
                visit[(parent.rev(), parent.node())] = parent
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   784
            if not visit:
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   785
                break
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   786
            c = visit.pop(max(visit))
4eb1e9d6a7c9 context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents: 13476
diff changeset
   787
            yield c
10262
eb243551cbd8 copies: speed up copy detection
Matt Mackall <mpm@selenic.com>
parents: 9843
diff changeset
   788
16602
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   789
    def copies(self, c2):
16610
f1745323a567 context: fix call to util.safehasattr
Idan Kamara <idankk86@gmail.com>
parents: 16602
diff changeset
   790
        if not util.safehasattr(self, "_copycache"):
16602
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   791
            self._copycache = {}
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   792
        sc2 = str(c2)
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   793
        if sc2 not in self._copycache:
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   794
            self._copycache[sc2] = copies.pathcopies(c2)
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   795
        return self._copycache[sc2]
80aef0bc5ba7 context: add copies method with caching
Matt Mackall <mpm@selenic.com>
parents: 16601
diff changeset
   796
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   797
class workingctx(changectx):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   798
    """A workingctx object makes access to data related to
6705
fec6bc978843 context: let workingctx parents be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6685
diff changeset
   799
    the current working directory convenient.
6709
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   800
    date - any valid date string or (unixtime, offset), or None.
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   801
    user - username string, or None.
6708
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   802
    extra - a dictionary of extra values, or None.
6707
02bad34230a2 localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6705
diff changeset
   803
    changes - a list of file lists as returned by localrepo.status()
02bad34230a2 localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6705
diff changeset
   804
               or None to use the repository status.
6705
fec6bc978843 context: let workingctx parents be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6685
diff changeset
   805
    """
10969
ca052b484e56 context: remove parents parameter to workingctx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10942
diff changeset
   806
    def __init__(self, repo, text="", user=None, date=None, extra=None,
ca052b484e56 context: remove parents parameter to workingctx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10942
diff changeset
   807
                 changes=None):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   808
        self._repo = repo
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   809
        self._rev = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   810
        self._node = None
6709
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   811
        self._text = text
6718
4386a7706828 Fix commit date (issue1193)
Christian Ebert <blacktrash@gmx.net>
parents: 6715
diff changeset
   812
        if date:
6709
f84f507c53d3 context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents: 6708
diff changeset
   813
            self._date = util.parsedate(date)
6817
cf319797d61c minor status fixups
Matt Mackall <mpm@selenic.com>
parents: 6809
diff changeset
   814
        if user:
cf319797d61c minor status fixups
Matt Mackall <mpm@selenic.com>
parents: 6809
diff changeset
   815
            self._user = user
6707
02bad34230a2 localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6705
diff changeset
   816
        if changes:
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   817
            self._status = list(changes[:4])
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   818
            self._unknown = changes[4]
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   819
            self._ignored = changes[5]
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   820
            self._clean = changes[6]
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   821
        else:
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   822
            self._unknown = None
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   823
            self._ignored = None
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   824
            self._clean = None
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   825
6708
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   826
        self._extra = {}
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   827
        if extra:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   828
            self._extra = extra.copy()
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   829
        if 'branch' not in self._extra:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   830
            try:
13047
6c375e07d673 branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents: 13031
diff changeset
   831
                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
   832
            except UnicodeDecodeError:
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   833
                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
   834
            self._extra['branch'] = branch
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   835
        if self._extra['branch'] == '':
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   836
            self._extra['branch'] = 'default'
7566f00a3979 localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents: 6707
diff changeset
   837
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   838
    def __str__(self):
3313
6c68bc1e7873 context: change workingctx str() from . to <node>+
Matt Mackall <mpm@selenic.com>
parents: 3310
diff changeset
   839
        return str(self._parents[0]) + "+"
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   840
12947
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
   841
    def __repr__(self):
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
   842
        return "<workingctx %s>" % str(self)
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
   843
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   844
    def __nonzero__(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   845
        return True
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   846
6771
f5d7cfcbb4d3 workingctx: add __contains__ method
Matt Mackall <mpm@selenic.com>
parents: 6764
diff changeset
   847
    def __contains__(self, key):
8061
26316dda374f context: fix workingctx.__contains__
Patrick Mezard <pmezard@gmail.com>
parents: 7633
diff changeset
   848
        return self._repo.dirstate[key] not in "?r"
6771
f5d7cfcbb4d3 workingctx: add __contains__ method
Matt Mackall <mpm@selenic.com>
parents: 6764
diff changeset
   849
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   850
    def _buildflagfunc(self):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   851
        # 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
   852
        # filesystem doesn't support them
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   853
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   854
        copiesget = self._repo.dirstate.copies().get
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   855
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   856
        if len(self._parents) < 2:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   857
            # 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
   858
            man = self._parents[0].manifest()
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   859
            def func(f):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   860
                f = copiesget(f, f)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   861
                return man.flags(f)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   862
        else:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   863
            # 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
   864
            # result from the merge (issue1802)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   865
            p1, p2 = self._parents
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   866
            pa = p1.ancestor(p2)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   867
            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
   868
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   869
            def func(f):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   870
                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
   871
                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
   872
                if fl1 == fl2:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   873
                    return fl1
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   874
                if fl1 == fla:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   875
                    return fl2
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   876
                if fl2 == fla:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   877
                    return fl1
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   878
                return '' # punt for conflicts
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   879
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   880
        return func
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   881
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   882
    @propertycache
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   883
    def _flagfunc(self):
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   884
        return self._repo.dirstate.flagfunc(self._buildflagfunc)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   885
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   886
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   887
    def _manifest(self):
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   888
        """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
   889
3218
8d4855fd9d7b merge: use new working context object in update
Matt Mackall <mpm@selenic.com>
parents: 3217
diff changeset
   890
        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
   891
        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
   892
            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
   893
            def getman(f):
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   894
                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
   895
                    return man
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   896
                return man2
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   897
        else:
fb89cd21a7a0 workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   898
            getman = lambda f: man
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   899
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   900
        copied = self._repo.dirstate.copies()
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
   901
        ff = self._flagfunc
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   902
        modified, added, removed, deleted = self._status
16094
0776a6cababe merge: don't use unknown()
Matt Mackall <mpm@selenic.com>
parents: 15912
diff changeset
   903
        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
   904
            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
   905
                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
   906
                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
   907
                try:
6743
86e8187b721a simplify flag handling
Matt Mackall <mpm@selenic.com>
parents: 6742
diff changeset
   908
                    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
   909
                except OSError:
676b75547d13 context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents: 3715
diff changeset
   910
                    pass
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   911
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   912
        for f in deleted + removed:
3325
50a18815e3f0 Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 3313
diff changeset
   913
            if f in man:
50a18815e3f0 Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 3313
diff changeset
   914
                del man[f]
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   915
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   916
        return man
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   917
14129
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   918
    def __iter__(self):
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   919
        d = self._repo.dirstate
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   920
        for f in d:
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   921
            if d[f] != 'r':
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   922
                yield f
81e6d42b3228 context: provide an efficient iterator for workingctx
Matt Mackall <mpm@selenic.com>
parents: 14004
diff changeset
   923
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   924
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   925
    def _status(self):
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   926
        return self._repo.status()[:4]
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   927
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   928
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   929
    def _user(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   930
        return self._repo.ui.username()
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   931
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   932
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   933
    def _date(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   934
        return util.makedate()
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   935
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
   936
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   937
    def _parents(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   938
        p = self._repo.dirstate.parents()
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   939
        if p[1] == nullid:
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
   940
            p = p[:-1]
17330
32e9d63d9ba6 context: simplify workingctx._parents
Patrick Mezard <patrick@mezard.eu>
parents: 17207
diff changeset
   941
        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
   942
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   943
    def status(self, ignored=False, clean=False, unknown=False):
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   944
        """Explicit status query
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   945
        Unless this method is used to query the working copy status, the
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   946
        _status property will implicitly read the status using its default
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   947
        arguments."""
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   948
        stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown)
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   949
        self._unknown = self._ignored = self._clean = None
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   950
        if unknown:
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   951
            self._unknown = stat[4]
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   952
        if ignored:
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   953
            self._ignored = stat[5]
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   954
        if clean:
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   955
            self._clean = stat[6]
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   956
        self._status = stat[:4]
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   957
        return stat
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   958
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   959
    def manifest(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   960
        return self._manifest
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   961
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   962
        return self._user or self._repo.ui.username()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   963
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   964
        return self._date
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   965
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   966
        return self._text
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   967
    def files(self):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8207
diff changeset
   968
        return sorted(self._status[0] + self._status[1] + self._status[2])
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   969
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   970
    def modified(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   971
        return self._status[0]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   972
    def added(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   973
        return self._status[1]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   974
    def removed(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   975
        return self._status[2]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   976
    def deleted(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   977
        return self._status[3]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   978
    def unknown(self):
11101
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   979
        assert self._unknown is not None  # must call status first
502474839293 context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents: 11100
diff changeset
   980
        return self._unknown
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
   981
    def ignored(self):
11100
83968ae4aaf2 context: use asserts for ignored and clean exceptions
Matt Mackall <mpm@selenic.com>
parents: 11099
diff changeset
   982
        assert self._ignored is not None  # must call status first
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   983
        return self._ignored
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   984
    def clean(self):
11100
83968ae4aaf2 context: use asserts for ignored and clean exceptions
Matt Mackall <mpm@selenic.com>
parents: 11099
diff changeset
   985
        assert self._clean is not None  # must call status first
11099
a68bd3b7c040 workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents: 11098
diff changeset
   986
        return self._clean
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   987
    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
   988
        return encoding.tolocal(self._extra['branch'])
16720
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   989
    def closesbranch(self):
e825a89de5d7 context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents: 16719
diff changeset
   990
        return 'close' in self._extra
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   991
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   992
        return self._extra
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
   993
4663
6b2e8cb39583 context: add tags() method
Matt Mackall <mpm@selenic.com>
parents: 4640
diff changeset
   994
    def tags(self):
6b2e8cb39583 context: add tags() method
Matt Mackall <mpm@selenic.com>
parents: 4640
diff changeset
   995
        t = []
13412
58c497d0e44d remove unnecessary list comprehensions
Martin Geisler <mg@aragost.com>
parents: 13384
diff changeset
   996
        for p in self.parents():
58c497d0e44d remove unnecessary list comprehensions
Martin Geisler <mg@aragost.com>
parents: 13384
diff changeset
   997
            t.extend(p.tags())
4663
6b2e8cb39583 context: add tags() method
Matt Mackall <mpm@selenic.com>
parents: 4640
diff changeset
   998
        return t
6b2e8cb39583 context: add tags() method
Matt Mackall <mpm@selenic.com>
parents: 4640
diff changeset
   999
13476
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1000
    def bookmarks(self):
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1001
        b = []
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1002
        for p in self.parents():
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1003
            b.extend(p.bookmarks())
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1004
        return b
b85a09f368bd workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents: 13468
diff changeset
  1005
15707
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1006
    def phase(self):
15818
57241845a4bb phases: store phase values in constant instead of using raw integer
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15738
diff changeset
  1007
        phase = phases.draft # default phase to draft
15707
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1008
        for p in self.parents():
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1009
            phase = max(phase, p.phase())
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1010
        return phase
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1011
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1012
    def hidden(self):
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1013
        return False
dc3eefe0c80e phases: implement ``phase()`` and ``hidden()`` method for workingctx
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15703
diff changeset
  1014
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1015
    def children(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1016
        return []
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1017
6743
86e8187b721a simplify flag handling
Matt Mackall <mpm@selenic.com>
parents: 6742
diff changeset
  1018
    def flags(self, path):
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1019
        if '_manifest' in self.__dict__:
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1020
            try:
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1021
                return self._manifest.flags(path)
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1022
            except KeyError:
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1023
                return ''
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5558
diff changeset
  1024
15337
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
  1025
        try:
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
  1026
            return self._flagfunc(path)
cf5f9df6406b windows: recompute flags when committing a merge (issue1802)
Matt Mackall <mpm@selenic.com>
parents: 14674
diff changeset
  1027
        except OSError:
5389
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1028
            return ''
26c060922085 context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents: 4909
diff changeset
  1029
3966
b4eaa68dea1b context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3965
diff changeset
  1030
    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
  1031
        """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
  1032
        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
  1033
                              filelog=filelog)
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1034
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1035
    def ancestor(self, c2):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1036
        """return the ancestor context of self and c2"""
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1037
        return self._parents[0].ancestor(c2) # punt on two parents for now
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1038
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
  1039
    def walk(self, match):
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18252
diff changeset
  1040
        return sorted(self._repo.dirstate.walk(match, sorted(self.substate),
10176
24ce8f0c0a39 dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents: 9974
diff changeset
  1041
                                               True, False))
6764
8db64464d136 context: add walk method
Matt Mackall <mpm@selenic.com>
parents: 6763
diff changeset
  1042
16491
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1043
    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
  1044
        "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
  1045
        # check subrepos first
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18252
diff changeset
  1046
        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
  1047
            if self.sub(s).dirty():
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1048
                return True
22f5ad0b5857 subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents: 11106
diff changeset
  1049
        # check current working dir
16491
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1050
        return ((merge and self.p2()) or
bfe89d65d651 update: make --check abort with dirty subrepos
Patrick Mezard <patrick@mezard.eu>
parents: 16410
diff changeset
  1051
                (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
  1052
                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
  1053
                (missing and self.deleted()))
e8de59577257 context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents: 8528
diff changeset
  1054
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1055
    def add(self, list, prefix=""):
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1056
        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
  1057
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1058
        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
  1059
        try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1060
            rejected = []
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1061
            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
  1062
                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
  1063
                p = self._repo.wjoin(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1064
                try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1065
                    st = os.lstat(p)
14004
97ed99d1f419 eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents: 13962
diff changeset
  1066
                except OSError:
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1067
                    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
  1068
                    rejected.append(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1069
                    continue
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1070
                if st.st_size > 10000000:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1071
                    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
  1072
                              "to manage this file\n"
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1073
                              "(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
  1074
                              "pending addition)\n")
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1075
                              % (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
  1076
                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
  1077
                    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
  1078
                              "supported currently\n") % join(f))
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1079
                    rejected.append(p)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1080
                elif ds[f] in 'amn':
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12070
diff changeset
  1081
                    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
  1082
                elif ds[f] == 'r':
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1083
                    ds.normallookup(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1084
                else:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1085
                    ds.add(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1086
            return rejected
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1087
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1088
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1089
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1090
    def forget(self, files, prefix=""):
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1091
        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
  1092
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1093
        try:
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15895
diff changeset
  1094
            rejected = []
14435
5f6090e559fa context: make forget work like commands.forget
Matt Mackall <mpm@selenic.com>
parents: 14434
diff changeset
  1095
            for f in files:
16111
131d1a09108a context: make workingctx.forget() really warn about untracked files
Patrick Mezard <patrick@mezard.eu>
parents: 15912
diff changeset
  1096
                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
  1097
                    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
  1098
                    rejected.append(f)
16111
131d1a09108a context: make workingctx.forget() really warn about untracked files
Patrick Mezard <patrick@mezard.eu>
parents: 15912
diff changeset
  1099
                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
  1100
                    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
  1101
                else:
14434
cc8c09855d19 dirstate: rename forget to drop
Matt Mackall <mpm@selenic.com>
parents: 14429
diff changeset
  1102
                    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
  1103
            return rejected
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1104
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1105
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1106
16410
80b3d574881f context: revert workingctx.ancestors() followfirst option
Patrick Mezard <patrick@mezard.eu>
parents: 16377
diff changeset
  1107
    def ancestors(self):
12999
acd69df118ab context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents: 12731
diff changeset
  1108
        for a in self._repo.changelog.ancestors(
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16761
diff changeset
  1109
            [p.rev() for p in self._parents]):
12999
acd69df118ab context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents: 12731
diff changeset
  1110
            yield changectx(self._repo, a)
acd69df118ab context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents: 12731
diff changeset
  1111
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1112
    def undelete(self, list):
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1113
        pctxs = self.parents()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1114
        wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1115
        try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1116
            for f in list:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1117
                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
  1118
                    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
  1119
                else:
12360
4ae3e5dffa60 context: fix filectx.undelete() (issue2388)
Patrick Mezard <pmezard@gmail.com>
parents: 12344
diff changeset
  1120
                    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
  1121
                    t = fctx.data()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1122
                    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
  1123
                    self._repo.dirstate.normal(f)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1124
        finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1125
            wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1126
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1127
    def copy(self, source, dest):
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1128
        p = self._repo.wjoin(dest)
12344
b6173aee4a47 Use lexists() instead of exists() where appropriate
Patrick Mezard <pmezard@gmail.com>
parents: 12067
diff changeset
  1129
        if not os.path.lexists(p):
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1130
            self._repo.ui.warn(_("%s does not exist!\n") % dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1131
        elif not (os.path.isfile(p) or os.path.islink(p)):
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1132
            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
  1133
                                 "symbolic link\n") % dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1134
        else:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1135
            wlock = self._repo.wlock()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1136
            try:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1137
                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
  1138
                    self._repo.dirstate.add(dest)
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1139
                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
  1140
            finally:
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1141
                wlock.release()
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11151
diff changeset
  1142
18661
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1143
    def markcommitted(self, node):
18958
c3b920980f22 spelling: fix typos and spelling errors
Mads Kiilerich <madski@unity3d.com>
parents: 18899
diff changeset
  1144
        """Perform post-commit cleanup necessary after committing this ctx
18661
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1145
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1146
        Specifically, this updates backing stores this working context
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1147
        wraps to reflect the fact that the changes reflected by this
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1148
        workingctx have been committed.  For example, it marks
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1149
        modified and added files as normal in the dirstate.
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1150
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1151
        """
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1152
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1153
        for f in self.modified() + self.added():
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1154
            self._repo.dirstate.normal(f)
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1155
        for f in self.removed():
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1156
            self._repo.dirstate.drop(f)
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1157
        self._repo.dirstate.setparents(node)
4fb92f14a97a commit: factor out post-commit cleanup into workingctx
David Schleimer <dschleimer@fb.com>
parents: 18644
diff changeset
  1158
16143
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
  1159
    def dirs(self):
18899
d8ff607ef721 scmutil: use new dirs class in dirstate and context
Bryan O'Sullivan <bryano@fb.com>
parents: 18858
diff changeset
  1160
        return self._repo.dirstate.dirs()
16143
fceb2964fa6c context: add 'dirs()' to changectx/workingctx for directory patterns
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16111
diff changeset
  1161
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1162
class workingfilectx(filectx):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1163
    """A workingfilectx object makes access to data related to a particular
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1164
       file in the working directory convenient."""
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1165
    def __init__(self, repo, path, filelog=None, workingctx=None):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1166
        """changeid can be a changeset revision, node, or tag.
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1167
           fileid can be a file revision or node."""
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1168
        self._repo = repo
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1169
        self._path = path
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1170
        self._changeid = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1171
        self._filerev = self._filenode = None
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1172
19149
921b64e1f7b9 filecontext: use 'is not None' to check for filelog existence
Durham Goode <durham@fb.com>
parents: 19061
diff changeset
  1173
        if filelog is not None:
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1174
            self._filelog = filelog
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1175
        if workingctx:
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1176
            self._changectx = workingctx
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1177
8157
77c5877a668c context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents: 8151
diff changeset
  1178
    @propertycache
7368
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1179
    def _changectx(self):
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1180
        return workingctx(self._repo)
595ba2537d4f context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7367
diff changeset
  1181
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1182
    def __nonzero__(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1183
        return True
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1184
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1185
    def __str__(self):
3313
6c68bc1e7873 context: change workingctx str() from . to <node>+
Matt Mackall <mpm@selenic.com>
parents: 3310
diff changeset
  1186
        return "%s@%s" % (self.path(), self._changectx)
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1187
12947
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
  1188
    def __repr__(self):
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
  1189
        return "<workingfilectx %s>" % str(self)
4832717aed98 context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12731
diff changeset
  1190
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1191
    def data(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1192
        return self._repo.wread(self._path)
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1193
    def renamed(self):
8528
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1194
        rp = self._repo.dirstate.copied(self._path)
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1195
        if not rp:
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1196
            return None
3965
2e5161335e65 context: fix a bug in workingfilectx.renamed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3964
diff changeset
  1197
        return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1198
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1199
    def parents(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1200
        '''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
  1201
        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
  1202
            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
  1203
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1204
        path = self._path
3217
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1205
        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
  1206
        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
  1207
        renamed = self.renamed()
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1208
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1209
        if renamed:
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1210
            pl = [renamed + (None,)]
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1211
        else:
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1212
            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
  1213
4ddffb793d18 workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8527
diff changeset
  1214
        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
  1215
            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
  1216
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3578
diff changeset
  1217
        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
  1218
                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
  1219
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1220
    def children(self):
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1221
        return []
6d98149d70fe contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents: 3216
diff changeset
  1222
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1223
    def size(self):
11605
ce95d8b87d22 context: use os.lstat instead of os.stat to fetch file size
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11539
diff changeset
  1224
        return os.lstat(self._repo.wjoin(self._path)).st_size
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1225
    def date(self):
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1226
        t, tz = self._changectx.date()
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1227
        try:
4117
eb0967c6e77b Use only integer part of mtime in workingfilectx.date(), fixes test-context.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4110
diff changeset
  1228
            return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz)
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1229
        except OSError, err:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1230
            if err.errno != errno.ENOENT:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1231
                raise
3962
2b8825c94c5a add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3961
diff changeset
  1232
            return (t, tz)
3310
0e370798eebf context: add cmp for filectxs
Matt Mackall <mpm@selenic.com>
parents: 3302
diff changeset
  1233
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
  1234
    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
  1235
        """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
  1236
11702
eb07fbc21e9c filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11605
diff changeset
  1237
        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
  1238
        """
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 17424
diff changeset
  1239
        # 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
  1240
        # 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
  1241
        return fctx.cmp(self)
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1242
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1243
class memctx(object):
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1244
    """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
  1245
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1246
    Revision information is supplied at initialization time while
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1247
    related files data and is made available through a callback
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1248
    mechanism.  'repo' is the current localrepo, 'parents' is a
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1249
    sequence of two parent revisions identifiers (pass None for every
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1250
    missing parent), 'text' is the commit message and 'files' lists
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1251
    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
  1252
    repository root).
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1253
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1254
    filectxfn(repo, memctx, path) is a callable receiving the
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1255
    repository, the current memctx object and the normalized path of
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1256
    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
  1257
    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
  1258
    undefined. If the file is available in the revision being
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1259
    committed (updated or added), filectxfn returns a memfilectx
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1260
    object. If the file was removed, filectxfn raises an
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1261
    IOError. Moved files are represented by marking the source file
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1262
    removed and the new file added with copy information (see
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1263
    memfilectx).
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1264
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1265
    user receives the committer name and defaults to current
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1266
    repository username, date is the commit date in any format
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1267
    supported by util.parsedate() and defaults to current date, extra
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1268
    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
  1269
    """
6721
521c6c6f3b9b kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6718
diff changeset
  1270
    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
  1271
                 date=None, extra=None):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1272
        self._repo = repo
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1273
        self._rev = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1274
        self._node = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1275
        self._text = text
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1276
        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
  1277
        self._user = user
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1278
        parents = [(p or nullid) for p in parents]
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1279
        p1, p2 = parents
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6744
diff changeset
  1280
        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
  1281
        files = sorted(set(files))
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1282
        self._status = [files, [], [], [], []]
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1283
        self._filectxfn = filectxfn
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1284
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1285
        self._extra = extra and extra.copy() or {}
14528
0bd69e37fd20 memctx: simplify constructor
Patrick Mezard <pmezard@gmail.com>
parents: 14518
diff changeset
  1286
        if self._extra.get('branch', '') == '':
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1287
            self._extra['branch'] = 'default'
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1288
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1289
    def __str__(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1290
        return str(self._parents[0]) + "+"
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1291
6763
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1292
    def __int__(self):
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1293
        return self._rev
403682f1c678 context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents: 6762
diff changeset
  1294
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1295
    def __nonzero__(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1296
        return True
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1297
8401
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1298
    def __getitem__(self, key):
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1299
        return self.filectx(key)
ca7dc47eecc6 filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents: 8380
diff changeset
  1300
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1301
    def p1(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1302
        return self._parents[0]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1303
    def p2(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1304
        return self._parents[1]
8406
6ad1f72bdf34 context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents: 8401
diff changeset
  1305
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1306
    def user(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1307
        return self._user or self._repo.ui.username()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1308
    def date(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1309
        return self._date
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1310
    def description(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1311
        return self._text
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1312
    def files(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1313
        return self.modified()
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1314
    def modified(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1315
        return self._status[0]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1316
    def added(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1317
        return self._status[1]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1318
    def removed(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1319
        return self._status[2]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1320
    def deleted(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1321
        return self._status[3]
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1322
    def unknown(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1323
        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
  1324
    def ignored(self):
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
  1325
        return self._status[5]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1326
    def clean(self):
11098
380ab78dbd69 workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents: 11097
diff changeset
  1327
        return self._status[6]
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1328
    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
  1329
        return encoding.tolocal(self._extra['branch'])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1330
    def extra(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1331
        return self._extra
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1332
    def flags(self, f):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1333
        return self[f].flags()
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1334
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1335
    def parents(self):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1336
        """return contexts for each parent changeset"""
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1337
        return self._parents
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1338
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1339
    def filectx(self, path, filelog=None):
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1340
        """get a file context from the working directory"""
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1341
        return self._filectxfn(self._repo, self, path)
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1342
11151
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1343
    def commit(self):
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1344
        """commit context to the repo"""
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1345
        return self._repo.commitctx(self)
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1346
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1347
class memfilectx(object):
7077
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1348
    """memfilectx represents an in-memory file to commit.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1349
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1350
    See memctx for more details.
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1351
    """
11151
c5c190822501 slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents: 11144
diff changeset
  1352
    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
  1353
        """
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1354
        path is the normalized file path relative to repository root.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1355
        data is the file content as a string.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1356
        islink is True if the file is a symbolic link.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1357
        isexec is True if the file is executable.
ccbd39cad3c3 context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents: 7008
diff changeset
  1358
        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
  1359
        revision being committed, or None."""
6715
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1360
        self._path = path
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1361
        self._data = data
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1362
        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
  1363
        self._copied = None
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1364
        if copied:
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1365
            self._copied = (copied, nullid)
a3c41abfa828 context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents: 6709
diff changeset
  1366
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1367
    def __nonzero__(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1368
        return True
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1369
    def __str__(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1370
        return "%s@%s" % (self.path(), self._changectx)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1371
    def path(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1372
        return self._path
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1373
    def data(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1374
        return self._data
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1375
    def flags(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1376
        return self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1377
    def isexec(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1378
        return 'x' in self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1379
    def islink(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1380
        return 'l' in self._flags
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1381
    def renamed(self):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
  1382
        return self._copied