File: latest_change.py

package info (click to toggle)
dulwich 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,388 kB
  • sloc: python: 99,991; makefile: 163; sh: 67
file content (27 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

# Example printing the last author of a specified file

import sys
import time

from dulwich.repo import Repo

if len(sys.argv) < 2:
    print(f"usage: {sys.argv[0]} filename")
    sys.exit(1)

r = Repo(".")

path = sys.argv[1].encode("utf-8")

w = r.get_walker(paths=[path], max_entries=1)
try:
    c = next(iter(w)).commit
except StopIteration:
    print(f"No file {sys.argv[1]} anywhere in history.")
else:
    print(
        f"{sys.argv[1]} was last changed by {c.author} at {time.ctime(c.author_time)} (commit {c.id})"
    )