2
0

diff.py 545 B

123456789101112131415161718192021
  1. #!/usr/bin/python
  2. # This trivial script demonstrates how to extract the unified diff for a single
  3. # commit in a local repository.
  4. #
  5. # Example usage:
  6. # python examples/diff.py
  7. import sys
  8. from dulwich.patch import write_tree_diff
  9. from dulwich.repo import Repo
  10. repo_path = "."
  11. commit_id = b"a6602654997420bcfd0bee2a0563d9416afe34b4"
  12. r = Repo(repo_path)
  13. commit = r[commit_id]
  14. parent_commit = r[commit.parents[0]]
  15. outstream = getattr(sys.stdout, "buffer", sys.stdout)
  16. write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)