Skip to content
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

Blame uncommitted deletions starting from HEAD #1009

Merged
merged 2 commits into from
Dec 13, 2020

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented Apr 29, 2020

When starting a blame in the stage view on a deleted line, it seems
appropriate to find the commit that added the line. To this end, instead
of starting the blame view from the working-tree-state of a file, use
the version at HEAD, which still has the deleted line (unless the line
was only just staged). Compute the position of the deleted line to
start the blame view there.

Closes #1008

src/stage.c Outdated Show resolved Hide resolved
@krobelus krobelus force-pushed the blame-from-head branch 3 times, most recently from afc152f to ba2676e Compare May 2, 2020 12:28
@koutcher
Copy link
Collaborator

Couldn't view->env->file be passed as an argument to git diff-index to avoid parsing all the diffs ? Also, you may return a pointer on a local variable in find_deleted_line_in_head. Maybe it could be changed to bool find_deleted_line_in_head(struct view *view, struct line *line, char *filename, unsigned long *lineno) and stage_request() changes could be reduced to:

+               if (find_deleted_line_in_head(view, line, view->env->file, &view->env->goto_lineno))
+                       string_copy(view->env->ref, "HEAD");
+               else
                        view->env->goto_lineno = diff_get_lineno(view, line, false);
                if (view->env->goto_lineno > 0)
                        view->env->goto_lineno--;

@krobelus
Copy link
Contributor Author

Couldn't view->env->file be passed as an argument to git diff-index to avoid parsing all the diffs ?

This is to deal with RM files; If file x is renamed to y in the index, then git diff-index HEAD y doesn't know about the rename. I think there is no way around computing the diff of the entire tree to detect renames.

However, dealing with renames here is not super important to me, maybe we should leave that out for now?
Alternatively, I can do the entire diff (to find the renaming) only for those cases that actually need it: where view->env->file exists in the index but not in HEAD.

@koutcher
Copy link
Collaborator

The use case is fine, I just didn't realize that providing a pathspec to diff-index was defeating the rename detection.

@krobelus
Copy link
Contributor Author

Addressed all comments.
I added an ls-tree call that allows to skip rename detection most of the time - when a file with the same name exists in HEAD, this will always use that filename Technically there can be false positives, but rename detection is only a heuristic, too.

@koutcher
Copy link
Collaborator

Looks good to me. As Steve used to say, one more thing: so far, @jonas has maintained compatibility with pre-C99 compilers. Can you keep variables declaration at the beginning of blocks ? Also can you check NEWS.adoc, Improvements are listed before Bug fixes.

When starting a blame in the stage view on a deleted line, it seems
appropriate to find the commit that added the line.  To this end, instead
of starting the blame view from the working-tree-state of a file, use
the version at HEAD, which still has the deleted line (unless the line
was only just staged).  Compute the position of the deleted line to
start the blame view there.

Closes jonas#1008
@krobelus
Copy link
Contributor Author

Should be done now, thanks!

Copy link
Collaborator

@koutcher koutcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great improvement. Thanks.

@koutcher koutcher merged commit c5b1f0c into jonas:master Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blame an unstaged deletion
2 participants