Skip to content

Commit 7b905a3

Browse files
committed
Added example.png
1 parent 1862f23 commit 7b905a3

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ These are flags that you probably won't need to use, but they're here if you nee
3636

3737
### Examples
3838

39+
![Example](assets/example.png)
40+
41+
Here are some examples of how to use `blame-tracker.py`:
42+
3943
```bash
4044
# Print the blame for all C files (recursively) in the current repository.
4145
blame-tracker.py -in "**/*.c"

assets/example.png

327 KB
Loading

blame-tracker.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def main():
6161
parser.add_argument('-t1', '--until', dest='end_date', type=str, help='The end date📅 in ISO 8601 format (default is now).', default=datetime.now().isoformat())
6262
parser.add_argument('-d', '--days-ago', type=int, help='The number of days ago⏱️ to shift the search.', default=0)
6363
parser.add_argument('-w', '--weeks-ago', type=int, help='The number of weeks ago⏱️ to shift the search.', default=0)
64+
parser.add_argument('-m', '--minutes-ago', type=int, help='The number of minutes ago⏱️ to shift the search.', default=0)
6465
parser.add_argument('-in', '--include', dest='include', type=str, help='The file patterns📂 to search for (default is "**/*").', default=['**/*'], nargs='+')
6566
parser.add_argument('-ex', '--exclude', type=str, help='The file patterns📂 to exclude (default is none).', default=[], nargs='+')
6667
parser.add_argument('-f', '--format', type=str, help=f'The format string🧶 to print each accusation (default is "{DEFAULT_FORMAT}")', default=DEFAULT_FORMAT)
@@ -113,11 +114,15 @@ def main():
113114
if args.verbose >= 3:
114115
# Print debug information if verbose level is 3 or higher
115116
info("Collecting accusations...")
116-
117+
# Get the list of files to search
118+
files = get_files(args.repo, args.include, args.exclude)
119+
if args.verbose >= 1:
120+
# Print info messages if verbose level is 1 or higher
121+
info(f"searching for blame in:")
122+
for i, file in enumerate(files):
123+
info(f" {i+1}. {file}")
117124
# Collect the accusations
118-
accusations_by_file = accuse_files(
119-
args.repo, get_files(args.repo, args.include, args.exclude),
120-
args.verbose, args.silence_warnings)
125+
accusations_by_file = accuse_files(args.repo, files, args.verbose, args.silence_warnings)
121126

122127
if args.verbose >= 3:
123128
# Print debug information if verbose level is 3 or higher
@@ -189,19 +194,15 @@ def main():
189194
total_non_blank = sum([stats['non-blank'] for stats in authors_stats.values()])
190195

191196
for author, stats in authors_stats.items():
192-
if args.author and author.lower() not in args.author:
193-
# If the user specified an author, filter out accusations by
194-
# other authors. If the user did not specify an author, include
195-
# all accusations.
196-
continue
197197
# Print the statistics for each author
198198
info(f'{author}:')
199+
info(f' {stats["chars"]} characters')
199200
info(f' {stats["lines"]} lines')
200201
info(f' {stats["non-blank-lines"]} non-whitespace lines')
201-
info(f' {stats["chars"]} characters')
202+
info(f' {stats["two-or-more-char-lines"]} two-or-more-char lines')
202203
info(f' {stats["non-blank"]} non-whitespace characters')
203204
# Print the percentage of non-blank characters written by the author
204-
info(f' {stats["non-blank"] / float(total_non_blank) * 100:2.0f}% of code since {start_date.month:02d}/{start_date.day:02d}/{start_date.year}')
205+
info(f' Composes {stats["non-blank"] / float(total_non_blank) * 100:2.0f}% of changes since {start_date.month:02d}/{start_date.day:02d}/{start_date.year}')
205206

206207
if not all_accusations and not args.silence_warnings:
207208
# Print a message if no authors were found
@@ -245,7 +246,7 @@ def analyze_author(author: str, accusations: list[tuple[str, datetime, str]]) ->
245246
return stats[author]
246247
else:
247248
# If the author has no accusations, return 0 for all statistics
248-
return {'lines': 0, 'chars': 0, 'non-blank': 0, 'non-blank-lines': 0, 'avg-line-len': 0}
249+
return {'lines': 0, 'chars': 0, 'non-blank': 0, 'two-or-more-char-lines': 0, 'non-blank-lines': 0, 'avg-line-len': 0}
249250

250251
def analyze_authors(accusations: list[tuple[str, datetime, str]]) -> dict[str, dict[str, int]]:
251252
'''
@@ -273,11 +274,14 @@ def analyze_authors(accusations: list[tuple[str, datetime, str]]) -> dict[str, d
273274
for author, _, content in accusations:
274275
author = author.lower()
275276
# Get the author's statistics
276-
result.setdefault(author, {'lines': 0, 'chars': 0, 'non-blank': 0, 'non-blank-lines': 0, 'avg-line-len': 0})
277+
result.setdefault(author, {'lines': 0, 'chars': 0, 'two-or-more-char-lines': 0, 'non-blank': 0, 'non-blank-lines': 0, 'avg-line-len': 0})
277278
result[author]['lines'] += 1
278-
if content.strip() == '':
279+
if content.strip() != '':
279280
# Check that the line is not blank, then increment the non-blank line count
280281
result[author]['non-blank-lines'] += 1
282+
if len(content.strip()) >= 2:
283+
# Check that the line is at least two characters long, then increment the two-or-more-char line count
284+
result[author]['two-or-more-char-lines'] += 1
281285
result[author]['chars'] += len(content)
282286
result[author]['non-blank'] += len(content.replace(' ', '').replace('\t', ''))
283287

0 commit comments

Comments
 (0)