author | Matt Harbison <matt_harbison@yahoo.com> |
Mon, 04 Nov 2024 16:43:05 -0500 | |
branch | stable |
changeset 52188 | e4b242f9d4d9 |
parent 51863 | f4733654f144 |
permissions | -rw-r--r-- |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
diff
changeset
|
1 |
from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51304
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 |
from mercurial.i18n import _ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
|
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
5 |
from mercurial.node import ( |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
6 |
bin, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
7 |
hex, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
8 |
nullrev, |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
9 |
sha1nodeconstants, |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
10 |
) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
from mercurial import ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
ancestor, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
changelog as hgchangelog, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
dagop, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
encoding, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 |
error, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
manifest, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 |
pycompat, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
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
|
21 |
repository, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
util as interfaceutil, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
from mercurial.utils import stringutil |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
from . import ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
gitutil, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
index, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
manifest as gitmanifest, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
|
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44481
diff
changeset
|
31 |
pygit2 = gitutil.get_pygit2() |
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44481
diff
changeset
|
32 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
|
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
34 |
class baselog: # revlog.revlog): |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
"""Common implementations between changelog and manifestlog.""" |
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 |
def __init__(self, gr, db): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
self.gitrepo = gr |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
self._db = db |
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 __len__(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
return int( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
self._db.execute('SELECT COUNT(*) FROM changelog').fetchone()[0] |
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 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 |
def rev(self, n): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
47 |
if n == sha1nodeconstants.nullid: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 |
return -1 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 |
t = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
'SELECT rev FROM changelog WHERE node = ?', (gitutil.togitnode(n),) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
if t is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 |
raise error.LookupError(n, b'00changelog.i', _(b'no node %d')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
return t[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
def node(self, r): |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
57 |
if r == nullrev: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
58 |
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
|
59 |
t = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
'SELECT node FROM changelog WHERE rev = ?', (r,) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
if t is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 |
raise error.LookupError(r, b'00changelog.i', _(b'no node')) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
64 |
return bin(t[0]) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
def hasnode(self, n): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
t = self._db.execute( |
47050
ce24a00fe7f0
git: pass the correct type to the sqlite3 query for baselog.hasnode()
Matt Harbison <matt_harbison@yahoo.com>
parents:
47049
diff
changeset
|
68 |
'SELECT node FROM changelog WHERE node = ?', |
ce24a00fe7f0
git: pass the correct type to the sqlite3 query for baselog.hasnode()
Matt Harbison <matt_harbison@yahoo.com>
parents:
47049
diff
changeset
|
69 |
(pycompat.sysstr(n),), |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
return t is not None |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
|
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
74 |
class baselogindex: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
def __init__(self, log): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 |
self._log = log |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
def has_node(self, n): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
return self._log.rev(n) != -1 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
def __len__(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
return len(self._log) |
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 |
def __getitem__(self, idx): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
p1rev, p2rev = self._log.parentrevs(idx) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 |
# TODO: it's messy that the index leaks so far out of the |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
# storage layer that we have to implement things like reading |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
# this raw tuple, which exposes revlog internals. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
return ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 |
# Pretend offset is just the index, since we don't really care. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 |
idx, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 |
# Same with lengths |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
idx, # length |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 |
idx, # rawsize |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 |
-1, # delta base |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
idx, # linkrev TODO is this right? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 |
p1rev, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 |
p2rev, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 |
self._log.node(idx), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
100 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
101 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 |
# TODO: an interface for the changelog type? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
104 |
class changelog(baselog): |
45414
66a10bd1b8db
git: restore basic functionality after b3040b6739ce
Augie Fackler <raf@durin42.com>
parents:
45413
diff
changeset
|
105 |
# TODO: this appears to be an enumerated type, and should probably |
66a10bd1b8db
git: restore basic functionality after b3040b6739ce
Augie Fackler <raf@durin42.com>
parents:
45413
diff
changeset
|
106 |
# be part of the public changelog interface |
66a10bd1b8db
git: restore basic functionality after b3040b6739ce
Augie Fackler <raf@durin42.com>
parents:
45413
diff
changeset
|
107 |
_copiesstorage = b'extra' |
66a10bd1b8db
git: restore basic functionality after b3040b6739ce
Augie Fackler <raf@durin42.com>
parents:
45413
diff
changeset
|
108 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 |
def __contains__(self, rev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
try: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
111 |
self.node(rev) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 |
return True |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
except error.LookupError: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
return False |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
|
44481
8b5f5d8ad783
gitlog: implement __iter__ on changelog
Augie Fackler <raf@durin42.com>
parents:
44480
diff
changeset
|
116 |
def __iter__(self): |
49284
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
117 |
return iter(range(len(self))) |
44481
8b5f5d8ad783
gitlog: implement __iter__ on changelog
Augie Fackler <raf@durin42.com>
parents:
44480
diff
changeset
|
118 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
@property |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
def filteredrevs(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
# TODO: we should probably add a refs/hg/ namespace for hidden |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
# heads etc, but that's an idea for later. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
return set() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
@property |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
def index(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
return baselogindex(self) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 |
@property |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
def nodemap(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
r = { |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
132 |
bin(v[0]): v[1] |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
for v in self._db.execute('SELECT node, rev FROM changelog') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
} |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
135 |
r[sha1nodeconstants.nullid] = nullrev |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 |
return r |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 |
def tip(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 |
t = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
'SELECT node FROM changelog ORDER BY rev DESC LIMIT 1' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 |
if t: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
143 |
return bin(t[0]) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
144 |
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
|
145 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
def revs(self, start=0, stop=None): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 |
if stop is None: |
47049
2a77c817d451
git: use the correct type for stopping changelog.revs()
Matt Harbison <matt_harbison@yahoo.com>
parents:
47048
diff
changeset
|
148 |
stop = self.tiprev() |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
t = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
'SELECT rev FROM changelog ' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
'WHERE rev >= ? AND rev <= ? ' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
'ORDER BY REV ASC', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
(start, stop), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 |
return (int(r[0]) for r in t) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
|
45925
6aacc39501f7
gitlog: add tiprev() function
Augie Fackler <raf@durin42.com>
parents:
45521
diff
changeset
|
157 |
def tiprev(self): |
6aacc39501f7
gitlog: add tiprev() function
Augie Fackler <raf@durin42.com>
parents:
45521
diff
changeset
|
158 |
t = self._db.execute( |
45939
66f6ca2b7aee
cleanup: fix a few recent black formatting violations
Matt Harbison <matt_harbison@yahoo.com>
parents:
45925
diff
changeset
|
159 |
'SELECT rev FROM changelog ' 'ORDER BY REV DESC ' 'LIMIT 1' |
47046
497cedcb6504
git: make changelog.tiprev() return int instead of tuple (issue6510)
Matt Harbison <matt_harbison@yahoo.com>
parents:
47045
diff
changeset
|
160 |
).fetchone() |
497cedcb6504
git: make changelog.tiprev() return int instead of tuple (issue6510)
Matt Harbison <matt_harbison@yahoo.com>
parents:
47045
diff
changeset
|
161 |
|
497cedcb6504
git: make changelog.tiprev() return int instead of tuple (issue6510)
Matt Harbison <matt_harbison@yahoo.com>
parents:
47045
diff
changeset
|
162 |
if t is not None: |
497cedcb6504
git: make changelog.tiprev() return int instead of tuple (issue6510)
Matt Harbison <matt_harbison@yahoo.com>
parents:
47045
diff
changeset
|
163 |
return t[0] |
497cedcb6504
git: make changelog.tiprev() return int instead of tuple (issue6510)
Matt Harbison <matt_harbison@yahoo.com>
parents:
47045
diff
changeset
|
164 |
return -1 |
45925
6aacc39501f7
gitlog: add tiprev() function
Augie Fackler <raf@durin42.com>
parents:
45521
diff
changeset
|
165 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
def _partialmatch(self, id): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
167 |
if sha1nodeconstants.wdirhex.startswith(id): |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
raise error.WdirUnsupported |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
candidates = [ |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
170 |
bin(x[0]) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
for x in self._db.execute( |
47045
846920d89476
git: fix partial node matching
Matt Harbison <matt_harbison@yahoo.com>
parents:
46795
diff
changeset
|
172 |
'SELECT node FROM changelog WHERE node LIKE ?', |
846920d89476
git: fix partial node matching
Matt Harbison <matt_harbison@yahoo.com>
parents:
46795
diff
changeset
|
173 |
(pycompat.sysstr(id + b'%'),), |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 |
] |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
176 |
if sha1nodeconstants.nullhex.startswith(id): |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
177 |
candidates.append(sha1nodeconstants.nullid) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 |
if len(candidates) > 1: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
179 |
raise error.AmbiguousPrefixLookupError( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 |
id, b'00changelog.i', _(b'ambiguous identifier') |
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 |
if candidates: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 |
return candidates[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 |
return None |
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 |
def flags(self, rev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
return 0 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 |
def shortest(self, node, minlength=1): |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
190 |
nodehex = hex(node) |
49284
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
191 |
for attempt in range(minlength, len(nodehex) + 1): |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 |
candidate = nodehex[:attempt] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 |
matches = int( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 |
self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 |
'SELECT COUNT(*) FROM changelog WHERE node LIKE ?', |
44478
6d953b3fc2bd
git: make {shortest()} return shortest *unique* prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
196 |
(pycompat.sysstr(candidate + b'%'),), |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
197 |
).fetchone()[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 |
if matches == 1: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 |
return candidate |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 |
return nodehex |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 |
def headrevs(self, revs=None): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 |
realheads = [ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 |
int(x[0]) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 |
for x in self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 |
'SELECT rev FROM changelog ' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 |
'INNER JOIN heads ON changelog.node = heads.node' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 |
if revs: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 |
return sorted([r for r in revs if r in realheads]) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 |
return sorted(realheads) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 |
def changelogrevision(self, nodeorrev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 |
# Ensure we have a node id |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 |
if isinstance(nodeorrev, int): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 |
n = self.node(nodeorrev) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 |
else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 |
n = nodeorrev |
47052
f8fa7ec53517
git: initialize `extra` to have at least the branch name for nullid
Matt Harbison <matt_harbison@yahoo.com>
parents:
47050
diff
changeset
|
221 |
extra = {b'branch': b'default'} |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
# handle looking up nullid |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
223 |
if n == sha1nodeconstants.nullid: |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
224 |
return hgchangelog._changelogrevision( |
47057 | 225 |
extra=extra, manifest=sha1nodeconstants.nullid |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
226 |
) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 |
hn = gitutil.togitnode(n) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
228 |
# We've got a real commit! |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
229 |
files = [ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 |
r[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
for r in self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 |
'SELECT filename FROM changedfiles ' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
233 |
'WHERE node = ? and filenode != ?', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 |
(hn, gitutil.nullgit), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
236 |
] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
237 |
filesremoved = [ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
238 |
r[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
239 |
for r in self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
240 |
'SELECT filename FROM changedfiles ' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
241 |
'WHERE node = ? and filenode = ?', |
47048
03c73fc6f89a
git: use the proper filenode for deleted files in changelog.changelogrevision
Matt Harbison <matt_harbison@yahoo.com>
parents:
47046
diff
changeset
|
242 |
(hn, gitutil.nullgit), |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
243 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
244 |
] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 |
c = self.gitrepo[hn] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
246 |
return hgchangelog._changelogrevision( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 |
manifest=n, # pretend manifest the same as the commit node |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
248 |
user=b'%s <%s>' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 |
% (c.author.name.encode('utf8'), c.author.email.encode('utf8')), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
250 |
date=(c.author.time, -c.author.offset * 60), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 |
files=files, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
252 |
# TODO filesadded in the index |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
253 |
filesremoved=filesremoved, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
254 |
description=c.message.encode('utf8'), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 |
# TODO do we want to handle extra? how? |
47052
f8fa7ec53517
git: initialize `extra` to have at least the branch name for nullid
Matt Harbison <matt_harbison@yahoo.com>
parents:
47050
diff
changeset
|
256 |
extra=extra, |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
257 |
) |
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 |
def ancestors(self, revs, stoprev=0, inclusive=False): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
260 |
revs = list(revs) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
261 |
tip = self.rev(self.tip()) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
262 |
for r in revs: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
263 |
if r > tip: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
264 |
raise IndexError(b'Invalid rev %r' % r) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 |
return ancestor.lazyancestors( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 |
self.parentrevs, revs, stoprev=stoprev, inclusive=inclusive |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
267 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
268 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 |
# Cleanup opportunity: this is *identical* to the revlog.py version |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 |
def descendants(self, revs): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
271 |
return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 |
|
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
273 |
def incrementalmissingrevs(self, common=None): |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
274 |
"""Return an object that can be used to incrementally compute the |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
275 |
revision numbers of the ancestors of arbitrary sets that are not |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
276 |
ancestors of common. This is an ancestor.incrementalmissingancestors |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
277 |
object. |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
278 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
279 |
'common' is a list of revision numbers. If common is not supplied, uses |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
280 |
nullrev. |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
281 |
""" |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
282 |
if common is None: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
283 |
common = [nullrev] |
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
284 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
285 |
return ancestor.incrementalmissingancestors(self.parentrevs, common) |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
286 |
|
49386
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
287 |
def findmissingrevs(self, common=None, heads=None): |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
288 |
"""Return the revision numbers of the ancestors of heads that |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
289 |
are not ancestors of common. |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
290 |
|
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
291 |
More specifically, return a list of revision numbers corresponding to |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
292 |
nodes N such that every N satisfies the following constraints: |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
293 |
|
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
294 |
1. N is an ancestor of some node in 'heads' |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
295 |
2. N is not an ancestor of any node in 'common' |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
296 |
|
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
297 |
The list is sorted by revision number, meaning it is |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
298 |
topologically sorted. |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
299 |
|
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
300 |
'heads' and 'common' are both lists of revision numbers. If heads is |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
301 |
not supplied, uses all of the revlog's heads. If common is not |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
302 |
supplied, uses nullid.""" |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
303 |
if common is None: |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
304 |
common = [nullrev] |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
305 |
if heads is None: |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
306 |
heads = self.headrevs() |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
307 |
|
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
308 |
inc = self.incrementalmissingrevs(common=common) |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
309 |
return inc.missingancestors(heads) |
1e12ea7d8435
git: copy findmissingrevs() from revlog.py to gitlog.py (issue6472)
Anton Shestakov <av6@dwimlabs.net>
parents:
49288
diff
changeset
|
310 |
|
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
311 |
def findmissing(self, common=None, heads=None): |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
312 |
"""Return the ancestors of heads that are not ancestors of common. |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
313 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
314 |
More specifically, return a list of nodes N such that every N |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
315 |
satisfies the following constraints: |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
316 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
317 |
1. N is an ancestor of some node in 'heads' |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
318 |
2. N is not an ancestor of any node in 'common' |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
319 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
320 |
The list is sorted by revision number, meaning it is |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
321 |
topologically sorted. |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
322 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
323 |
'heads' and 'common' are both lists of node IDs. If heads is |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
324 |
not supplied, uses all of the revlog's heads. If common is not |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
325 |
supplied, uses nullid.""" |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
326 |
if common is None: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
327 |
common = [sha1nodeconstants.nullid] |
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
328 |
if heads is None: |
51304
d91b55371d6f
git-hgext: adjust to the lack of `changelog.heads` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49386
diff
changeset
|
329 |
heads = [self.node(r) for r in self.headrevs()] |
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
330 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
331 |
common = [self.rev(n) for n in common] |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
332 |
heads = [self.rev(n) for n in heads] |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
333 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
334 |
inc = self.incrementalmissingrevs(common=common) |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
335 |
return [self.node(r) for r in inc.missingancestors(heads)] |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
336 |
|
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
337 |
def children(self, node): |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
338 |
"""find the children of a given node""" |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
339 |
c = [] |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
340 |
p = self.rev(node) |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
341 |
for r in self.revs(start=p + 1): |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
342 |
prevs = [pr for pr in self.parentrevs(r) if pr != nullrev] |
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
343 |
if prevs: |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
344 |
for pr in prevs: |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
345 |
if pr == p: |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
346 |
c.append(self.node(r)) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
347 |
elif p == nullrev: |
44845
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
348 |
c.append(self.node(r)) |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
349 |
return c |
3e09d22a0bf5
git: implement some changelog methods
Romain DEP. <rom1dep@gmail.com>
parents:
44844
diff
changeset
|
350 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
351 |
def reachableroots(self, minroot, heads, roots, includepath=False): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
352 |
return dagop._reachablerootspure( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
353 |
self.parentrevs, minroot, roots, heads, includepath |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
354 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
355 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 |
# Cleanup opportunity: this is *identical* to the revlog.py version |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
357 |
def isancestor(self, a, b): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
358 |
a, b = self.rev(a), self.rev(b) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
359 |
return self.isancestorrev(a, b) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
360 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
361 |
# Cleanup opportunity: this is *identical* to the revlog.py version |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
362 |
def isancestorrev(self, a, b): |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
363 |
if a == nullrev: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
364 |
return True |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
365 |
elif a == b: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
366 |
return True |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
367 |
elif a > b: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
368 |
return False |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
369 |
return bool(self.reachableroots(a, [b], [a], includepath=False)) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
370 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
371 |
def parentrevs(self, rev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
372 |
n = self.node(rev) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
373 |
hn = gitutil.togitnode(n) |
44844
8bfc6cc8e480
git: avoid looking-up parents for the null commit
Romain DEP. <rom1dep@gmail.com>
parents:
44484
diff
changeset
|
374 |
if hn != gitutil.nullgit: |
8bfc6cc8e480
git: avoid looking-up parents for the null commit
Romain DEP. <rom1dep@gmail.com>
parents:
44484
diff
changeset
|
375 |
c = self.gitrepo[hn] |
8bfc6cc8e480
git: avoid looking-up parents for the null commit
Romain DEP. <rom1dep@gmail.com>
parents:
44484
diff
changeset
|
376 |
else: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
377 |
return nullrev, nullrev |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
378 |
p1 = p2 = nullrev |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
379 |
if c.parents: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
380 |
p1 = self.rev(c.parents[0].id.raw) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
381 |
if len(c.parents) > 2: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
382 |
raise error.Abort(b'TODO octopus merge handling') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
383 |
if len(c.parents) == 2: |
44480
f19491aae641
gitlog: fix embarassing bug that prevented log from showing correct parents
Augie Fackler <raf@durin42.com>
parents:
44478
diff
changeset
|
384 |
p2 = self.rev(c.parents[1].id.raw) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
385 |
return p1, p2 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
386 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
387 |
# Private method is used at least by the tags code. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
388 |
_uncheckedparentrevs = parentrevs |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
389 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
390 |
def commonancestorsheads(self, a, b): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
391 |
# TODO the revlog verson of this has a C path, so we probably |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
392 |
# need to optimize this... |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
393 |
a, b = self.rev(a), self.rev(b) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
394 |
return [ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
395 |
self.node(n) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
396 |
for n in ancestor.commonancestorsheads(self.parentrevs, a, b) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
397 |
] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
398 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
399 |
def branchinfo(self, rev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
400 |
"""Git doesn't do named branches, so just put everything on default.""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
401 |
return b'default', False |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
402 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
403 |
def delayupdate(self, tr): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
404 |
# TODO: I think we can elide this because we're just dropping |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
405 |
# an object in the git repo? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
406 |
pass |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
407 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
408 |
def add( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
409 |
self, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
410 |
manifest, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
411 |
files, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
412 |
desc, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
413 |
transaction, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
414 |
p1, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
415 |
p2, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
416 |
user, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
417 |
date=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
418 |
extra=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
419 |
p1copies=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
420 |
p2copies=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
421 |
filesadded=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
422 |
filesremoved=None, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
423 |
): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
424 |
parents = [] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
425 |
hp1, hp2 = gitutil.togitnode(p1), gitutil.togitnode(p2) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
426 |
if 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
|
427 |
parents.append(hp1) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
428 |
if p2 and p2 != sha1nodeconstants.nullid: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
429 |
parents.append(hp2) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
430 |
assert date is not None |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
431 |
timestamp, tz = date |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
432 |
sig = pygit2.Signature( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
433 |
encoding.unifromlocal(stringutil.person(user)), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
434 |
encoding.unifromlocal(stringutil.email(user)), |
45521
e7587430ca23
git: also convert timezone to int (issue6359)
Augie Fackler <augie@google.com>
parents:
45414
diff
changeset
|
435 |
int(timestamp), |
45413
8ddbb75bad09
git: convert tz offset to int (issue6359)
Augie Fackler <raf@durin42.com>
parents:
44951
diff
changeset
|
436 |
-int(tz // 60), |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
437 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
438 |
oid = self.gitrepo.create_commit( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
439 |
None, sig, sig, desc, gitutil.togitnode(manifest), parents |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
440 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
441 |
# Set up an internal reference to force the commit into the |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
442 |
# changelog. Hypothetically, we could even use this refs/hg/ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
443 |
# namespace to allow for anonymous heads on git repos, which |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
444 |
# would be neat. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
445 |
self.gitrepo.references.create( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
446 |
'refs/hg/internal/latest-commit', oid, force=True |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
447 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
448 |
# Reindex now to pick up changes. We omit the progress |
44951
83e41b73d115
git: add debug logging when there's a mismatch in the cached heads list
Augie Fackler <augie@google.com>
parents:
44845
diff
changeset
|
449 |
# and log callbacks because this will be very quick. |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
450 |
index._index_repo(self.gitrepo, self._db) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
451 |
return oid.raw |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
452 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
453 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
454 |
class manifestlog(baselog): |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
455 |
nodeconstants = sha1nodeconstants |
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
456 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
457 |
def __getitem__(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
458 |
return self.get(b'', node) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
459 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
460 |
def get(self, relpath, node): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
461 |
if node == sha1nodeconstants.nullid: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
462 |
# TODO: this should almost certainly be a memgittreemanifestctx |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
463 |
return manifest.memtreemanifestctx(self, relpath) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
464 |
commit = self.gitrepo[gitutil.togitnode(node)] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
465 |
t = commit.tree |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
466 |
if relpath: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
467 |
parts = relpath.split(b'/') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
468 |
for p in parts: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
469 |
te = t[p] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
470 |
t = self.gitrepo[te.id] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
471 |
return gitmanifest.gittreemanifestctx(self.gitrepo, t) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
472 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
473 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
474 |
@interfaceutil.implementer(repository.ifilestorage) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
475 |
class filelog(baselog): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
476 |
def __init__(self, gr, db, path): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
477 |
super(filelog, self).__init__(gr, db) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
478 |
assert isinstance(path, bytes) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
479 |
self.path = path |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
480 |
self.nullid = sha1nodeconstants.nullid |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
481 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
482 |
def read(self, node): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46795
diff
changeset
|
483 |
if node == sha1nodeconstants.nullid: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
484 |
return b'' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
485 |
return self.gitrepo[gitutil.togitnode(node)].data |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
486 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
487 |
def lookup(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
488 |
if len(node) not in (20, 40): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
489 |
node = int(node) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
490 |
if isinstance(node, int): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
491 |
assert False, b'todo revnums for nodes' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
492 |
if len(node) == 40: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
493 |
node = bin(node) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
494 |
hnode = gitutil.togitnode(node) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
495 |
if hnode in self.gitrepo: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
496 |
return node |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
497 |
raise error.LookupError(self.path, node, _(b'no match found')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
498 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
499 |
def cmp(self, node, text): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
500 |
"""Returns True if text is different than content at `node`.""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
501 |
return self.read(node) != text |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
502 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
503 |
def add(self, text, meta, transaction, link, p1=None, p2=None): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
504 |
assert not meta # Should we even try to handle this? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
505 |
return self.gitrepo.create_blob(text).raw |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
506 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
507 |
def __iter__(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
508 |
for clrev in self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
509 |
''' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
510 |
SELECT rev FROM changelog |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
511 |
INNER JOIN changedfiles ON changelog.node = changedfiles.node |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
512 |
WHERE changedfiles.filename = ? AND changedfiles.filenode != ? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
513 |
''', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
514 |
(pycompat.fsdecode(self.path), gitutil.nullgit), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
515 |
): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
516 |
yield clrev[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
517 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
518 |
def linkrev(self, fr): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
519 |
return fr |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
520 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
521 |
def rev(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
522 |
row = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
523 |
''' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
524 |
SELECT rev FROM changelog |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
525 |
INNER JOIN changedfiles ON changelog.node = changedfiles.node |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
526 |
WHERE changedfiles.filename = ? AND changedfiles.filenode = ?''', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
527 |
(pycompat.fsdecode(self.path), gitutil.togitnode(node)), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
528 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
529 |
if row is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
530 |
raise error.LookupError(self.path, node, _(b'no such node')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
531 |
return int(row[0]) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
532 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
533 |
def node(self, rev): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
534 |
maybe = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
535 |
'''SELECT filenode FROM changedfiles |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
536 |
INNER JOIN changelog ON changelog.node = changedfiles.node |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
537 |
WHERE changelog.rev = ? AND filename = ? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
538 |
''', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
539 |
(rev, pycompat.fsdecode(self.path)), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
540 |
).fetchone() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
541 |
if maybe is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
542 |
raise IndexError('gitlog %r out of range %d' % (self.path, rev)) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
543 |
return bin(maybe[0]) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
544 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
545 |
def parents(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
546 |
gn = gitutil.togitnode(node) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
547 |
gp = pycompat.fsdecode(self.path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
548 |
ps = [] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
549 |
for p in self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
550 |
'''SELECT p1filenode, p2filenode FROM changedfiles |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
551 |
WHERE filenode = ? AND filename = ? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
552 |
''', |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
553 |
(gn, gp), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
554 |
).fetchone(): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
555 |
if p is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
556 |
commit = self._db.execute( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
557 |
"SELECT node FROM changedfiles " |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
558 |
"WHERE filenode = ? AND filename = ?", |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
559 |
(gn, gp), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
560 |
).fetchone()[0] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
561 |
# This filelog is missing some data. Build the |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
562 |
# filelog, then recurse (which will always find data). |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
49284
diff
changeset
|
563 |
commit = commit.decode('ascii') |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
564 |
index.fill_in_filelog(self.gitrepo, self._db, commit, gp, gn) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
565 |
return self.parents(node) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
566 |
else: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45939
diff
changeset
|
567 |
ps.append(bin(p)) |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
568 |
return ps |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
569 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
570 |
def renamed(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
571 |
# TODO: renames/copies |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
572 |
return False |