diff.py 604 B

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