latest_change.py 607 B

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