dandavison / dandavison/delta

🚀 Improve on git's function/class detection

Open
#259 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
32.2k
Forks
572
Avg merge
11m
Merged PRs (30d)
1

Description

The logic in `git diff --function-context` will always print the preceding function on the top line, since that's "technically" the preceding code. This happens even if -U0 is provided, unfortunately.

Note that here, other_routine is the top line, even though no changes are within other_routine.

```c
int other_routine() {
}

int main() {
puts("Hello, world!");
return 0;
}
```

```diff
$ git diff -U0 --function-context
diff --git i/example.c w/example.c
index 346e2a7..0b40a82 100644
--- i/example.c
+++ w/example.c
@@ -6,3 +6,4 @@ int other_routine() {
int main() {
puts("Hello, world!");
+ return 0;
}
\ No newline at end of file
```

This breaks scripts that rely on the top line to determine which function the changes are in, including `delta`.

Here we can see that `delta` boxes the name `other_routine`, based on this information.

Screen Shot 2020-07-20 at 5 44 02 PM

It would be nice if there were a way to pass e.g. `--function-context` to delta such that it's able to recognize this situation.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example with `git diff -U0 --function-context` and inspect how delta consumes the diff header and function context. Determine how to distinguish a changed function from a merely preceding function, then verify that delta identifies `main` rather than `other_routine` without regressing other function-context output.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.