annotate hgext/git/dirstate.py @ 53040:cdd7bf612c7b stable tip

bundle-spec: properly format boolean parameter (issue6960) This was breaking automatic clone bundle generation. This changeset fixes it and add a test to catch it in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 11 Mar 2025 02:29:42 +0100
parents a7dcb7c1ff5a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51293
diff changeset
1 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51293
diff changeset
2
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
3 import contextlib
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
4 import os
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
5
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
6 from typing import (
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
7 Any,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
8 Dict,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
9 Iterable,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
10 Iterator,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
11 List,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
12 Optional,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
13 Tuple,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
14 )
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
15
52768
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
16 from mercurial.interfaces.types import (
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
17 MatcherT,
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
18 TransactionT,
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
19 )
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
20 from mercurial.node import sha1nodeconstants
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
21 from mercurial import (
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
22 dirstatemap,
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
23 error,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
24 extensions,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
25 match as matchmod,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
26 pycompat,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
27 scmutil,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
28 util,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
29 )
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
30 from mercurial.dirstateutils import (
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
31 timestamp,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
32 )
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
33 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
34 dirstate as intdirstate,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
35 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
36
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
37 from . import gitutil
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
38
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
39
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
40 DirstateItem = dirstatemap.DirstateItem
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
41 propertycache = util.propertycache
44496
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
42 pygit2 = gitutil.get_pygit2()
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
43
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
44
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
45 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
46 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
47 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
48 result = []
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
49 warnings = []
49133
020328be00cb git: un-byteify the `mode` argument for the builtin `open()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 49132
diff changeset
50 with open(filepath, 'rb') as fp:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
51 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
52 l = l.strip()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
53 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
54 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
55 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
56 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
57 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
58 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
59 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
60 else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
61 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
62 return result, warnings
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
63
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
64
50816
39eb3aab3e63 wrapfunction: use sysstr instead of bytes as argument in the "git" extension
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50256
diff changeset
65 extensions.wrapfunction(matchmod, 'readpatternfile', readpatternfile)
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
66
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
67
44496
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
68 _STATUS_MAP = {}
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
69 if pygit2:
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
70 _STATUS_MAP = {
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
71 pygit2.GIT_STATUS_CONFLICTED: b'm',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
72 pygit2.GIT_STATUS_CURRENT: b'n',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
73 pygit2.GIT_STATUS_IGNORED: b'?',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
74 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: 44489
diff changeset
75 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: 44489
diff changeset
76 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: 44489
diff changeset
77 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: 44489
diff changeset
78 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: 44489
diff changeset
79 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: 44489
diff changeset
80 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: 44489
diff changeset
81 pygit2.GIT_STATUS_WT_NEW: b'?',
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
82 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: 44489
diff changeset
83 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: 44489
diff changeset
84 pygit2.GIT_STATUS_WT_UNREADABLE: b'?',
47025
9cea55ca1175 git: ensure all dirstate state values are bytes
Matt Harbison <matt_harbison@yahoo.com>
parents: 46114
diff changeset
85 pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_WT_MODIFIED: b'm',
44496
ec54b3d2af0b git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents: 44489
diff changeset
86 }
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
87
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
88
51961
3a90a6fd710d dirstate: subclass the new dirstate Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51960
diff changeset
89 class gitdirstate(intdirstate.idirstate):
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
90 def __init__(self, ui, vfs, gitrepo, use_dirstate_v2):
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
91 self._ui = ui
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
92 self._root = os.path.dirname(vfs.base)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
93 self._opener = vfs
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
94 self.git = gitrepo
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
95 self._plchangecallbacks = {}
47771
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
96 # TODO: context.poststatusfixup is bad and uses this attribute
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
97 self._dirty = False
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
98 self._mapcls = dirstatemap.dirstatemap
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
99 self._use_dirstate_v2 = use_dirstate_v2
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
100
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
101 @propertycache
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
102 def _map(self):
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
103 """Return the dirstate contents (see documentation for dirstatemap)."""
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
104 self._map = self._mapcls(
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
105 self._ui,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
106 self._opener,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
107 self._root,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
108 sha1nodeconstants,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
109 self._use_dirstate_v2,
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
110 )
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
111 return self._map
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
112
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
113 def p1(self) -> bytes:
44504
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44496
diff changeset
114 try:
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44496
diff changeset
115 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: 44496
diff changeset
116 except pygit2.GitError:
eb061d272af4 git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents: 44496
diff changeset
117 # 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: 44496
diff changeset
118 # empty repository.
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
119 return sha1nodeconstants.nullid
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
120
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
121 def p2(self) -> bytes:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
122 # TODO: MERGE_HEAD? something like that, right?
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
123 return sha1nodeconstants.nullid
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
124
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
125 def setparents(self, p1: bytes, p2: Optional[bytes] = None):
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
126 if p2 is None:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
127 p2 = sha1nodeconstants.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
128 assert p2 == sha1nodeconstants.nullid, b'TODO merging support'
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
129 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
130
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
131 @util.propertycache
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
132 def identity(self):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
133 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
134 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
135 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
136
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
137 def branch(self) -> bytes:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
138 return b'default'
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
139
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
140 def parents(self) -> List[bytes]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
141 # TODO how on earth do we find p2 if a merge is in flight?
51963
e99c007030da git: make `dirstate.parents()` return a list like the core class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51961
diff changeset
142 return [self.p1(), sha1nodeconstants.nullid]
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
143
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
144 def __iter__(self) -> Iterator[bytes]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
145 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
146
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
147 def items(self) -> Iterator[Tuple[bytes, intdirstate.DirstateItemT]]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
148 for ie in self.git.index:
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47084
diff changeset
149 yield ie.path, None # value should be a DirstateItem
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
150
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
151 # 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
152 iteritems = items
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
153
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
154 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
155 try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
156 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
157 except KeyError:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
158 return b'?'
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
159 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
160
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
161 def __contains__(self, filename: Any) -> bool:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
162 try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
163 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
164 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
165 except KeyError:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
166 return False
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
167
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
168 def status(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
169 self,
52755
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52656
diff changeset
170 match: MatcherT,
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
171 subrepos: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
172 ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
173 clean: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
174 unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
175 ) -> intdirstate.StatusReturnT:
45442
7a57ced7de87 git: remove unrequired assignment of listignored and listunknown
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45434
diff changeset
176 listclean = clean
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
177 # 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
178 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
179 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
180 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
181 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
182 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
183 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
184 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
185 [],
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
186 )
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
187
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
188 try:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
189 mtime_boundary = timestamp.get_fs_now(self._opener)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
190 except OSError:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
191 # In largefiles or readonly context
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
192 mtime_boundary = None
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
193
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
194 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
195 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
196 path = pycompat.fsencode(path)
45432
0c6b2cc9a7bb git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents: 45431
diff changeset
197 if not match(path):
0c6b2cc9a7bb git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents: 45431
diff changeset
198 continue
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
199 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
200 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
201 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
202 ignored.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
203 elif status in (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
204 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
205 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
206 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
207 | 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
208 ):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
209 modified.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
210 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
211 added.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
212 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
213 unknown.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
214 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
215 deleted.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
216 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
217 removed.append(path)
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
218 else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
219 raise error.Abort(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
220 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
221 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
222
45433
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
223 if listclean:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
224 observed = set(
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
225 modified + added + removed + deleted + unknown + ignored
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
226 )
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
227 index = self.git.index
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
228 index.read()
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
229 for entry in index:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
230 path = pycompat.fsencode(entry.path)
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
231 if not match(path):
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
232 continue
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
233 if path in observed:
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
234 continue # already in some other set
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
235 if path[-1] == b'/':
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
236 continue # directory
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
237 clean.append(path)
601e3658216d git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents: 45432
diff changeset
238
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
239 # 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
240 return (
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
241 False,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
242 scmutil.status(
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
243 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
244 ),
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
245 mtime_boundary,
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
246 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
247
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
248 def flagfunc(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
249 self, buildfallback: intdirstate.FlagFuncFallbackT
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
250 ) -> intdirstate.FlagFuncReturnT:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
251 # 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
252 return buildfallback()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
253
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
254 def getcwd(self) -> bytes:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
255 # 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
256 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
257 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
258 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
259
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
260 def get_entry(self, path: bytes) -> intdirstate.DirstateItemT:
49132
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
261 """return a DirstateItem for the associated path"""
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
262 entry = self._map.get(path)
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
263 if entry is None:
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
264 return DirstateItem()
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
265 return entry
20d151e43429 git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
266
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
267 def normalize(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
268 self, path: bytes, isknown: bool = False, ignoremissing: bool = False
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
269 ) -> bytes:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
270 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
271 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
272 normed,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
273 path,
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
274 )
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
275 return path
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
276
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
277 def is_changing_files(self) -> bool:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
278 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
279
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
280 def _ignorefileandline(self, f: bytes) -> intdirstate.IgnoreFileAndLineT:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
281 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
282
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
283 @property
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
284 def _checklink(self) -> bool:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
285 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
286
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
287 def invalidate(self) -> None:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
288 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
289
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
290 def copy(self, source: Optional[bytes], dest: bytes) -> None:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
291 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
292
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
293 def copies(self) -> Dict[bytes, bytes]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
294 # TODO support copies?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
295 return {}
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
296
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
297 # # 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
298 _filecache = set()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
299
51960
51be8bf8c986 git: correct some signature mismatches between dirstate and the Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
300 @property
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
301 def is_changing_parents(self) -> bool:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
302 # 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
303 # 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
304 return False
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
305
51960
51be8bf8c986 git: correct some signature mismatches between dirstate and the Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
306 @property
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
307 def is_changing_any(self) -> bool:
50079
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50078
diff changeset
308 # TODO: we need to implement the context manager bits and
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50078
diff changeset
309 # correctly stage/revert index edits.
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50078
diff changeset
310 return False
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50078
diff changeset
311
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
312 def clear(self) -> None:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
313 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
314
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
315 def rebuild(
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
316 self,
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
317 parent: bytes,
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
318 allfiles: Iterable[bytes], # TODO: more than iterable? (uses len())
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
319 changedfiles: Optional[Iterable[bytes]] = None,
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
320 ) -> None:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
321 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
322
52768
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
323 def write(self, tr: Optional[TransactionT]) -> None:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
324 # 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
325
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
326 if tr:
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 writeinner(category):
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
329 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
330
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
331 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
332 else:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
333 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
334
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
335 def pathto(self, f: bytes, cwd: Optional[bytes] = None) -> bytes:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
336 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
337 cwd = self.getcwd()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
338 # 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
339 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
340 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
341 return r
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
342
52755
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52656
diff changeset
343 def matches(self, match: MatcherT) -> Iterable[bytes]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
344 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
345 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
346 if match(p):
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
347 yield p # TODO: return list instead of yielding?
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
348
48433
080151f18f3a dirstate: make it mandatory to provide parentfiledata in `set_clean`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47771
diff changeset
349 def set_clean(self, f, parentfiledata):
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
350 """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
351 # 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
352 # clearly do better.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
353
47771
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
354 def set_possibly_dirty(self, f):
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
355 """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
356 # 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
357 # clearly do better.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
358
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
359 def walk(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
360 self,
52755
5c48fd4c0e68 typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52656
diff changeset
361 match: MatcherT,
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
362 subrepos: Any,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
363 unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
364 ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
365 full: bool = True,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
366 ) -> intdirstate.WalkReturnT:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
367 # 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
368 # 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
369 # 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
370 # silently do nothing.
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
371 r = {}
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
372 cwd = self.getcwd()
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
373 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
374 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
375 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
376 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
377 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
378 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
379 # 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
380 try:
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
381 s = os.stat(os.path.join(cwd, path))
49314
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49133
diff changeset
382 except FileNotFoundError:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
383 continue
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
384 r[path] = s
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
385 return r
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
386
49381
3c4d36a96a3e git: add a missing reset_copy keyword argument to dirstate.set_tracked()
Anton Shestakov <av6@dwimlabs.net>
parents: 49314
diff changeset
387 def set_tracked(self, f, reset_copy=False):
3c4d36a96a3e git: add a missing reset_copy keyword argument to dirstate.set_tracked()
Anton Shestakov <av6@dwimlabs.net>
parents: 49314
diff changeset
388 # TODO: support copies and reset_copy=True
47771
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
389 uf = pycompat.fsdecode(f)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
390 if uf in self.git.index:
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
391 return False
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
392 index = self.git.index
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
393 index.read()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
394 index.add(uf)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
395 index.write()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
396 return True
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
397
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
398 def add(self, f):
45431
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
399 index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
400 index.read()
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
401 index.add(pycompat.fsdecode(f))
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
402 index.write()
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
403
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
404 def drop(self, f):
45431
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
405 index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
406 index.read()
45434
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45433
diff changeset
407 fs = pycompat.fsdecode(f)
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45433
diff changeset
408 if fs in index:
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45433
diff changeset
409 index.remove(fs)
d4cf80341589 git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents: 45433
diff changeset
410 index.write()
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
411
47771
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
412 def set_untracked(self, f):
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
413 index = self.git.index
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
414 index.read()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
415 fs = pycompat.fsdecode(f)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
416 if fs in index:
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
417 index.remove(fs)
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
418 index.write()
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
419 return True
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
420 return False
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
421
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
422 def remove(self, f):
45431
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
423 index = self.git.index
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
424 index.read()
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
425 index.remove(pycompat.fsdecode(f))
c67529569643 git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents: 44968
diff changeset
426 index.write()
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
427
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
428 def copied(self, file: bytes) -> Optional[bytes]:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
429 # TODO: track copies?
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
430 return None
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
431
44968
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44626
diff changeset
432 def prefetch_parents(self):
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44626
diff changeset
433 # TODO
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44626
diff changeset
434 pass
472b14da52c2 git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44626
diff changeset
435
47771
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
436 def update_file(self, *args, **kwargs):
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
437 # TODO
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
438 pass
0bdcb5ef932c git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents: 47539
diff changeset
439
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
440 def _checkexec(self) -> bool:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
441 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
442
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
443 @contextlib.contextmanager
50023
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50022
diff changeset
444 def changing_parents(self, repo):
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
445 # 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
446 yield
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
447
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
448 @contextlib.contextmanager
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
449 def changing_files(self, repo) -> Iterator: # TODO: typehint this
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
450 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
451
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
452 def hasdir(self, d: bytes) -> bool:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
453 raise NotImplementedError
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
454
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
455 def addparentchangecallback(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
456 self, category: bytes, callback: intdirstate.AddParentChangeCallbackT
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
457 ) -> None:
44489
ad718271a9eb git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff changeset
458 # 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
459 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
460
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
461 def setbranch(
52768
a7dcb7c1ff5a typing: add a transaction protocol
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52755
diff changeset
462 self, branch: bytes, transaction: Optional[TransactionT]
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51963
diff changeset
463 ) -> None:
44626
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44504
diff changeset
464 raise error.Abort(
7bbb83e4e8de git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44504
diff changeset
465 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: 44504
diff changeset
466 )
52641
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
467
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
468 def verify(
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
469 self, m1, m2, p1: bytes, narrow_matcher: Optional[Any] = None
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
470 ) -> Iterator[bytes]:
b798ad65ced8 git: add stubs for dirstate methods
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 51965
diff changeset
471 raise NotImplementedError
52646
ab4fb2d15bc9 git: add stub for gitdirstate.running_status
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52641
diff changeset
472
ab4fb2d15bc9 git: add stub for gitdirstate.running_status
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52641
diff changeset
473 def running_status(self, repo):
ab4fb2d15bc9 git: add stub for gitdirstate.running_status
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52641
diff changeset
474 raise NotImplementedError
52656
482728ca94c1 git: add nop refresh method to gitdirstate
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52646
diff changeset
475
482728ca94c1 git: add nop refresh method to gitdirstate
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52646
diff changeset
476 def refresh(self):
482728ca94c1 git: add nop refresh method to gitdirstate
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 52646
diff changeset
477 pass