I mostly added absolute_import and fixed warnings related to undefined name.
This should get folded in the main hgit RFC patch.
There are still more failures but they are harmless as of now.
pulkit |
hg-reviewers |
I mostly added absolute_import and fixed warnings related to undefined name.
This should get folded in the main hgit RFC patch.
There are still more failures but they are harmless as of now.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/git/__init__.py (2 lines) | |||
M | hgext/git/dirstate.py (6 lines) | |||
M | hgext/git/gitlog.py (12 lines) | |||
M | hgext/git/index.py (5 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
564265c816d5 | d28f43c8ddb8 | Pulkit Goyal | Aug 19 2019, 6:34 AM |
"""Grant Mercurial the ability to operate on Git repositories. (EXPERIMENTAL) | """Grant Mercurial the ability to operate on Git repositories. (EXPERIMENTAL) | ||||
This is currently super experimental. It probably will consume your | This is currently super experimental. It probably will consume your | ||||
firstborn a la Rumpelstiltskin, etc. | firstborn a la Rumpelstiltskin, etc. | ||||
""" | """ | ||||
from __future__ import absolute_import | |||||
import os | import os | ||||
from mercurial import ( | from mercurial import ( | ||||
commands, | commands, | ||||
debugcommands, | debugcommands, | ||||
extensions, | extensions, | ||||
hg, | hg, | ||||
localrepo, | localrepo, |
from __future__ import absolute_import | |||||
import errno | import errno | ||||
import os | import os | ||||
import stat | import stat | ||||
from mercurial import ( | from mercurial import ( | ||||
dirstate, | dirstate, | ||||
error, | error, | ||||
extensions, | extensions, | ||||
match as matchmod, | match as matchmod, | ||||
node as nodemod, | node as nodemod, | ||||
parsers, | parsers, | ||||
scmutil, | scmutil, | ||||
util, | util, | ||||
) | ) | ||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
import pygit2 | import pygit2 | ||||
def readpatternfile(orig, filepath, warn, sourceinfo=False): | def readpatternfile(orig, filepath, warn, sourceinfo=False): | ||||
if not ('info/exclude' in fp.name or fp.name.endswith('.gitignore')): | if not ('info/exclude' in filepath or filepath.endswith('.gitignore')): | ||||
return orig(filepath, warn, sourceinfo=False) | return orig(filepath, warn, sourceinfo=False) | ||||
result = [] | result = [] | ||||
warnings = [] | warnings = [] | ||||
with open(filepath, 'rb') as fp: | with open(filepath, 'rb') as fp: | ||||
for l in fp: | for l in fp: | ||||
l = l.strip() | l = l.strip() | ||||
if not l or l.startswith('#'): | if not l or l.startswith('#'): | ||||
continue | continue | ||||
update_needed = bool(flags & (1 << 14)) | update_needed = bool(flags & (1 << 14)) | ||||
stage = (flags >> 12) & 3 # this is used during merge. | stage = (flags >> 12) & 3 # this is used during merge. | ||||
# Not sure quite what it is though. | # Not sure quite what it is though. | ||||
state = 'n' # XXX THIS IS A LIE | state = 'n' # XXX THIS IS A LIE | ||||
# this should be 'a' for adds and 'r' for removes | # this should be 'a' for adds and 'r' for removes | ||||
# git stores symlinks with a mode of 000, we need it to be 777 | # git stores symlinks with a mode of 000, we need it to be 777 | ||||
if mode == stat.S_IFLNK: | if mode == stat.S_IFLNK: | ||||
mode = mode | 0777 | mode = mode | 0o777 | ||||
# this is a crude hack, but makes 'hg forget' work | # this is a crude hack, but makes 'hg forget' work | ||||
if p not in p1: | if p not in p1: | ||||
state = 'a' | state = 'a' | ||||
self._map[p] = parsers.dirstatetuple(state, mode, size, mtime) | self._map[p] = parsers.dirstatetuple(state, mode, size, mtime) |
from __future__ import absolute_import | |||||
from mercurial.i18n import _ | |||||
from mercurial import ( | from mercurial import ( | ||||
ancestor, | ancestor, | ||||
changelog as hgchangelog, | changelog as hgchangelog, | ||||
error, | error, | ||||
manifest, | manifest, | ||||
node as nodemod, | node as nodemod, | ||||
revlog, | revlog, | ||||
) | ) | ||||
def rev(self, n): | def rev(self, n): | ||||
if n == nodemod.nullid: | if n == nodemod.nullid: | ||||
return -1 | return -1 | ||||
t = self._db.execute( | t = self._db.execute( | ||||
'SELECT rev FROM changelog WHERE node = ?', | 'SELECT rev FROM changelog WHERE node = ?', | ||||
(nodemod.hex(n),)).fetchone() | (nodemod.hex(n),)).fetchone() | ||||
if t is None: | if t is None: | ||||
raise error.LookupError(node, '00changelog.i', _('no node')) | raise error.LookupError(n, '00changelog.i', _('no node')) | ||||
return t[0] | return t[0] | ||||
def node(self, r): | def node(self, r): | ||||
if r == nodemod.nullrev: | if r == nodemod.nullrev: | ||||
return nodemod.nullid | return nodemod.nullid | ||||
t = self._db.execute( | t = self._db.execute( | ||||
'SELECT node FROM changelog WHERE rev = ?', | 'SELECT node FROM changelog WHERE rev = ?', | ||||
(r,)).fetchone() | (r,)).fetchone() | ||||
if t is None: | if t is None: | ||||
raise error.LookupError(node, '00changelog.i', _('no node')) | raise error.LookupError(r, '00changelog.i', _('no node')) | ||||
return nodemod.bin(t[0]) | return nodemod.bin(t[0]) | ||||
# TODO: an interface for the changelog type? | # TODO: an interface for the changelog type? | ||||
class changelog(baselog): | class changelog(baselog): | ||||
@property | @property | ||||
def filteredrevs(self): | def filteredrevs(self): | ||||
def parentrevs(self, rev): | def parentrevs(self, rev): | ||||
n = self.node(rev) | n = self.node(rev) | ||||
hn = nodemod.hex(n) | hn = nodemod.hex(n) | ||||
c = self.gitrepo[hn] | c = self.gitrepo[hn] | ||||
p1 = p2 = nodemod.nullrev | p1 = p2 = nodemod.nullrev | ||||
if c.parents: | if c.parents: | ||||
p1 = self.rev(c.parents[0].id.raw) | p1 = self.rev(c.parents[0].id.raw) | ||||
if len(c.parents) > 2: | if len(c.parents) > 2: | ||||
raise util.Abort('TODO octopus merge handling') | raise error.Abort('TODO octopus merge handling') | ||||
if len(c.parents) == 2: | if len(c.parents) == 2: | ||||
p2 = self.rev(c.parents[0].id.raw) | p2 = self.rev(c.parents[0].id.raw) | ||||
return p1, p2 | return p1, p2 | ||||
# Private method is used at least by the tags code. | # Private method is used at least by the tags code. | ||||
_uncheckedparentrevs = parentrevs | _uncheckedparentrevs = parentrevs | ||||
def commonancestorsheads(self, a, b): | def commonancestorsheads(self, a, b): | ||||
if node == nodemod.nullid: | if node == nodemod.nullid: | ||||
return manifest.memtreemanifestctx(self, relpath) | return manifest.memtreemanifestctx(self, relpath) | ||||
commit = self.gitrepo[nodemod.hex(node)] | commit = self.gitrepo[nodemod.hex(node)] | ||||
t = commit.tree | t = commit.tree | ||||
if relpath: | if relpath: | ||||
parts = relpath.split('/') | parts = relpath.split('/') | ||||
for p in parts: | for p in parts: | ||||
te = t[p] | te = t[p] | ||||
t = repo[te.id] | t = self.gitrepo[te.id] | ||||
return gittreemanifestctx(t) | return gittreemanifestctx(t) | ||||
class filelog(baselog): | class filelog(baselog): | ||||
def __init__(self, gr, db, path): | def __init__(self, gr, db, path): | ||||
super(filelog, self).__init__(gr, db) | super(filelog, self).__init__(gr, db) | ||||
self.path = path | self.path = path | ||||
def read(self, node): | def read(self, node): |
from __future__ import absolute_import | |||||
import os | import os | ||||
import sqlite3 | import sqlite3 | ||||
from mercurial.i18n import _ | |||||
from mercurial import ( | from mercurial import ( | ||||
encoding, | encoding, | ||||
error, | |||||
node as nodemod, | node as nodemod, | ||||
) | ) | ||||
import pygit2 | import pygit2 | ||||
_CURRENT_SCHEMA_VERSION = 1 | _CURRENT_SCHEMA_VERSION = 1 | ||||
_SCHEMA = """ | _SCHEMA = """ | ||||
CREATE TABLE refs ( | CREATE TABLE refs ( |