changeset 8112:135bbd1862cf

vcs: minor cleanup Make it more friendly to humans and py3.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 27 Dec 2019 00:26:41 +0100
parents 4eacfdf08b9a
children c78fd87d362b
files kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/git/repository.py kallithea/lib/vcs/backends/hg/repository.py
diffstat 3 files changed, 22 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/changeset.py	Fri Dec 27 01:55:52 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Fri Dec 27 00:26:41 2019 +0100
@@ -98,7 +98,7 @@
     @LazyProperty
     def branches(self):
         heads = self.repository._heads(reverse=True)
-        return [b for b in heads if heads[b] == self.raw_id] # FIXME: Inefficient ... and returning None!
+        return [b for b in heads if heads[b] == self._commit.id] # FIXME: Inefficient ... and returning None!
 
     def _fix_path(self, path):
         """
--- a/kallithea/lib/vcs/backends/git/repository.py	Fri Dec 27 01:55:52 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/repository.py	Fri Dec 27 00:26:41 2019 +0100
@@ -157,7 +157,6 @@
         On failures it'll raise urllib2.HTTPError, exception is also thrown
         when the return code is non 200
         """
-
         # check first if it's not an local url
         if os.path.isdir(url) or url.startswith('file:'):
             return True
@@ -188,10 +187,11 @@
         o = urllib2.build_opener(*handlers)
         o.addheaders = [('User-Agent', 'git/1.7.8.0')]  # fake some git
 
-        q = {"service": 'git-upload-pack'}
-        qs = '?%s' % urllib.urlencode(q)
-        cu = "%s%s" % (test_uri, qs)
-        req = urllib2.Request(cu, None, {})
+        req = urllib2.Request(
+            "%s?%s" % (
+                test_uri,
+                urllib.urlencode({"service": 'git-upload-pack'})
+            ))
 
         try:
             resp = o.open(req)
@@ -252,8 +252,8 @@
 
     def _get_all_revisions2(self):
         # alternate implementation using dulwich
-        includes = [ascii_str(x[1][0]) for x in self._parsed_refs.iteritems()
-                    if x[1][1] != b'T']
+        includes = [ascii_str(sha) for key, (sha, type_) in self._parsed_refs.iteritems()
+                    if type_ != b'T']
         return [c.commit.id for c in self._repo.get_walker(include=includes)]
 
     def _get_revision(self, revision):
@@ -368,8 +368,8 @@
         if not self.revisions:
             return {}
         sortkey = lambda ctx: ctx[0]
-        _branches = [(x[0], ascii_str(x[1][0]))
-                     for x in self._parsed_refs.iteritems() if x[1][1] == b'H']
+        _branches = [(key, ascii_str(sha))
+                     for key, (sha, type_) in self._parsed_refs.iteritems() if type_ == b'H']
         return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
 
     @LazyProperty
@@ -385,8 +385,8 @@
             return {}
 
         sortkey = lambda ctx: ctx[0]
-        _tags = [(x[0], ascii_str(x[1][0]))
-                 for x in self._parsed_refs.iteritems() if x[1][1] == b'T']
+        _tags = [(key, ascii_str(sha))
+                 for key, (sha, type_) in self._parsed_refs.iteritems() if type_ == b'T']
         return OrderedDict(sorted(_tags, key=sortkey, reverse=True))
 
     def tag(self, name, user, revision=None, message=None, date=None,
@@ -488,9 +488,7 @@
         """
         if isinstance(revision, GitChangeset):
             return revision
-        revision = self._get_revision(revision)
-        changeset = GitChangeset(repository=self, revision=revision)
-        return changeset
+        return GitChangeset(repository=self, revision=self._get_revision(revision))
 
     def get_changesets(self, start=None, end=None, start_date=None,
            end_date=None, branch_name=None, reverse=False, max_revisions=None):
--- a/kallithea/lib/vcs/backends/hg/repository.py	Fri Dec 27 01:55:52 2019 +0100
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Fri Dec 27 00:26:41 2019 +0100
@@ -75,7 +75,6 @@
             raise VCSError('Mercurial backend requires repository path to '
                            'be instance of <str> got %s instead' %
                            type(repo_path))
-
         self.path = abspath(repo_path)
         self.baseui = baseui or mercurial.ui.ui()
         # We've set path and ui, now we can set _repo itself
@@ -324,11 +323,14 @@
         o.addheaders = [('Content-Type', 'application/mercurial-0.1'),
                         ('Accept', 'application/mercurial-0.1')]
 
-        q = {"cmd": 'between'}
-        q.update({'pairs': "%s-%s" % ('0' * 40, '0' * 40)})
-        qs = '?%s' % urllib.urlencode(q)
-        cu = "%s%s" % (test_uri, qs)
-        req = urllib2.Request(cu, None, {})
+        req = urllib2.Request(
+            "%s?%s" % (
+                test_uri,
+                urllib.urlencode({
+                    'cmd': 'between',
+                    'pairs': "%s-%s" % ('0' * 40, '0' * 40),
+                })
+            ))
 
         try:
             resp = o.open(req)
@@ -359,7 +361,6 @@
         location at given clone_point. Additionally it'll make update to
         working copy accordingly to ``update_after_clone`` flag
         """
-
         try:
             if src_url:
                 url = safe_bytes(self._get_url(src_url))
@@ -502,9 +503,7 @@
         Returns ``MercurialChangeset`` object representing repository's
         changeset at the given ``revision``.
         """
-        revision = self._get_revision(revision)
-        changeset = MercurialChangeset(repository=self, revision=revision)
-        return changeset
+        return MercurialChangeset(repository=self, revision=self._get_revision(revision))
 
     def get_changesets(self, start=None, end=None, start_date=None,
                        end_date=None, branch_name=None, reverse=False, max_revisions=None):