Skip to content

Commit efe9d70

Browse files
committedOct 31, 2019
Add --no-merges flag for total commit count
Addresses #131
1 parent 110811a commit efe9d70

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed
 

Diff for: ‎src/info.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl std::fmt::Display for Info {
8888
iter.collect()
8989
}
9090
};
91-
91+
9292
for (cnt, language) in languages.iter().enumerate() {
9393
let formatted_number = format!("{:.*}", 2, language.1);
9494
if cnt != 0 && cnt % 3 == 0 {
@@ -223,14 +223,15 @@ impl Info {
223223
colors: Vec<String>,
224224
disabled: InfoFieldOn,
225225
bold_flag: bool,
226-
custom_image: Option<DynamicImage>
226+
custom_image: Option<DynamicImage>,
227+
no_merges: bool,
227228
) -> Result<Info> {
228229
let authors = Info::get_authors(&dir, 3);
229230
let (git_v, git_user) = Info::get_git_info(&dir);
230231
let current_commit_info = Info::get_current_commit_info(&dir)?;
231232
let config = Info::get_configuration(&dir)?;
232233
let version = Info::get_version(&dir)?;
233-
let commits = Info::get_commits(&dir)?;
234+
let commits = Info::get_commits(&dir, no_merges)?;
234235
let repo_size = Info::get_packed_size(&dir)?;
235236
let last_change = Info::get_last_change(&dir)?;
236237
let creation_date = Info::get_creation_time(dir)?;
@@ -407,13 +408,15 @@ impl Info {
407408
}
408409
}
409410

410-
fn get_commits(dir: &str) -> Result<String> {
411+
fn get_commits(dir: &str, no_merges: bool) -> Result<String> {
412+
let mut args = vec!["-C", dir, "rev-list", "--count"];
413+
if no_merges {
414+
args.push("--no-merges");
415+
}
416+
args.push("HEAD");
417+
411418
let output = Command::new("git")
412-
.arg("-C")
413-
.arg(dir)
414-
.arg("rev-list")
415-
.arg("--count")
416-
.arg("HEAD")
419+
.args(args)
417420
.output()
418421
.expect("Failed to execute git.");
419422

Diff for: ‎src/main.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
176176
.long("image")
177177
.takes_value(true)
178178
.help("Sets a custom image to use instead of the ascii logo"),
179+
).arg(
180+
Arg::with_name("no-merges")
181+
.long("no-merges")
182+
.help("Prevents merge commits from being counted"),
179183
)
180184
.get_matches();
181185

@@ -237,7 +241,17 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
237241
None
238242
};
239243

240-
let info = Info::new(&dir, custom_logo, custom_colors, disable_fields, bold_flag, custom_image)?;
244+
let no_merges = matches.is_present("no-merges");
245+
246+
let info = Info::new(
247+
&dir,
248+
custom_logo,
249+
custom_colors,
250+
disable_fields,
251+
bold_flag,
252+
custom_image,
253+
no_merges,
254+
)?;
241255

242256
print!("{}", info);
243257
Ok(())
@@ -255,4 +269,4 @@ fn is_git_installed() -> bool {
255269
struct Configuration {
256270
pub repository_name: String,
257271
pub repository_url: String,
258-
}
272+
}

0 commit comments

Comments
 (0)