Parcourir la source

Fix build on Python3, update NEWS.

Jelmer Vernooij il y a 6 ans
Parent
commit
4529549600
3 fichiers modifiés avec 11 ajouts et 7 suppressions
  1. 4 0
      NEWS
  2. 5 5
      dulwich/porcelain.py
  3. 2 2
      dulwich/tests/test_porcelain.py

+ 4 - 0
NEWS

@@ -1,5 +1,9 @@
 0.19.5	UNRELEASED
 
+ IMPROVEMENTS
+
+  * Add ``porcelain.describe``. (Sylvia van Os)
+
  BUG FIXES
 
   * Fix regression in ``dulwich.porcelain.clone`` that prevented cloning

+ 5 - 5
dulwich/porcelain.py

@@ -1319,7 +1319,7 @@ def describe(repo):
                 commit = r.get_object(commit[1])
             tags[tag] = [
                 datetime.datetime(*time.gmtime(commit.commit_time)[:6]),
-                commit.id.decode('utf-8'),
+                commit.id.decode('ascii'),
             ]
 
         sorted_tags = sorted(tags.items(),
@@ -1328,7 +1328,7 @@ def describe(repo):
 
         # If there are no tags, return the current commit
         if len(sorted_tags) == 0:
-            return 'g{}'.format(r[r.head()].id.decode('utf-8')[:7])
+            return 'g{}'.format(r[r.head()].id.decode('ascii')[:7])
 
         # We're now 0 commits from the top
         commit_count = 0
@@ -1340,7 +1340,7 @@ def describe(repo):
         walker = r.get_walker()
         for entry in walker:
             # Check if tag
-            commit_id = entry.commit.id.decode('utf-8')
+            commit_id = entry.commit.id.decode('ascii')
             for tag in sorted_tags:
                 tag_name = tag[0]
                 tag_commit = tag[1][1]
@@ -1351,9 +1351,9 @@ def describe(repo):
                         return '{}-{}-g{}'.format(
                                 tag_name,
                                 commit_count,
-                                latest_commit.id.decode('utf-8')[:7])
+                                latest_commit.id.decode('ascii')[:7])
 
             commit_count += 1
 
         # Return plain commit if no parent tag can be found
-        return 'g{}'.format(latest_commit.id.decode('utf-8')[:7])
+        return 'g{}'.format(latest_commit.id.decode('ascii')[:7])

+ 2 - 2
dulwich/tests/test_porcelain.py

@@ -1392,7 +1392,7 @@ class DescribeTests(PorcelainTestCase):
                 author=b"Joe <joe@example.com>",
                 committer=b"Bob <bob@example.com>")
         self.assertEqual(
-                'g{}'.format(str(sha)[:7]),
+                'g{}'.format(sha[:7].decode('ascii')),
                 porcelain.describe(self.repo.path))
 
     def test_tag(self):
@@ -1429,5 +1429,5 @@ class DescribeTests(PorcelainTestCase):
                 author=b"Joe <joe@example.com>",
                 committer=b"Bob <bob@example.com>")
         self.assertEqual(
-                'tryme-1-g{}'.format(str(sha)[:7]),
+                'tryme-1-g{}'.format(sha[:7].decode('ascii')),
                 porcelain.describe(self.repo.path))