D6747: hgit: fix some pyflakes and check-code warning

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Tue Aug 20 15:01:51 UTC 2019


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6747

AFFECTED FILES
  hgext/git/__init__.py
  hgext/git/dirstate.py
  hgext/git/gitlog.py
  hgext/git/index.py

CHANGE DETAILS

diff --git a/hgext/git/index.py b/hgext/git/index.py
--- a/hgext/git/index.py
+++ b/hgext/git/index.py
@@ -1,8 +1,13 @@
+from __future__ import absolute_import
+
 import os
 import sqlite3
 
+from mercurial.i18n import _
+
 from mercurial import (
     encoding,
+    error,
     node as nodemod,
 )
 
diff --git a/hgext/git/gitlog.py b/hgext/git/gitlog.py
--- a/hgext/git/gitlog.py
+++ b/hgext/git/gitlog.py
@@ -1,3 +1,7 @@
+from __future__ import absolute_import
+
+from mercurial.i18n import _
+
 from mercurial import (
     ancestor,
     changelog as hgchangelog,
@@ -24,7 +28,7 @@
             'SELECT rev FROM changelog WHERE node = ?',
             (nodemod.hex(n),)).fetchone()
         if t is None:
-            raise error.LookupError(node, '00changelog.i', _('no node'))
+            raise error.LookupError(n, '00changelog.i', _('no node'))
         return t[0]
 
     def node(self, r):
@@ -34,7 +38,7 @@
             'SELECT node FROM changelog WHERE rev = ?',
             (r,)).fetchone()
         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])
 
 
@@ -112,7 +116,7 @@
         if c.parents:
             p1 = self.rev(c.parents[0].id.raw)
             if len(c.parents) > 2:
-                raise util.Abort('TODO octopus merge handling')
+                raise error.Abort('TODO octopus merge handling')
             if len(c.parents) == 2:
                 p2 = self.rev(c.parents[0].id.raw)
         return p1, p2
@@ -172,7 +176,7 @@
             parts = relpath.split('/')
             for p in parts:
                 te = t[p]
-                t = repo[te.id]
+                t = self.gitrepo[te.id]
         return gittreemanifestctx(t)
 
 class filelog(baselog):
diff --git a/hgext/git/dirstate.py b/hgext/git/dirstate.py
--- a/hgext/git/dirstate.py
+++ b/hgext/git/dirstate.py
@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import errno
 import os
 import stat
@@ -18,7 +20,7 @@
 
 
 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)
     result = []
     warnings = []
@@ -270,7 +272,7 @@
 
             # git stores symlinks with a mode of 000, we need it to be 777
             if mode == stat.S_IFLNK:
-                mode = mode | 0777
+                mode = mode | 0o777
 
             # this is a crude hack, but makes 'hg forget' work
             if p not in p1:
diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py
--- a/hgext/git/__init__.py
+++ b/hgext/git/__init__.py
@@ -4,6 +4,8 @@
 firstborn a la Rumpelstiltskin, etc.
 """
 
+from __future__ import absolute_import
+
 import os
 
 from mercurial import (



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list