Переглянути джерело

Add implementation of 'show' for porcelain.

Jelmer Vernooij 11 роки тому
батько
коміт
c32cd5ee61
3 змінених файлів з 35 додано та 1 видалено
  1. 7 1
      bin/dulwich
  2. 17 0
      dulwich/porcelain.py
  3. 11 0
      dulwich/tests/test_porcelain.py

+ 7 - 1
bin/dulwich

@@ -184,6 +184,11 @@ def cmd_update_server_info(args):
     porcelain.update_server_info(".")
 
 
+def cmd_show(args):
+    opts, args = getopt(args, "", [])
+    porcelain.show(".")
+
+
 commands = {
     "commit": cmd_commit,
     "fetch-pack": cmd_fetch_pack,
@@ -197,7 +202,8 @@ commands = {
     "update-server-info": cmd_update_server_info,
     "diff": cmd_diff,
     "add": cmd_add,
-    "rm": cmd_rm
+    "rm": cmd_rm,
+    "show": cmd_show,
     }
 
 if len(sys.argv) < 2:

+ 17 - 0
dulwich/porcelain.py

@@ -20,6 +20,7 @@ import os
 import sys
 
 from dulwich.client import get_transport_and_path
+from dulwich.patch import write_tree_diff
 from dulwich.repo import (BaseRepo, Repo)
 from dulwich.server import update_server_info as server_update_server_info
 
@@ -176,3 +177,19 @@ def log(repo=".", outstream=sys.stdout):
     walker = r.get_walker()
     for entry in walker:
         print_commit(entry.commit, outstream)
+
+
+def show(repo=".", committish=None, outstream=sys.stdout):
+    """Print the changes in a commit.
+
+    :param repo: Path to repository
+    :param committish: Commit to write
+    :param outstream: Stream to write to
+    """
+    if committish is None:
+        committish = "HEAD"
+    r = open_repo(repo)
+    commit = r[committish]
+    parent_commit = r[commit.parents[0]]
+    print_commit(commit, outstream)
+    write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)

+ 11 - 0
dulwich/tests/test_porcelain.py

@@ -141,3 +141,14 @@ class LogTests(PorcelainTestCase):
         outstream = StringIO()
         porcelain.log(self.repo.path, outstream=outstream)
         self.assertTrue(outstream.getvalue().startswith("-" * 50))
+
+
+class ShowTests(PorcelainTestCase):
+
+    def test_simple(self):
+        c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
+            [3, 1, 2]])
+        self.repo.refs["HEAD"] = c3.id
+        outstream = StringIO()
+        porcelain.show(self.repo.path, committish=c3.id, outstream=outstream)
+        self.assertTrue(outstream.getvalue().startswith("-" * 50))