ソースを参照

Add porcelain for diff-tree.

Jelmer Vernooij 11 年 前
コミット
8d4d28cb9b
3 ファイル変更32 行追加0 行削除
  1. 9 0
      bin/dulwich
  2. 12 0
      dulwich/porcelain.py
  3. 11 0
      dulwich/tests/test_porcelain.py

+ 9 - 0
bin/dulwich

@@ -199,6 +199,14 @@ def cmd_show(args):
     porcelain.show(".")
 
 
+def cmd_diff_tree(args):
+    opts, args = getopt(args, "", [])
+    if len(args) < 2:
+        print "Usage: dulwich diff-tree OLD-TREE NEW-TREE"
+        sys.exit(1)
+    porcelain.diff_tree(".", args[0], args[1])
+
+
 commands = {
     "commit": cmd_commit,
     "fetch-pack": cmd_fetch_pack,
@@ -215,6 +223,7 @@ commands = {
     "add": cmd_add,
     "rm": cmd_rm,
     "show": cmd_show,
+    "diff-tree": cmd_diff_tree,
     }
 
 if len(sys.argv) < 2:

+ 12 - 0
dulwich/porcelain.py

@@ -215,3 +215,15 @@ def show(repo=".", committish=None, outstream=sys.stdout):
     parent_commit = r[commit.parents[0]]
     print_commit(commit, outstream)
     write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)
+
+
+def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
+    """Compares the content and mode of blobs found via two tree objects.
+
+    :param repo: Path to repository
+    :param old_tree: Id of old tree
+    :param new_tree: Id of new tree
+    :param outstream: Stream to write to
+    """
+    r = open_repo(repo)
+    write_tree_diff(outstream, r.object_store, old_tree, new_tree)

+ 11 - 0
dulwich/tests/test_porcelain.py

@@ -201,3 +201,14 @@ class SymbolicRefTests(PorcelainTestCase):
         #test if we actually changed the file
         new_ref = self.repo.get_named_file('HEAD').read()
         self.assertEqual(new_ref, 'ref: refs/heads/develop\n')
+
+
+class DiffTreeTests(PorcelainTestCase):
+
+    def test_empty(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.diff_tree(self.repo.path, c2.tree, c3.tree, outstream=outstream)
+        self.assertEquals(outstream.getvalue(), "")