Skip to content

Commit 654a726

Browse files
authored
Merge pull request #141 from o2sh/feature/no-merges
Feature/no merges
2 parents 1e10bd2 + f09d556 commit 654a726

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Diff for: src/info.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,14 @@ impl Info {
286286
disabled: InfoFieldOn,
287287
bold_flag: bool,
288288
custom_image: Option<DynamicImage>,
289+
no_merges: bool,
289290
) -> Result<Info> {
290-
let authors = Info::get_authors(&dir, 3);
291+
let authors = Info::get_authors(&dir, no_merges, 3);
291292
let (git_v, git_user) = Info::get_git_info(&dir);
292293
let current_commit_info = Info::get_current_commit_info(&dir)?;
293294
let config = Info::get_configuration(&dir)?;
294295
let version = Info::get_version(&dir)?;
295-
let commits = Info::get_commits(&dir)?;
296+
let commits = Info::get_commits(&dir, no_merges)?;
296297
let repo_size = Info::get_packed_size(&dir)?;
297298
let last_change = Info::get_last_change(&dir)?;
298299
let creation_date = Info::get_creation_time(dir)?;
@@ -325,12 +326,14 @@ impl Info {
325326
}
326327

327328
// Return first n most active commiters as authors within this project.
328-
fn get_authors(dir: &str, n: usize) -> Vec<(String, usize, usize)> {
329+
fn get_authors(dir: &str, no_merges: bool, n: usize) -> Vec<(String, usize, usize)> {
330+
let mut args = vec!["-C", dir, "log", "--format='%aN'"];
331+
if no_merges {
332+
args.push("--no-merges");
333+
}
334+
329335
let output = Command::new("git")
330-
.arg("-C")
331-
.arg(dir)
332-
.arg("log")
333-
.arg("--format='%aN'")
336+
.args(args)
334337
.output()
335338
.expect("Failed to execute git.");
336339

@@ -468,13 +471,15 @@ impl Info {
468471
}
469472
}
470473

471-
fn get_commits(dir: &str) -> Result<String> {
474+
fn get_commits(dir: &str, no_merges: bool) -> Result<String> {
475+
let mut args = vec!["-C", dir, "rev-list", "--count"];
476+
if no_merges {
477+
args.push("--no-merges");
478+
}
479+
args.push("HEAD");
480+
472481
let output = Command::new("git")
473-
.arg("-C")
474-
.arg(dir)
475-
.arg("rev-list")
476-
.arg("--count")
477-
.arg("HEAD")
482+
.args(args)
478483
.output()
479484
.expect("Failed to execute git.");
480485

Diff for: src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
179179
.long("image")
180180
.takes_value(true)
181181
.help("Sets a custom image to use instead of the ascii logo"),
182+
).arg(
183+
Arg::with_name("no-merges")
184+
.short("m")
185+
.long("no-merges")
186+
.help("Prevents merge commits from being counted"),
182187
)
183188
.get_matches();
184189

@@ -239,13 +244,16 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
239244
None
240245
};
241246

247+
let no_merges = matches.is_present("no-merges");
248+
242249
let info = Info::new(
243250
&dir,
244251
custom_logo,
245252
custom_colors,
246253
disable_fields,
247254
bold_flag,
248255
custom_image,
256+
no_merges,
249257
)?;
250258

251259
print!("{}", info);

0 commit comments

Comments
 (0)