Browse Source

Fix 'dulwich diff'. Fixes #935

Jelmer Vernooij 3 years ago
parent
commit
a92ab5e826
2 changed files with 9 additions and 9 deletions
  1. 8 8
      dulwich/cli.py
  2. 1 1
      dulwich/porcelain.py

+ 8 - 8
dulwich/cli.py

@@ -40,8 +40,8 @@ from dulwich import porcelain
 from dulwich.client import get_transport_and_path
 from dulwich.errors import ApplyDeltaError
 from dulwich.index import Index
+from dulwich.objectspec import parse_commit
 from dulwich.pack import Pack, sha_to_hex
-from dulwich.patch import write_tree_diff
 from dulwich.repo import Repo
 
 
@@ -172,15 +172,15 @@ class cmd_diff(Command):
     def run(self, args):
         opts, args = getopt(args, "", [])
 
-        if args == []:
-            print("Usage: dulwich diff COMMITID")
-            sys.exit(1)
-
         r = Repo(".")
-        commit_id = args[0]
-        commit = r[commit_id]
+        if args == []:
+            commit_id = b'HEAD'
+        else:
+            commit_id = args[0]
+        commit = parse_commit(r, commit_id)
         parent_commit = r[commit.parents[0]]
-        write_tree_diff(sys.stdout, r.object_store, parent_commit.tree, commit.tree)
+        porcelain.diff_tree(
+            r, parent_commit.tree, commit.tree, outstream=sys.stdout.buffer)
 
 
 class cmd_dump_pack(Command):

+ 1 - 1
dulwich/porcelain.py

@@ -831,7 +831,7 @@ def show(
             show_object(r, o, decode, outstream)
 
 
-def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
+def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout.buffer):
     """Compares the content and mode of blobs found via two tree objects.
 
     Args: