bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
1 |
"""Classify a commit based on the types of files it changed."""
|
2 |
||
3 |
from bzrlib import urlutils |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
4 |
from bzrlib.trace import mutter |
5 |
||
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
6 |
|
7 |
def classify_filename(name): |
|
8 |
"""Classify a file based on its name. |
|
9 |
|
|
10 |
:param name: File path.
|
|
11 |
:return: One of code, documentation, translation or art.
|
|
12 |
None if determining the file type failed.
|
|
13 |
"""
|
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
14 |
# FIXME: Use mime types? Ohcount?
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
15 |
basename = urlutils.basename(name) |
16 |
try: |
|
17 |
extension = basename.split(".")[1] |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
18 |
if extension in ("c", "h", "py", "cpp", "rb", "ac"): |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
19 |
return "code" |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
20 |
if extension in ("html", "xml", "txt", "rst", "TODO"): |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
21 |
return "documentation" |
22 |
if extension in ("po"): |
|
23 |
return "translation" |
|
24 |
if extension in ("svg", "png", "jpg"): |
|
25 |
return "art" |
|
26 |
except IndexError: |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
27 |
if basename in ("README", "NEWS", "TODO", |
28 |
"AUTHORS", "COPYING"): |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
29 |
return "documentation" |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
30 |
if basename in ("Makefile"): |
31 |
return "code" |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
32 |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
33 |
mutter("don't know how to classify %s", name) |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
34 |
return None |
35 |
||
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
36 |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
37 |
def classify_delta(delta): |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
38 |
"""Determine what sort of changes a delta contains. |
39 |
||
40 |
:param delta: A TreeDelta to inspect
|
|
41 |
:return: List with classes found (see classify_filename)
|
|
42 |
"""
|
|
43 |
# TODO: This is inaccurate, since it doesn't look at the
|
|
44 |
# number of lines changed in a file.
|
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
45 |
types = [] |
46 |
for d in delta.added + delta.modified: |
|
47 |
types.append(classify_filename(d[0])) |
|
48 |
return types |