Browse Source

Fix examples on Python3.

Jelmer Vernooij 8 years ago
parent
commit
3ea005cc2c
2 changed files with 6 additions and 3 deletions
  1. 3 2
      examples/diff.py
  2. 3 1
      examples/latest_change.py

+ 3 - 2
examples/diff.py

@@ -10,10 +10,11 @@ from dulwich.patch import write_tree_diff
 import sys
 
 repo_path = "."
-commit_id = "a6602654997420bcfd0bee2a0563d9416afe34b4"
+commit_id = b"a6602654997420bcfd0bee2a0563d9416afe34b4"
 
 r = Repo(repo_path)
 
 commit = r[commit_id]
 parent_commit = r[commit.parents[0]]
-write_tree_diff(sys.stdout, r.object_store, parent_commit.tree, commit.tree)
+outstream = getattr(sys.stdout, 'buffer', sys.stdout)
+write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)

+ 3 - 1
examples/latest_change.py

@@ -11,7 +11,9 @@ if len(sys.argv) < 2:
 
 r = Repo(".")
 
-w = r.get_walker(paths=[sys.argv[1]], max_entries=1)
+path = sys.argv[1].encode('utf-8')
+
+w = r.get_walker(paths=[path], max_entries=1)
 try:
     c = next(iter(w)).commit
 except StopIteration: