-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore gix APIs, experiment with gix-blame API #1453
Open
cruessler
wants to merge
15
commits into
GitoxideLabs:main
Choose a base branch
from
cruessler:gix-blame
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
984fad3
Add initial implementation and tests for `gix-blame`.
cruessler 1f225d3
Update meta-data to include `gix-blame` crate
Byron bee2ec1
feat: Add `blame` plumbing crate to the top-level.
cruessler ba5bc6f
feat: add `gix blame` to the CLI
cruessler 6102c83
Pass blame to more than one parent
cruessler e4c2e97
Add ignored test for resolved merge conflict
cruessler b0aea31
Replace expect by ?
cruessler a7cb234
Correctly pass blame for some merge commits
cruessler 02083c0
Adapt to changes in gix-diff
cruessler a6e9e32
Add failing test
cruessler 89e54c7
Add shortcut when oid is identical to parent's
cruessler a7d9b0b
Walk commits in topological order
cruessler f9bd9ec
Add shortcut when oid is identical to parent's
cruessler 79539f0
Update gix-blame dependencies
cruessler 0f1da23
let `gitoxide-core` enable the `blame` feature in `gix` by default.
Byron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::{ffi::OsStr, path::PathBuf, str::Lines}; | ||
|
||
use anyhow::anyhow; | ||
use gix::bstr::BStr; | ||
|
||
pub fn blame_file(mut repo: gix::Repository, file: &OsStr, out: impl std::io::Write) -> anyhow::Result<()> { | ||
repo.object_cache_size_if_unset(repo.compute_object_cache_size_for_tree_diffs(&**repo.index_or_empty()?)); | ||
|
||
let suspect = repo.head()?.peel_to_commit_in_place()?; | ||
let traverse: Vec<_> = | ||
gix::traverse::commit::topo::Builder::from_iters(&repo.objects, [suspect.id], None::<Vec<gix::ObjectId>>) | ||
.build()? | ||
.collect(); | ||
let mut resource_cache = repo.diff_resource_cache_for_tree_diff()?; | ||
|
||
let work_dir: PathBuf = repo | ||
.work_dir() | ||
.ok_or_else(|| anyhow!("blame needs a workdir, but there is none"))? | ||
.into(); | ||
let file_path: &BStr = gix::path::os_str_into_bstr(file)?; | ||
|
||
let blame_entries = gix::blame::blame_file( | ||
&repo.objects, | ||
traverse, | ||
&mut resource_cache, | ||
suspect.id, | ||
work_dir.clone(), | ||
file_path, | ||
)?; | ||
|
||
let absolute_path = work_dir.join(file); | ||
let file_content = std::fs::read_to_string(absolute_path)?; | ||
let lines = file_content.lines(); | ||
|
||
write_blame_entries(out, lines, blame_entries)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn write_blame_entries( | ||
mut out: impl std::io::Write, | ||
mut lines: Lines<'_>, | ||
blame_entries: Vec<gix::blame::BlameEntry>, | ||
) -> Result<(), std::io::Error> { | ||
for blame_entry in blame_entries { | ||
for line_number in blame_entry.range_in_blamed_file { | ||
let line = lines.next().unwrap(); | ||
|
||
writeln!( | ||
out, | ||
"{} {} {}", | ||
blame_entry.commit_id.to_hex_with_len(8), | ||
// `line_number` is 0-based, but we want to show 1-based line numbers (as `git` | ||
// does). | ||
line_number + 1, | ||
line | ||
)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ name = "gix-blame" | |
version = "0.0.0" | ||
repository = "https://github.com/GitoxideLabs/gitoxide" | ||
license = "MIT OR Apache-2.0" | ||
description = "A crate of the gitoxide project dedicated implementing a 'blame' algorithm" | ||
description = "A crate of the gitoxide project dedicated to implementing a 'blame' algorithm" | ||
authors = ["Christoph Rüßler <[email protected]>", "Sebastian Thiel <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.65" | ||
|
@@ -14,6 +14,16 @@ rust-version = "1.65" | |
doctest = false | ||
|
||
[dependencies] | ||
gix-diff = { version = "^0.47.0", path = "../gix-diff", default-features = false, features = ["blob"] } | ||
gix-object = { version = "^0.45.0", path = "../gix-object" } | ||
gix-hash = { version = "^0.15.0", path = "../gix-hash" } | ||
gix-worktree = { version = "^0.37.0", path = "../gix-worktree", default-features = false, features = ["attributes"] } | ||
gix-traverse = { version = "^0.42.0", path = "../gix-traverse" } | ||
|
||
[dev-dependencies] | ||
gix-ref = { version = "^0.48.0", path = "../gix-ref" } | ||
gix-filter = { version = "^0.14.0", path = "../gix-filter" } | ||
gix-fs = { version = "^0.12.0", path = "../gix-fs" } | ||
gix-index = { version = "^0.36.0", path = "../gix-index" } | ||
gix-odb = { version = "^0.64.0", path = "../gix-odb" } | ||
gix-testtools = { path = "../tests/tools" } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Byron This makes compiliation on CI fail as
gix::blame
is behind a feature flag. I feel like I’ve hit this issue already in the past, but I forgot how to resolve it. Would you be able to help me? :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting - looks like the
blame
feature disappeared from the list somehow. In any case, it's back now and CI should get past this point (even though clippy has some legit complaints I locally at least).