Skip to content

Commit

Permalink
only diff files that are probably not a binary file (as per extension…
Browse files Browse the repository at this point in the history
…). (#470)

We assume unguessable ones are a plain text file, like one without
extension.
  • Loading branch information
Byron committed Sep 20, 2022
1 parent e27b65a commit 2a3c5b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gitoxide-core/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ default = []
## Discover all git repositories within a directory. Particularly useful with [skim](https://github.com/lotabout/skim).
organize = ["git-url", "jwalk"]
## Derive the amount of time invested into a git repository akin to [git-hours](https://github.com/kimmobrunfeldt/git-hours).
estimate-hours = ["itertools", "fs-err", "num_cpus", "crossbeam-channel"]
estimate-hours = ["itertools", "fs-err", "num_cpus", "crossbeam-channel", "mime_guess"]

#! ### Mutually Exclusive Networking
#! If both are set, _blocking-client_ will take precedence, allowing `--all-features` to be used.
Expand Down Expand Up @@ -64,6 +64,7 @@ itertools = { version = "0.10.1", optional = true }
fs-err = { version = "2.6.0", optional = true }
num_cpus = { version = "1.13.1", optional = true }
crossbeam-channel = { version = "0.5.6", optional = true }
mime_guess = { version = "2.0.4", optional = true }

document-features = { version = "0.2.0", optional = true }

Expand Down
50 changes: 29 additions & 21 deletions gitoxide-core/src/hours.rs
Expand Up @@ -171,7 +171,7 @@ where
Some(c) => c,
None => continue,
};
from.changes().for_each_to_obtain_tree(&to, |change| {
from.changes().track_filename().for_each_to_obtain_tree(&to, |change| {
use git::object::tree::diff::change::Event::*;
if let Some(c) = change_counter.as_ref() {
c.fetch_add(1, Ordering::SeqCst);
Expand Down Expand Up @@ -205,29 +205,37 @@ where
if entry_mode.is_no_tree() {
files.modified += 1;
}
if let Some(Ok(diff)) =
line_stats.then(|| change.event.diff()).flatten()
{
use git::diff::lines::similar::ChangeTag::*;
let mut nl = 0;
for change in diff
.text(git::diff::lines::Algorithm::Myers)
.iter_all_changes()
if line_stats {
let is_text_file = mime_guess::from_path(
git::path::from_bstr(change.location).as_ref(),
)
.first_or_text_plain()
.type_()
== mime_guess::mime::TEXT;
if let Some(Ok(diff)) =
is_text_file.then(|| change.event.diff()).flatten()
{
match change.tag() {
Delete => {
lines.removed += 1;
nl += 1;
use git::diff::lines::similar::ChangeTag::*;
let mut nl = 0;
for change in diff
.text(git::diff::lines::Algorithm::Myers)
.iter_all_changes()
{
match change.tag() {
Delete => {
lines.removed += 1;
nl += 1;
}
Insert => {
lines.added += 1;
nl += 1
}
Equal => {}
}
Insert => {
lines.added += 1;
nl += 1
}
Equal => {}
}
}
if let Some(c) = lines_counter.as_ref() {
c.fetch_add(nl, Ordering::SeqCst);
if let Some(c) = lines_counter.as_ref() {
c.fetch_add(nl, Ordering::SeqCst);
}
}
}
}
Expand Down

0 comments on commit 2a3c5b0

Please sign in to comment.