@@ -79,24 +79,32 @@ def branch_tree(config: Dict[str, Union[str, int]]) -> None:
79
79
print ("No data available." )
80
80
81
81
82
- def branches_by_date () -> None :
82
+ def branches_by_date (config : Dict [ str , Union [ str , int ]] ) -> None :
83
83
"""
84
84
Lists branches sorted by the latest commit date.
85
85
86
86
Args:
87
- None
87
+ config: Dict[str, Union[str, int]]: Config dictionary holding env vars.
88
88
89
89
Returns:
90
90
None
91
91
"""
92
92
93
+ # Grab the config options from our config.py.
94
+ ignore_authors = config .get ("ignore_authors" , lambda _s : False )
95
+
93
96
# Original command:
94
97
# git for-each-ref --sort=committerdate refs/heads/ \
95
98
# --format='[%(authordate:relative)] %(authorname) %(refname:short)' | cat -n
96
99
# TODO: Wouldn't git log --pretty=format:'%ad' --date=short be better here?
97
100
# Then we could pipe it through sort, uniq -c, sort -nr, etc.
98
101
# Possibly feed back into the parent project
99
- format_str = "[%(authordate:relative)] %(authorname) %(refname:short)"
102
+
103
+ # Include the email so we can filter based off it, but keep the visible
104
+ # part the same as before.
105
+ visible_fmt = "[%(authordate:relative)] %(authorname) %(refname:short)"
106
+ format_str = f"{ visible_fmt } |%(authoremail)"
107
+
100
108
cmd = [
101
109
"git" ,
102
110
"for-each-ref" ,
@@ -106,19 +114,35 @@ def branches_by_date() -> None:
106
114
]
107
115
108
116
output = run_git_command (cmd )
109
- if output :
110
- # Split the output into lines
111
- lines = output . split ( " \n " )
117
+ if not output :
118
+ print ( "No commits found." )
119
+ return
112
120
113
- # Number the lines similar to 'cat -n'
114
- numbered_lines = [f"{ idx + 1 } { line } " for idx , line in enumerate (lines )]
121
+ # Split lines and filter by author (both name and email), but keep
122
+ # visible text only.
123
+ visible_lines = []
124
+ for raw in output .split ("\n " ):
125
+ if not raw .strip ():
126
+ continue
127
+ if "|" in raw :
128
+ visible , email = raw .split ("|" , 1 )
129
+ else :
130
+ visible , email = raw , ""
115
131
116
- # Output numbered lines
117
- print ("All branches (sorted by most recent commit):\n " )
118
- for line in numbered_lines :
119
- print (f"\t { line } " )
120
- else :
132
+ # Filter by either email or the visible chunk.
133
+ if ignore_authors (email ) or ignore_authors (visible ):
134
+ continue
135
+
136
+ visible_lines .append (visible )
137
+
138
+ if not visible_lines :
121
139
print ("No commits found." )
140
+ return
141
+
142
+ # Number like `cat -n`
143
+ print ("All branches (sorted by most recent commit):\n " )
144
+ for idx , line in enumerate (visible_lines , 1 ):
145
+ print (f"\t { idx } { line } " )
122
146
123
147
124
148
def contributors (config : Dict [str , Union [str , int ]]) -> None :
@@ -213,6 +237,7 @@ def new_contributors(config: Dict[str, Union[str, int]], new_date: str) -> None:
213
237
until = config .get ("until" , "" )
214
238
log_options = config .get ("log_options" , "" )
215
239
pathspec = config .get ("pathspec" , "" )
240
+ ignore_authors = config .get ("ignore_authors" , lambda _s : False )
216
241
217
242
# Original command:
218
243
# git -c log.showSignature=false log --use-mailmap $_merges \
@@ -245,6 +270,9 @@ def new_contributors(config: Dict[str, Union[str, int]], new_date: str) -> None:
245
270
try :
246
271
email , timestamp = line .split ("|" )
247
272
timestamp = int (timestamp )
273
+ # Skip ignored by email
274
+ if ignore_authors (email ):
275
+ continue
248
276
# If the contributor is not in the dictionary or the current timestamp is earlier
249
277
if email not in contributors_dict or timestamp < contributors_dict [email ]:
250
278
contributors_dict [email ] = timestamp
@@ -283,12 +311,14 @@ def new_contributors(config: Dict[str, Union[str, int]], new_date: str) -> None:
283
311
name_cmd = [arg for arg in name_cmd if arg ]
284
312
285
313
# Grab name + email if we can. Otherwise, just grab email
286
- name = run_git_command (name_cmd )
287
- if name :
288
- new_contributors_list .append ((name , email ))
289
- else :
290
- new_contributors_list .append (("" , email ))
291
-
314
+ # while also making sure to ignore any authors that may be
315
+ # in our ignore_author env var
316
+ name = (run_git_command (name_cmd ) or "" ).strip ()
317
+ combo = f"{ name } <{ email } >" if name else f"<{ email } >"
318
+ if ignore_authors (email ) or ignore_authors (name ) or ignore_authors (combo ):
319
+ continue
320
+
321
+ new_contributors_list .append ((name , email ))
292
322
# Sort the list alphabetically by name to match the original
293
323
# and print all of this out
294
324
if new_contributors_list :
0 commit comments