equal
deleted
inserted
replaced
3 from mercurial.i18n import _ |
3 from mercurial.i18n import _ |
4 |
4 |
5 from mercurial.node import ( |
5 from mercurial.node import ( |
6 bin, |
6 bin, |
7 hex, |
7 hex, |
8 nullhex, |
|
9 nullid, |
|
10 nullrev, |
8 nullrev, |
11 sha1nodeconstants, |
9 sha1nodeconstants, |
12 wdirhex, |
|
13 ) |
10 ) |
14 from mercurial import ( |
11 from mercurial import ( |
15 ancestor, |
12 ancestor, |
16 changelog as hgchangelog, |
13 changelog as hgchangelog, |
17 dagop, |
14 dagop, |
45 return int( |
42 return int( |
46 self._db.execute('SELECT COUNT(*) FROM changelog').fetchone()[0] |
43 self._db.execute('SELECT COUNT(*) FROM changelog').fetchone()[0] |
47 ) |
44 ) |
48 |
45 |
49 def rev(self, n): |
46 def rev(self, n): |
50 if n == nullid: |
47 if n == sha1nodeconstants.nullid: |
51 return -1 |
48 return -1 |
52 t = self._db.execute( |
49 t = self._db.execute( |
53 'SELECT rev FROM changelog WHERE node = ?', (gitutil.togitnode(n),) |
50 'SELECT rev FROM changelog WHERE node = ?', (gitutil.togitnode(n),) |
54 ).fetchone() |
51 ).fetchone() |
55 if t is None: |
52 if t is None: |
56 raise error.LookupError(n, b'00changelog.i', _(b'no node %d')) |
53 raise error.LookupError(n, b'00changelog.i', _(b'no node %d')) |
57 return t[0] |
54 return t[0] |
58 |
55 |
59 def node(self, r): |
56 def node(self, r): |
60 if r == nullrev: |
57 if r == nullrev: |
61 return nullid |
58 return sha1nodeconstants.nullid |
62 t = self._db.execute( |
59 t = self._db.execute( |
63 'SELECT node FROM changelog WHERE rev = ?', (r,) |
60 'SELECT node FROM changelog WHERE rev = ?', (r,) |
64 ).fetchone() |
61 ).fetchone() |
65 if t is None: |
62 if t is None: |
66 raise error.LookupError(r, b'00changelog.i', _(b'no node')) |
63 raise error.LookupError(r, b'00changelog.i', _(b'no node')) |
132 def nodemap(self): |
129 def nodemap(self): |
133 r = { |
130 r = { |
134 bin(v[0]): v[1] |
131 bin(v[0]): v[1] |
135 for v in self._db.execute('SELECT node, rev FROM changelog') |
132 for v in self._db.execute('SELECT node, rev FROM changelog') |
136 } |
133 } |
137 r[nullid] = nullrev |
134 r[sha1nodeconstants.nullid] = nullrev |
138 return r |
135 return r |
139 |
136 |
140 def tip(self): |
137 def tip(self): |
141 t = self._db.execute( |
138 t = self._db.execute( |
142 'SELECT node FROM changelog ORDER BY rev DESC LIMIT 1' |
139 'SELECT node FROM changelog ORDER BY rev DESC LIMIT 1' |
143 ).fetchone() |
140 ).fetchone() |
144 if t: |
141 if t: |
145 return bin(t[0]) |
142 return bin(t[0]) |
146 return nullid |
143 return sha1nodeconstants.nullid |
147 |
144 |
148 def revs(self, start=0, stop=None): |
145 def revs(self, start=0, stop=None): |
149 if stop is None: |
146 if stop is None: |
150 stop = self.tip() |
147 stop = self.tip() |
151 t = self._db.execute( |
148 t = self._db.execute( |
161 'SELECT rev FROM changelog ' 'ORDER BY REV DESC ' 'LIMIT 1' |
158 'SELECT rev FROM changelog ' 'ORDER BY REV DESC ' 'LIMIT 1' |
162 ) |
159 ) |
163 return next(t) |
160 return next(t) |
164 |
161 |
165 def _partialmatch(self, id): |
162 def _partialmatch(self, id): |
166 if wdirhex.startswith(id): |
163 if sha1nodeconstants.wdirhex.startswith(id): |
167 raise error.WdirUnsupported |
164 raise error.WdirUnsupported |
168 candidates = [ |
165 candidates = [ |
169 bin(x[0]) |
166 bin(x[0]) |
170 for x in self._db.execute( |
167 for x in self._db.execute( |
171 'SELECT node FROM changelog WHERE node LIKE ?', (id + b'%',) |
168 'SELECT node FROM changelog WHERE node LIKE ?', (id + b'%',) |
172 ) |
169 ) |
173 ] |
170 ] |
174 if nullhex.startswith(id): |
171 if sha1nodeconstants.nullhex.startswith(id): |
175 candidates.append(nullid) |
172 candidates.append(sha1nodeconstants.nullid) |
176 if len(candidates) > 1: |
173 if len(candidates) > 1: |
177 raise error.AmbiguousPrefixLookupError( |
174 raise error.AmbiguousPrefixLookupError( |
178 id, b'00changelog.i', _(b'ambiguous identifier') |
175 id, b'00changelog.i', _(b'ambiguous identifier') |
179 ) |
176 ) |
180 if candidates: |
177 if candidates: |
215 if isinstance(nodeorrev, int): |
212 if isinstance(nodeorrev, int): |
216 n = self.node(nodeorrev) |
213 n = self.node(nodeorrev) |
217 else: |
214 else: |
218 n = nodeorrev |
215 n = nodeorrev |
219 # handle looking up nullid |
216 # handle looking up nullid |
220 if n == nullid: |
217 if n == sha1nodeconstants.nullid: |
221 return hgchangelog._changelogrevision(extra={}, manifest=nullid) |
218 return hgchangelog._changelogrevision( |
|
219 extra={}, manifest=sha1nodeconstants.nullid |
|
220 ) |
222 hn = gitutil.togitnode(n) |
221 hn = gitutil.togitnode(n) |
223 # We've got a real commit! |
222 # We've got a real commit! |
224 files = [ |
223 files = [ |
225 r[0] |
224 r[0] |
226 for r in self._db.execute( |
225 for r in self._db.execute( |
232 filesremoved = [ |
231 filesremoved = [ |
233 r[0] |
232 r[0] |
234 for r in self._db.execute( |
233 for r in self._db.execute( |
235 'SELECT filename FROM changedfiles ' |
234 'SELECT filename FROM changedfiles ' |
236 'WHERE node = ? and filenode = ?', |
235 'WHERE node = ? and filenode = ?', |
237 (hn, nullhex), |
236 (hn, sha1nodeconstants.nullhex), |
238 ) |
237 ) |
239 ] |
238 ] |
240 c = self.gitrepo[hn] |
239 c = self.gitrepo[hn] |
241 return hgchangelog._changelogrevision( |
240 return hgchangelog._changelogrevision( |
242 manifest=n, # pretend manifest the same as the commit node |
241 manifest=n, # pretend manifest the same as the commit node |
293 |
292 |
294 'heads' and 'common' are both lists of node IDs. If heads is |
293 'heads' and 'common' are both lists of node IDs. If heads is |
295 not supplied, uses all of the revlog's heads. If common is not |
294 not supplied, uses all of the revlog's heads. If common is not |
296 supplied, uses nullid.""" |
295 supplied, uses nullid.""" |
297 if common is None: |
296 if common is None: |
298 common = [nullid] |
297 common = [sha1nodeconstants.nullid] |
299 if heads is None: |
298 if heads is None: |
300 heads = self.heads() |
299 heads = self.heads() |
301 |
300 |
302 common = [self.rev(n) for n in common] |
301 common = [self.rev(n) for n in common] |
303 heads = [self.rev(n) for n in heads] |
302 heads = [self.rev(n) for n in heads] |
392 filesadded=None, |
391 filesadded=None, |
393 filesremoved=None, |
392 filesremoved=None, |
394 ): |
393 ): |
395 parents = [] |
394 parents = [] |
396 hp1, hp2 = gitutil.togitnode(p1), gitutil.togitnode(p2) |
395 hp1, hp2 = gitutil.togitnode(p1), gitutil.togitnode(p2) |
397 if p1 != nullid: |
396 if p1 != sha1nodeconstants.nullid: |
398 parents.append(hp1) |
397 parents.append(hp1) |
399 if p2 and p2 != nullid: |
398 if p2 and p2 != sha1nodeconstants.nullid: |
400 parents.append(hp2) |
399 parents.append(hp2) |
401 assert date is not None |
400 assert date is not None |
402 timestamp, tz = date |
401 timestamp, tz = date |
403 sig = pygit2.Signature( |
402 sig = pygit2.Signature( |
404 encoding.unifromlocal(stringutil.person(user)), |
403 encoding.unifromlocal(stringutil.person(user)), |
427 |
426 |
428 def __getitem__(self, node): |
427 def __getitem__(self, node): |
429 return self.get(b'', node) |
428 return self.get(b'', node) |
430 |
429 |
431 def get(self, relpath, node): |
430 def get(self, relpath, node): |
432 if node == nullid: |
431 if node == sha1nodeconstants.nullid: |
433 # TODO: this should almost certainly be a memgittreemanifestctx |
432 # TODO: this should almost certainly be a memgittreemanifestctx |
434 return manifest.memtreemanifestctx(self, relpath) |
433 return manifest.memtreemanifestctx(self, relpath) |
435 commit = self.gitrepo[gitutil.togitnode(node)] |
434 commit = self.gitrepo[gitutil.togitnode(node)] |
436 t = commit.tree |
435 t = commit.tree |
437 if relpath: |
436 if relpath: |
446 class filelog(baselog): |
445 class filelog(baselog): |
447 def __init__(self, gr, db, path): |
446 def __init__(self, gr, db, path): |
448 super(filelog, self).__init__(gr, db) |
447 super(filelog, self).__init__(gr, db) |
449 assert isinstance(path, bytes) |
448 assert isinstance(path, bytes) |
450 self.path = path |
449 self.path = path |
|
450 self.nullid = sha1nodeconstants.nullid |
451 |
451 |
452 def read(self, node): |
452 def read(self, node): |
453 if node == nullid: |
453 if node == sha1nodeconstants.nullid: |
454 return b'' |
454 return b'' |
455 return self.gitrepo[gitutil.togitnode(node)].data |
455 return self.gitrepo[gitutil.togitnode(node)].data |
456 |
456 |
457 def lookup(self, node): |
457 def lookup(self, node): |
458 if len(node) not in (20, 40): |
458 if len(node) not in (20, 40): |