3 from git_python
import Git
6 """Simple storage class containing stats on the activity in one file."""
14 return str(self
.count
) + ": +" + str(self
.added
) + " -" + str(self
.deleted
)
16 def activityInArea(log
, filterid
):
17 """Parses the specified file containing commit logs.
18 The output is filtered to contain only the results of the specified author.
19 The output is expected to be in the format described below:
22 [<lines added>\t<lines deleted>\t<path>]+
27 log: The log formatted as described above.
28 filterid: The id address to filter on.
31 A dictionary containing activity per path is returned.
32 Each path contains one Activity object with the aggregated results.
35 # Create a dict to store the activity stats per path
38 # Create a place to store the result in
43 # Parse all the lines in the file
47 # Split the line at the tab and store the data
48 splitline
= line
.split('\t')
50 length
= len(line
.lstrip())
52 # There is something on this line, but it contains no separator
53 if size
== 1 and length
> 0:
54 # Get the id address minus the newline
55 activity
.id.append(line
[:-1])
58 addpart
= splitline
[0]
59 deletepart
= splitline
[1]
67 activity
.added
= int(addpart
)
68 activity
.deleted
= int(deletepart
)
70 print("On line '" + str(i
) + "', could not convert number: " + str(e
))
72 path
= splitline
[2][:-1]
74 if not filterid
in activity
.id:
75 # Ignore other authors
80 # If we already encountered this path, update the count
81 if activityByPath
.has_key(path
):
82 known
= activityByPath
[path
]
83 result
.added
= known
.added
+ activity
.added
84 result
.deleted
= known
.deleted
+ activity
.deleted
85 result
.count
= known
.count
+ activity
.count
89 # Store it under it's path
90 activityByPath
[path
] = result
92 # Create a fresh activity to store the next round in
95 print("Cannot parse line " + str(i
) + ".")
101 """Shows the activity for the specified developer in the current repo.
104 id: The id of the developer, currently only e-mail address is accepted.
108 result
= git
.log("--numstat", "--pretty=format:%ae")
110 log
= result
.splitlines(True)
111 activity
= activityInArea(log
, id)
113 for key
, value
in activity
.iteritems():
114 print(str(key
) + " = " + str(value
))
117 """Dispatches author related commands
122 if __name__
== '__main__':
123 path
= "testrepo.log"
128 log
= file.readlines()
130 activity
= activityInArea(log
, "sverre@rabbelier.nl")
132 for key
, value
in activity
.iteritems():
133 print(str(key
) + " = " + str(value
))