2
0

latest_change.py 586 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python
  2. # Example printing the last author of a specified file
  3. import sys
  4. import time
  5. from dulwich.repo import Repo
  6. if len(sys.argv) < 2:
  7. print(f"usage: {sys.argv[0]} filename")
  8. sys.exit(1)
  9. r = Repo(".")
  10. path = sys.argv[1].encode("utf-8")
  11. w = r.get_walker(paths=[path], max_entries=1)
  12. try:
  13. c = next(iter(w)).commit
  14. except StopIteration:
  15. print("No file %s anywhere in history." % sys.argv[1])
  16. else:
  17. print(
  18. "{} was last changed by {} at {} (commit {})".format(
  19. sys.argv[1], c.author, time.ctime(c.author_time), c.id
  20. )
  21. )