Mercurial > hg
annotate hgext/git/dirstate.py @ 52032:09a54892b7ee
mergestate: reduce the number of attribute lookups
This code is called a lot during updates, this is a very small but also very
easy thing to do.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 21 Aug 2024 09:48:14 +0200 |
parents | 93d872a06132 |
children |
rev | line source |
---|---|
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51273
diff
changeset
|
1 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51273
diff
changeset
|
2 |
44477
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 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
6 from typing import ( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
7 Any, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
8 Dict, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
9 Iterable, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
10 Iterator, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
11 List, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
12 Optional, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
13 Tuple, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
14 ) |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
15 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
16 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
|
17 from mercurial import ( |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
18 dirstatemap, |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 error, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 extensions, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 match as matchmod, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 pycompat, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 scmutil, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 util, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 ) |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
26 from mercurial.dirstateutils import ( |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
27 timestamp, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
28 ) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 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
|
30 dirstate as intdirstate, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 from . import gitutil |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
35 |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
36 DirstateItem = dirstatemap.DirstateItem |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
37 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
|
38 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
|
39 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 result = [] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 warnings = [] |
49078
020328be00cb
git: un-byteify the `mode` argument for the builtin `open()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
49077
diff
changeset
|
46 with open(filepath, 'rb') as fp: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 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
|
48 l = l.strip() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 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
|
50 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 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
|
52 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
|
53 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 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
|
55 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
|
56 else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 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
|
58 return result, warnings |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
50779
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
|
61 extensions.wrapfunction(matchmod, 'readpatternfile', readpatternfile) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
64 _STATUS_MAP = {} |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
65 if pygit2: |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
66 _STATUS_MAP = { |
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_CONFLICTED: b'm', |
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_CURRENT: b'n', |
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_IGNORED: b'?', |
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_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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 } |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
51925
3a90a6fd710d
dirstate: subclass the new dirstate Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents:
51924
diff
changeset
|
85 class gitdirstate(intdirstate.idirstate): |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
86 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
|
87 self._ui = ui |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
88 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
|
89 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
|
90 self.git = gitrepo |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 self._plchangecallbacks = {} |
47772
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
92 # TODO: context.poststatusfixup is bad and uses this attribute |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
93 self._dirty = False |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
94 self._mapcls = dirstatemap.dirstatemap |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
95 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
|
96 |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
97 @propertycache |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
98 def _map(self): |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
99 """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
|
100 self._map = self._mapcls( |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
101 self._ui, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
102 self._opener, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
103 self._root, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
104 sha1nodeconstants, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
105 self._use_dirstate_v2, |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
106 ) |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
107 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
|
108 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
109 def p1(self) -> bytes: |
44492
eb061d272af4
git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
110 try: |
eb061d272af4
git: correctly handle p1() on dirstate when underlying git repo is empty
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
111 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
|
112 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
|
113 # 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
|
114 # empty repository. |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
115 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
|
116 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
117 def p2(self) -> bytes: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 # 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
|
119 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
|
120 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
121 def setparents(self, p1: bytes, p2: Optional[bytes] = None): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
122 if p2 is None: |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
123 p2 = sha1nodeconstants.nullid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
124 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
|
125 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
|
126 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 @util.propertycache |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 def identity(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 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
|
130 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
|
131 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
133 def branch(self) -> bytes: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 return b'default' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
136 def parents(self) -> List[bytes]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 # TODO how on earth do we find p2 if a merge is in flight? |
51927
e99c007030da
git: make `dirstate.parents()` return a list like the core class
Matt Harbison <matt_harbison@yahoo.com>
parents:
51925
diff
changeset
|
138 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
|
139 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
140 def __iter__(self) -> Iterator[bytes]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 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
|
142 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
143 def items(self) -> Iterator[Tuple[bytes, intdirstate.DirstateItemT]]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 # 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
|
148 iteritems = items |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 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
|
151 try: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 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
|
153 except KeyError: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 return b'?' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 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
|
156 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
157 def __contains__(self, filename: Any) -> bool: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 try: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 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
|
160 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
|
161 except KeyError: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 return False |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
164 def status( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
165 self, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
166 match: matchmod.basematcher, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
167 subrepos: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
168 ignored: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
169 clean: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
170 unknown: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
171 ) -> intdirstate.StatusReturnT: |
45431
7a57ced7de87
git: remove unrequired assignment of listignored and listunknown
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45423
diff
changeset
|
172 listclean = clean |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 # 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
|
174 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
|
175 [], |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 [], |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 [], |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 [], |
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 ) |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
183 |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
184 try: |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
185 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
|
186 except OSError: |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
187 # In largefiles or readonly context |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
188 mtime_boundary = None |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
189 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 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
|
191 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
|
192 path = pycompat.fsencode(path) |
45421
0c6b2cc9a7bb
git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents:
45420
diff
changeset
|
193 if not match(path): |
0c6b2cc9a7bb
git: make dirstate status() respect matcher
Augie Fackler <raf@durin42.com>
parents:
45420
diff
changeset
|
194 continue |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 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
|
196 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
|
197 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 ignored.append(path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 elif status in ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 | 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
|
204 ): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 modified.append(path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 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
|
207 added.append(path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 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
|
209 unknown.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_WT_DELETED: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 deleted.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_INDEX_DELETED: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 removed.append(path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 raise error.Abort( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 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
|
217 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 |
45422
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
219 if listclean: |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
220 observed = set( |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
221 modified + added + removed + deleted + unknown + ignored |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
222 ) |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
223 index = self.git.index |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
224 index.read() |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
225 for entry in index: |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
226 path = pycompat.fsencode(entry.path) |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
227 if not match(path): |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
228 continue |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
229 if path in observed: |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
230 continue # already in some other set |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
231 if path[-1] == b'/': |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
232 continue # directory |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
233 clean.append(path) |
601e3658216d
git: make dirstate actually support listclean parameter
Augie Fackler <raf@durin42.com>
parents:
45421
diff
changeset
|
234 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 # 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
|
236 return ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
237 False, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
238 scmutil.status( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
239 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
|
240 ), |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
241 mtime_boundary, |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
243 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
244 def flagfunc( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
245 self, buildfallback: intdirstate.FlagFuncFallbackT |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
246 ) -> intdirstate.FlagFuncReturnT: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 # 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
|
248 return buildfallback() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
250 def getcwd(self) -> bytes: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 # 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
|
252 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
|
253 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
|
254 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
256 def get_entry(self, path: bytes) -> intdirstate.DirstateItemT: |
49077
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
257 """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
|
258 entry = self._map.get(path) |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
259 if entry is None: |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
260 return DirstateItem() |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
261 return entry |
20d151e43429
git: adapt to some recent dirstate API changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
48946
diff
changeset
|
262 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
263 def normalize( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
264 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:
51927
diff
changeset
|
265 ) -> bytes: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 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
|
267 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
|
268 normed, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 path, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 ) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
271 return path |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 @property |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
274 def _checklink(self) -> bool: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
275 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
|
276 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
277 def copies(self) -> Dict[bytes, bytes]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
278 # TODO support copies? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
279 return {} |
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 # # 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
|
282 _filecache = set() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
283 |
51924
51be8bf8c986
git: correct some signature mismatches between dirstate and the Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents:
51863
diff
changeset
|
284 @property |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
285 def is_changing_parents(self) -> bool: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
286 # 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
|
287 # 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
|
288 return False |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
289 |
51924
51be8bf8c986
git: correct some signature mismatches between dirstate and the Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents:
51863
diff
changeset
|
290 @property |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
291 def is_changing_any(self) -> bool: |
50023
e1cff85484e2
dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50022
diff
changeset
|
292 # 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:
50022
diff
changeset
|
293 # correctly stage/revert index edits. |
e1cff85484e2
dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50022
diff
changeset
|
294 return False |
e1cff85484e2
dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50022
diff
changeset
|
295 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
296 def write(self, tr: Optional[intdirstate.TransactionT]) -> None: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
297 # 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
|
298 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
299 if tr: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
300 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
301 def writeinner(category): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
302 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
|
303 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
304 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
|
305 else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
306 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
|
307 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
308 def pathto(self, f: bytes, cwd: Optional[bytes] = None) -> bytes: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
309 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
|
310 cwd = self.getcwd() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
311 # 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
|
312 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
|
313 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
|
314 return r |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
315 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
316 def matches(self, match: matchmod.basematcher) -> Iterable[bytes]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
317 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
|
318 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
|
319 if match(p): |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
320 yield p # TODO: return list instead of yielding? |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
321 |
48385
080151f18f3a
dirstate: make it mandatory to provide parentfiledata in `set_clean`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47772
diff
changeset
|
322 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
|
323 """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
|
324 # 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
|
325 # clearly do better. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
326 |
47772
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
327 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
|
328 """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
|
329 # 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
|
330 # clearly do better. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
331 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
332 def walk( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
333 self, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
334 match: matchmod.basematcher, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
335 subrepos: Any, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
336 unknown: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
337 ignored: bool, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
338 full: bool = True, |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
339 ) -> intdirstate.WalkReturnT: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
340 # 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
|
341 # 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
|
342 # 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
|
343 # silently do nothing. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
344 r = {} |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
345 cwd = self.getcwd() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
346 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
|
347 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
|
348 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
349 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
|
350 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
|
351 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
352 # 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
|
353 try: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
354 s = os.stat(os.path.join(cwd, path)) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49078
diff
changeset
|
355 except FileNotFoundError: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
357 r[path] = s |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
358 return r |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
359 |
49385
3c4d36a96a3e
git: add a missing reset_copy keyword argument to dirstate.set_tracked()
Anton Shestakov <av6@dwimlabs.net>
parents:
49306
diff
changeset
|
360 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:
49306
diff
changeset
|
361 # TODO: support copies and reset_copy=True |
47772
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
362 uf = pycompat.fsdecode(f) |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
363 if uf in self.git.index: |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
364 return False |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
365 index = self.git.index |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
366 index.read() |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
367 index.add(uf) |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
368 index.write() |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
369 return True |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
370 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
371 def add(self, f): |
45420
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
372 index = self.git.index |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
373 index.read() |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
374 index.add(pycompat.fsdecode(f)) |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
375 index.write() |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
376 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
377 def drop(self, f): |
45420
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
378 index = self.git.index |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
379 index.read() |
45423
d4cf80341589
git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents:
45422
diff
changeset
|
380 fs = pycompat.fsdecode(f) |
d4cf80341589
git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents:
45422
diff
changeset
|
381 if fs in index: |
d4cf80341589
git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents:
45422
diff
changeset
|
382 index.remove(fs) |
d4cf80341589
git: fix index handling of removed files during commit (issue6398)
Augie Fackler <raf@durin42.com>
parents:
45422
diff
changeset
|
383 index.write() |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
384 |
47772
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
385 def set_untracked(self, f): |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
386 index = self.git.index |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
387 index.read() |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
388 fs = pycompat.fsdecode(f) |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
389 if fs in index: |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
390 index.remove(fs) |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
391 index.write() |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
392 return True |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
393 return False |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
394 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
395 def remove(self, f): |
45420
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
396 index = self.git.index |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
397 index.read() |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
398 index.remove(pycompat.fsdecode(f)) |
c67529569643
git: fix up dirstate use of index
Augie Fackler <raf@durin42.com>
parents:
44927
diff
changeset
|
399 index.write() |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
400 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
401 def copied(self, file: bytes) -> Optional[bytes]: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
402 # TODO: track copies? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
403 return None |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
404 |
44927
472b14da52c2
git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44622
diff
changeset
|
405 def prefetch_parents(self): |
472b14da52c2
git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44622
diff
changeset
|
406 # TODO |
472b14da52c2
git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44622
diff
changeset
|
407 pass |
472b14da52c2
git: implement stub prefetch_parents dirstate method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44622
diff
changeset
|
408 |
47772
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
409 def update_file(self, *args, **kwargs): |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
410 # TODO |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
411 pass |
0bdcb5ef932c
git: restore basic functionality (issue6545)
Augie Fackler <augie@google.com>
parents:
47539
diff
changeset
|
412 |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
413 @contextlib.contextmanager |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
414 def changing_parents(self, repo): |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
415 # 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
|
416 yield |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
417 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
418 def addparentchangecallback( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
419 self, category: bytes, callback: intdirstate.AddParentChangeCallbackT |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
420 ) -> None: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
421 # 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
|
422 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
|
423 |
51929
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
424 def setbranch( |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
425 self, branch: bytes, transaction: Optional[intdirstate.TransactionT] |
93d872a06132
typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents:
51927
diff
changeset
|
426 ) -> None: |
44622
7bbb83e4e8de
git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44492
diff
changeset
|
427 raise error.Abort( |
7bbb83e4e8de
git: abort when attempting to set a branch
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44492
diff
changeset
|
428 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
|
429 ) |