hgext/git/dirstate.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 18 Apr 2022 11:21:09 -0400
changeset 49077 20d151e43429
parent 48946 642e31cb55f0
child 49078 020328be00cb
permissions -rw-r--r--
git: adapt to some recent dirstate API changes There are still old methods like add() and drop(). I don't see anything that looks equivalent, so there's likely more work to do. But this allows diff and commit to work again on the simple webpage repo for thg. Differential Revision: https://phab.mercurial-scm.org/D12567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
import contextlib
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
import errno
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
import os
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
     5
from mercurial.node import sha1nodeconstants
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
from mercurial import (
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
     7
    dirstatemap,
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
    error,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
    extensions,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
    match as matchmod,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
    pycompat,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
    scmutil,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
    util,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
)
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    15
from mercurial.dirstateutils import (
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    16
    timestamp,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    17
)
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
from mercurial.interfaces import (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    dirstate as intdirstate,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    util as interfaceutil,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
from . import gitutil
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    25
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    26
DirstateItem = dirstatemap.DirstateItem
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    27
propertycache = util.propertycache
44484
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    28
pygit2 = gitutil.get_pygit2()
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    29
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
def readpatternfile(orig, filepath, warn, sourceinfo=False):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
    if not (b'info/exclude' in filepath or filepath.endswith(b'.gitignore')):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
        return orig(filepath, warn, sourceinfo=False)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
    result = []
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
    warnings = []
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
    with open(filepath, b'rb') as fp:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
        for l in fp:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
            l = l.strip()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
            if not l or l.startswith(b'#'):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
                continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
            if l.startswith(b'!'):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
                warnings.append(b'unsupported ignore pattern %s' % l)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
                continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
            if l.startswith(b'/'):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
                result.append(b'rootglob:' + l[1:])
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
            else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
                result.append(b'relglob:' + l)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
    return result, warnings
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
extensions.wrapfunction(matchmod, b'readpatternfile', readpatternfile)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
44484
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    54
_STATUS_MAP = {}
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    55
if pygit2:
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    56
    _STATUS_MAP = {
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    57
        pygit2.GIT_STATUS_CONFLICTED: b'm',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    58
        pygit2.GIT_STATUS_CURRENT: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    59
        pygit2.GIT_STATUS_IGNORED: b'?',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    60
        pygit2.GIT_STATUS_INDEX_DELETED: b'r',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    61
        pygit2.GIT_STATUS_INDEX_MODIFIED: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    62
        pygit2.GIT_STATUS_INDEX_NEW: b'a',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    63
        pygit2.GIT_STATUS_INDEX_RENAMED: b'a',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    64
        pygit2.GIT_STATUS_INDEX_TYPECHANGE: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    65
        pygit2.GIT_STATUS_WT_DELETED: b'r',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    66
        pygit2.GIT_STATUS_WT_MODIFIED: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    67
        pygit2.GIT_STATUS_WT_NEW: b'?',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    68
        pygit2.GIT_STATUS_WT_RENAMED: b'a',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    69
        pygit2.GIT_STATUS_WT_TYPECHANGE: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    70
        pygit2.GIT_STATUS_WT_UNREADABLE: b'?',
47054
9cea55ca1175 git: ensure all dirstate state values are bytes
Matt Harbison <matt_harbison@yahoo.com>
parents: 46113
diff changeset
    71
        pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_WT_MODIFIED: b'm',
44484
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44477
diff changeset
    72
    }
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    73
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    74
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    75
@interfaceutil.implementer(intdirstate.idirstate)
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    76
class gitdirstate:
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    77
    def __init__(self, ui, vfs, gitrepo, use_dirstate_v2):
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    78
        self._ui = ui
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    79
        self._root = os.path.dirname(vfs.base)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    80
        self._opener = vfs
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    81
        self.git = gitrepo
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    82
        self._plchangecallbacks = {}
47772
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
    83
        # TODO: context.poststatusfixup is bad and uses this attribute
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
    84
        self._dirty = False
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    85
        self._mapcls = dirstatemap.dirstatemap
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    86
        self._use_dirstate_v2 = use_dirstate_v2
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    87
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    88
    @propertycache
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    89
    def _map(self):
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    90
        """Return the dirstate contents (see documentation for dirstatemap)."""
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    91
        self._map = self._mapcls(
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    92
            self._ui,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    93
            self._opener,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    94
            self._root,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    95
            sha1nodeconstants,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    96
            self._use_dirstate_v2,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    97
        )
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
    98
        return self._map
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   100
    def p1(self):
44492
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44484
diff changeset
   101
        try:
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44484
diff changeset
   102
            return self.git.head.peel().id.raw
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44484
diff changeset
   103
        except pygit2.GitError:
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44484
diff changeset
   104
            # Typically happens when peeling HEAD fails, as in an
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44484
diff changeset
   105
            # empty repository.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   106
            return sha1nodeconstants.nullid
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
    def p2(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
        # TODO: MERGE_HEAD? something like that, right?
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   110
        return sha1nodeconstants.nullid
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   111
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   112
    def setparents(self, p1, p2=None):
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   113
        if p2 is None:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   114
            p2 = sha1nodeconstants.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   115
        assert p2 == sha1nodeconstants.nullid, b'TODO merging support'
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
        self.git.head.set_target(gitutil.togitnode(p1))
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   117
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
    @util.propertycache
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   119
    def identity(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   120
        return util.filestat.frompath(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   121
            os.path.join(self._root, b'.git', b'index')
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   122
        )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   123
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   124
    def branch(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   125
        return b'default'
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   126
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   127
    def parents(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   128
        # TODO how on earth do we find p2 if a merge is in flight?
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46113
diff changeset
   129
        return self.p1(), sha1nodeconstants.nullid
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   130
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   131
    def __iter__(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   132
        return (pycompat.fsencode(f.path) for f in self.git.index)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   133
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   134
    def items(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   135
        for ie in self.git.index:
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47057
diff changeset
   136
            yield ie.path, None  # value should be a DirstateItem
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   138
    # py2,3 compat forward
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   139
    iteritems = items
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   140
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   141
    def __getitem__(self, filename):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   142
        try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   143
            gs = self.git.status_file(filename)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   144
        except KeyError:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   145
            return b'?'
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   146
        return _STATUS_MAP[gs]
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   147
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   148
    def __contains__(self, filename):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   149
        try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   150
            gs = self.git.status_file(filename)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   151
            return _STATUS_MAP[gs] != b'?'
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   152
        except KeyError:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   153
            return False
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   154
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   155
    def status(self, match, subrepos, ignored, clean, unknown):
45431
7a57ced7de87 git: remove unrequired assignment of listignored and listunknown
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45423
diff changeset
   156
        listclean = clean
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   157
        # TODO handling of clean files - can we get that from git.status()?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   158
        modified, added, removed, deleted, unknown, ignored, clean = (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   159
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   160
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   161
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   163
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   164
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   165
            [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   166
        )
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   167
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   168
        try:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   169
            mtime_boundary = timestamp.get_fs_now(self._opener)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   170
        except OSError:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   171
            # In largefiles or readonly context
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   172
            mtime_boundary = None
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   173
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   174
        gstatus = self.git.status()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   175
        for path, status in gstatus.items():
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   176
            path = pycompat.fsencode(path)
45421
0c6b2cc9a7bb git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents: 45420
diff changeset
   177
            if not match(path):
0c6b2cc9a7bb git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents: 45420
diff changeset
   178
                continue
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   179
            if status == pygit2.GIT_STATUS_IGNORED:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   180
                if path.endswith(b'/'):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   181
                    continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
                ignored.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   183
            elif status in (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   184
                pygit2.GIT_STATUS_WT_MODIFIED,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   185
                pygit2.GIT_STATUS_INDEX_MODIFIED,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   186
                pygit2.GIT_STATUS_WT_MODIFIED
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   187
                | pygit2.GIT_STATUS_INDEX_MODIFIED,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   188
            ):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   189
                modified.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   190
            elif status == pygit2.GIT_STATUS_INDEX_NEW:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   191
                added.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   192
            elif status == pygit2.GIT_STATUS_WT_NEW:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   193
                unknown.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   194
            elif status == pygit2.GIT_STATUS_WT_DELETED:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
                deleted.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
            elif status == pygit2.GIT_STATUS_INDEX_DELETED:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
                removed.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
            else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   199
                raise error.Abort(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   200
                    b'unhandled case: status for %r is %r' % (path, status)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   201
                )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   202
45422
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   203
        if listclean:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   204
            observed = set(
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   205
                modified + added + removed + deleted + unknown + ignored
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   206
            )
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   207
            index = self.git.index
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   208
            index.read()
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   209
            for entry in index:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   210
                path = pycompat.fsencode(entry.path)
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   211
                if not match(path):
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   212
                    continue
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   213
                if path in observed:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   214
                    continue  # already in some other set
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   215
                if path[-1] == b'/':
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   216
                    continue  # directory
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   217
                clean.append(path)
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45421
diff changeset
   218
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   219
        # TODO are we really always sure of status here?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   220
        return (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   221
            False,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   222
            scmutil.status(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   223
                modified, added, removed, deleted, unknown, ignored, clean
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   224
            ),
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   225
            mtime_boundary,
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   226
        )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   227
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   228
    def flagfunc(self, buildfallback):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   229
        # TODO we can do better
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   230
        return buildfallback()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   231
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   232
    def getcwd(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   233
        # TODO is this a good way to do this?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   234
        return os.path.dirname(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   235
            os.path.dirname(pycompat.fsencode(self.git.path))
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   236
        )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   237
49077
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   238
    def get_entry(self, path):
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   239
        """return a DirstateItem for the associated path"""
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   240
        entry = self._map.get(path)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   241
        if entry is None:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   242
            return DirstateItem()
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   243
        return entry
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
   244
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   245
    def normalize(self, path):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   246
        normed = util.normcase(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   247
        assert normed == path, b"TODO handling of case folding: %s != %s" % (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   248
            normed,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   249
            path,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   250
        )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   251
        return path
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   252
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   253
    @property
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   254
    def _checklink(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   255
        return util.checklink(os.path.dirname(pycompat.fsencode(self.git.path)))
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   256
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   257
    def copies(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   258
        # TODO support copies?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   259
        return {}
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   260
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   261
    # # TODO what the heck is this
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   262
    _filecache = set()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   263
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   264
    def pendingparentchange(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   265
        # TODO: we need to implement the context manager bits and
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   266
        # correctly stage/revert index edits.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   267
        return False
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   269
    def write(self, tr):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   270
        # TODO: call parent change callbacks
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   271
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   272
        if tr:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   273
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   274
            def writeinner(category):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   275
                self.git.index.write()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   276
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   277
            tr.addpending(b'gitdirstate', writeinner)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   278
        else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   279
            self.git.index.write()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   280
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   281
    def pathto(self, f, cwd=None):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   282
        if cwd is None:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   283
            cwd = self.getcwd()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   284
        # TODO core dirstate does something about slashes here
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   285
        assert isinstance(f, bytes)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   286
        r = util.pathto(self._root, cwd, f)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   287
        return r
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   288
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   289
    def matches(self, match):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   290
        for x in self.git.index:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   291
            p = pycompat.fsencode(x.path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   292
            if match(p):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   293
                yield p
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   294
48385
080151f18f3a dirstate: make it mandatory to provide parentfiledata in `set_clean`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47772
diff changeset
   295
    def set_clean(self, f, parentfiledata):
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   296
        """Mark a file normal and clean."""
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   297
        # TODO: for now we just let libgit2 re-stat the file. We can
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   298
        # clearly do better.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   299
47772
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   300
    def set_possibly_dirty(self, f):
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   301
        """Mark a file normal, but possibly dirty."""
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   302
        # TODO: for now we just let libgit2 re-stat the file. We can
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   303
        # clearly do better.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   304
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   305
    def walk(self, match, subrepos, unknown, ignored, full=True):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   306
        # TODO: we need to use .status() and not iterate the index,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   307
        # because the index doesn't force a re-walk and so `hg add` of
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   308
        # a new file without an intervening call to status will
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
        # silently do nothing.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   310
        r = {}
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   311
        cwd = self.getcwd()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   312
        for path, status in self.git.status().items():
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
            if path.startswith('.hg/'):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   314
                continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   315
            path = pycompat.fsencode(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   316
            if not match(path):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   317
                continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   318
            # TODO construct the stat info from the status object?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   319
            try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   320
                s = os.stat(os.path.join(cwd, path))
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   321
            except OSError as e:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   322
                if e.errno != errno.ENOENT:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   323
                    raise
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   324
                continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   325
            r[path] = s
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
        return r
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   327
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   328
    def savebackup(self, tr, backupname):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   329
        # TODO: figure out a strategy for saving index backups.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   330
        pass
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   331
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   332
    def restorebackup(self, tr, backupname):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   333
        # TODO: figure out a strategy for saving index backups.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   334
        pass
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   335
47772
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   336
    def set_tracked(self, f):
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   337
        uf = pycompat.fsdecode(f)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   338
        if uf in self.git.index:
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   339
            return False
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   340
        index = self.git.index
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   341
        index.read()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   342
        index.add(uf)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   343
        index.write()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   344
        return True
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   345
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   346
    def add(self, f):
45420
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   347
        index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   348
        index.read()
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   349
        index.add(pycompat.fsdecode(f))
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   350
        index.write()
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   351
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   352
    def drop(self, f):
45420
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   353
        index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   354
        index.read()
45423
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45422
diff changeset
   355
        fs = pycompat.fsdecode(f)
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45422
diff changeset
   356
        if fs in index:
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45422
diff changeset
   357
            index.remove(fs)
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45422
diff changeset
   358
            index.write()
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   359
47772
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   360
    def set_untracked(self, f):
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   361
        index = self.git.index
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   362
        index.read()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   363
        fs = pycompat.fsdecode(f)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   364
        if fs in index:
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   365
            index.remove(fs)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   366
            index.write()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   367
            return True
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   368
        return False
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   369
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   370
    def remove(self, f):
45420
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   371
        index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   372
        index.read()
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   373
        index.remove(pycompat.fsdecode(f))
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44927
diff changeset
   374
        index.write()
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   375
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   376
    def copied(self, path):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   377
        # TODO: track copies?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   378
        return None
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   379
44927
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44622
diff changeset
   380
    def prefetch_parents(self):
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44622
diff changeset
   381
        # TODO
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44622
diff changeset
   382
        pass
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44622
diff changeset
   383
47772
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   384
    def update_file(self, *args, **kwargs):
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   385
        # TODO
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   386
        pass
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
   387
44477
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   388
    @contextlib.contextmanager
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   389
    def parentchange(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   390
        # TODO: track this maybe?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   391
        yield
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   392
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   393
    def addparentchangecallback(self, category, callback):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   394
        # TODO: should this be added to the dirstate interface?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   395
        self._plchangecallbacks[category] = callback
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   396
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   397
    def clearbackup(self, tr, backupname):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   398
        # TODO
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
   399
        pass
44622
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44492
diff changeset
   400
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44492
diff changeset
   401
    def setbranch(self, branch):
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44492
diff changeset
   402
        raise error.Abort(
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44492
diff changeset
   403
            b'git repos do not support branches. try using bookmarks'
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44492
diff changeset
   404
        )