-
Notifications
You must be signed in to change notification settings - Fork 145
gitk: add external diff file rename detection #1774
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
base: master
Are you sure you want to change the base?
gitk: add external diff file rename detection #1774
Conversation
Welcome to GitGitGadgetHi @ToBoMi, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax:
NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel
Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):
To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
There are issues in commit 37f18d1: |
37f18d1
to
383d90c
Compare
There are issues in commit 383d90c: |
383d90c
to
5d4b12e
Compare
383d90c
to
5d4b12e
Compare
Error: User ToBoMi is not yet permitted to use GitGitGadget |
/allow |
Just for the record (this was already accomplished in #1773). |
User ToBoMi already allowed to use GitGitGadget. |
Error: Could not determine full name of ToBoMi |
/preview |
Preview email sent as pull.1774.git.1723806010304.gitgitgadget@gmail.com |
5d4b12e
to
829b37b
Compare
/preview |
Preview email sent as pull.1774.git.1723816893059.gitgitgadget@gmail.com |
829b37b
to
4ff4aec
Compare
/submit |
Submitted as pull.1774.git.1724318874608.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
4ff4aec
to
a4b9c33
Compare
a4b9c33
to
6209080
Compare
/submit |
Submitted as pull.1774.v2.git.1725607698680.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
6209080
to
c585fd5
Compare
/preview |
Preview email sent as pull.1774.v3.git.1739286914838.gitgitgadget@gmail.com |
c585fd5
to
c4db1e5
Compare
/preview |
Preview email sent as pull.1774.v3.git.1741092841997.gitgitgadget@gmail.com |
/submit |
Submitted as pull.1774.v3.git.1741093275742.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Johannes Sixt wrote (reply to this): Am 04.03.25 um 14:01 schrieb ToBoMi via GitGitGadget:
> From: Tobias Boesch <tobias.boesch@miele.com>
>
> * If a file was renamed between commits and an external diff is started
> through gitk on the original or the renamed file name,
> gitk was unable to open the renamed file in the external diff editor.
> It failed to fetch the renamed file from git, because it fetched it
> using its original path in contrast to using the renamed path of the
> file.
> * With this change gitk detects the rename and opens the external diff
> with the original and the renamed file instead of no file (it is able
> to fetch the renamed file path and name now from git).
> * Since git doesn't destinguish between move or rename this also works
> for moved files.
> * Showing the external diff with the original and the renamed file
> works when either of the files is selected in gitk.
>
> Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
> ---
I've picked up this patch, but haven't found time to look at it in
detail. It will take some time. Please bear with me.
The commit message would need to be rewritten to match our usual style:
- We do not use bullet points for normal text paragraphs.
- We describe the status quo in present tense,
- and then the changes in imperative mood. (Like, "code, become so!")
- The subject is not in past tense, but usually also imperative.
-- Hannes
|
User |
1a64e98
to
948b94b
Compare
/preview |
Preview email sent as pull.1774.v4.git.1743415804106.gitgitgadget@gmail.com |
/submit |
Submitted as pull.1774.v4.git.1745830037917.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, "tobias.boesch@miele.com" wrote (reply to this): Thanks for the update.
Take the time you need.
Changes to the message are following.
> -----Ursprüngliche Nachricht-----
> Von: Johannes Sixt <j6t@kdbg.org>
> Gesendet: Sonntag, 16. März 2025 17:22
> An: Boesch, Tobias <tobias.boesch@miele.com>
> Cc: git@vger.kernel.org; ToBoMi via GitGitGadget <gitgitgadget@gmail.com>
> Betreff: Re: [PATCH v3] gitk: added external diff file rename detection
>
> Am 04.03.25 um 14:01 schrieb ToBoMi via GitGitGadget:
> > From: Tobias Boesch <tobias.boesch@miele.com>
> >
> > * If a file was renamed between commits and an external diff is started
> > through gitk on the original or the renamed file name,
> > gitk was unable to open the renamed file in the external diff editor.
> > It failed to fetch the renamed file from git, because it fetched it
> > using its original path in contrast to using the renamed path of the
> > file.
> > * With this change gitk detects the rename and opens the external diff
> > with the original and the renamed file instead of no file (it is able
> > to fetch the renamed file path and name now from git).
> > * Since git doesn't destinguish between move or rename this also works
> > for moved files.
> > * Showing the external diff with the original and the renamed file
> > works when either of the files is selected in gitk.
> >
> > Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
> > ---
>
> I've picked up this patch, but haven't found time to look at it in detail. It will
> take some time. Please bear with me.
>
> The commit message would need to be rewritten to match our usual style:
>
> - We do not use bullet points for normal text paragraphs.
> - We describe the status quo in present tense,
> - and then the changes in imperative mood. (Like, "code, become so!")
> - The subject is not in past tense, but usually also imperative.
>
> -- Hannes
-------------------------------------------------------------------------------------------------
imperial-Werke oHG, Sitz Bünde, Registergericht Bad Oeynhausen - HRA 4825 |
User |
On the Git mailing list, Johannes Sixt wrote (reply to this): Am 28.04.25 um 10:47 schrieb ToBoMi via GitGitGadget:
> From: Tobias Boesch <tobias.boesch@miele.com>
>
> If a file is renamed between commits and an external diff is started
> through gitk on the original or the renamed file name,
> gitk is unable to open the renamed file in the external diff editor.
> It fails to fetch the renamed file from git, because it fetches it
> using its original path in contrast to using the renamed path of the
> file.
> Detect the rename and open the external diff with the original and
> the renamed file instead of no file (fetch the renamed file path and
> name from git) no matter if the original or the renamed file is
> selected in gitk.
> Since moved or renamed file are handled the same way do this also
> for moved files.
>
> Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
Thank you. Sorry for taking so long to respond.
In general, I like the goal of this patch.
I am not familar, yet, how renamed files are represented in Gitk.
I wonder whether it is necessary to parse diff text to find renamed file
names. When you click on a renamed file in the file list, the diff panel
jumps to the corresponding text for both the original file name and the
renamed file name. Is the information about those two names not already
available?
Would it make sense to support also copied files?
> gitk-git/gitk | 45 +++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index bc9efa18566..ddbe60398f2 100755
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -3806,6 +3806,39 @@ proc external_diff_get_one_file {diffid filename diffdir} {
> "revision $diffid"]
> }
>
> +proc check_for_renames_in_diff {filepath} {
> + global ctext
> +
> + set renamed_filenames [list {}]
> + set filename [file tail $filepath]
> + set rename_from_text_identifier_length 12
> + set rename_to_text_identifier_length 10
> + set reg_expr_rename_from {^rename from (.*$filename)}
$filename can certainly have characters that are special for a regular
expression, such as the fullstop, right? They need to be escaped or this
will find the wrong file if one at all.
If this search wants to find one side of the rename, why does it ignore
the directories?
> + set reg_expr_rename_from [subst -nobackslashes -nocommands $reg_expr_rename_from]
> + set rename_from_text_index [$ctext search -elide -regexp -- $reg_expr_rename_from 0.0]
> + if { ($rename_from_text_index != {})} {
Here and elsewhere in this patch we have a string comparison that uses
'!='. It should use 'ne'.
Please avoid the extra set of parentheses, even around && (below). Also,
in this code base, we do not have spaces around the condition inside {}.
> + set reg_expr_rename_to {^rename to (.*)}
> + set rename_to_text_index [$ctext search -elide -regexp -- $reg_expr_rename_to $rename_from_text_index]
> + if { ($rename_from_text_index != {}) && ($rename_to_text_index != {}) } {
> + lappend renamed_filenames [$ctext get "$rename_from_text_index + $rename_from_text_identifier_length chars" "$rename_from_text_index lineend"]
> + lappend renamed_filenames [$ctext get "$rename_to_text_index + $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> + }
> + return $renamed_filenames
> + }
> + set reg_expr_rename_to {^rename to (.*$filename)}
> + set reg_expr_rename_to [subst -nobackslashes -nocommands $reg_expr_rename_to]
> + set rename_to_text_index [$ctext search -elide -regexp -- $reg_expr_rename_to 0.0]
> + if { ($rename_to_text_index != {})} {
> + set reg_expr_rename_from {^rename from (.*)}
> + set rename_from_text_index [$ctext search -backwards -elide -regexp -- $reg_expr_rename_from $rename_to_text_index]
> + if { ($rename_to_text_index != {}) && ($rename_from_text_index != {}) } {
> + lappend renamed_filenames [$ctext get "$rename_from_text_index + $rename_from_text_identifier_length chars" "$rename_from_text_index lineend"]
> + lappend renamed_filenames [$ctext get "$rename_to_text_index + $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> + }
> + return $renamed_filenames
> + }
> +}
> +
Can we please have shorter variable names? They are all local variables.
I have to spend so mucht time to find the end of the variable names
before I can understand what the lines do...
> proc external_diff {} {
> global nullid nullid2
> global flist_menu_file
> @@ -3836,8 +3869,16 @@ proc external_diff {} {
> if {$diffdir eq {}} return
>
> # gather files to diff
> - set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
> - set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> + set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
> + set rename_from_filename [lindex $renamed_filenames 1]
> + set rename_to_filename [lindex $renamed_filenames 2]
> + if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
> + set difffromfile [external_diff_get_one_file $diffidfrom $rename_from_filename $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $rename_to_filename $diffdir]
> + } else {
> + set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> + }
>
> if {$difffromfile ne {} && $difftofile ne {}} {
> set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
>
> base-commit: 5b97a56fa0e7d580dc8865b73107407c9b3f0eff
-- Hannes
|
948b94b
to
ad4121b
Compare
/preview |
Preview email sent as pull.1774.v5.git.1749211339281.gitgitgadget@gmail.com |
ad4121b
to
0d28f18
Compare
/submit |
Submitted as pull.1774.v5.git.1749544174590.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, "tobias.boesch@miele.com" wrote (reply to this): > -----Ursprüngliche Nachricht-----
> Von: Johannes Sixt <j6t@kdbg.org>
> Gesendet: Dienstag, 6. Mai 2025 21:39
> An: ToBoMi via GitGitGadget <gitgitgadget@gmail.com>; git@vger.kernel.org
> Cc: Boesch, Tobias <tobias.boesch@miele.com>
> Betreff: Re: [PATCH v4] gitk: add external diff file rename detection
>
> Am 28.04.25 um 10:47 schrieb ToBoMi via GitGitGadget:
> > From: Tobias Boesch <tobias.boesch@miele.com>
> >
> > If a file is renamed between commits and an external diff is started
> > through gitk on the original or the renamed file name, gitk is unable
> > to open the renamed file in the external diff editor.
> > It fails to fetch the renamed file from git, because it fetches it
> > using its original path in contrast to using the renamed path of the
> > file.
> > Detect the rename and open the external diff with the original and the
> > renamed file instead of no file (fetch the renamed file path and name
> > from git) no matter if the original or the renamed file is selected in
> > gitk.
> > Since moved or renamed file are handled the same way do this also for
> > moved files.
> >
> > Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
>
> Thank you. Sorry for taking so long to respond.
>
> In general, I like the goal of this patch.
>
> I am not familar, yet, how renamed files are represented in Gitk.
>
> I wonder whether it is necessary to parse diff text to find renamed file names.
> When you click on a renamed file in the file list, the diff panel jumps to the
> corresponding text for both the original file name and the renamed file name.
> Is the information about those two names not already available?
I believe this could go wrong, because I think one can scroll after selecting
the file and then right click on it or even another file to execute the external diff.
Then the filenames are no longer at the top top of the text field.
I got around this by finding a git command that delivers the full paths of the original
and the renamed file. Since git commands are executed in the codebase already I
hope this is okay and maybe this is even more efficient than parsing the ctext.
>
> Would it make sense to support also copied files?
I don't know how why this is a benefit and I believe that git currently does not handle
copied files the way it does with renamed or moved files. That's why I would like to skip this.
>
> > gitk-git/gitk | 45 +++++++++++++++++++++++++++++++++++++++++++--
> > 1 file changed, 43 insertions(+), 2 deletions(-)
> >
> > diff --git a/gitk-git/gitk b/gitk-git/gitk index
> > bc9efa18566..ddbe60398f2 100755
> > --- a/gitk-git/gitk
> > +++ b/gitk-git/gitk
> > @@ -3806,6 +3806,39 @@ proc external_diff_get_one_file {diffid filename
> diffdir} {
> > "revision $diffid"]
> > }
> >
> > +proc check_for_renames_in_diff {filepath} {
> > + global ctext
> > +
> > + set renamed_filenames [list {}]
> > + set filename [file tail $filepath]
> > + set rename_from_text_identifier_length 12
> > + set rename_to_text_identifier_length 10
> > + set reg_expr_rename_from {^rename from (.*$filename)}
>
> $filename can certainly have characters that are special for a regular
> expression, such as the fullstop, right? They need to be escaped or this will
> find the wrong file if one at all.
>
> If this search wants to find one side of the rename, why does it ignore the
> directories?
True. Now that a git command is used that emits the full path of the files
This regex is no longer necessary and is removed.
>
> > + set reg_expr_rename_from [subst -nobackslashes -nocommands
> $reg_expr_rename_from]
> > + set rename_from_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_from 0.0]
> > + if { ($rename_from_text_index != {})} {
>
> Here and elsewhere in this patch we have a string comparison that uses '!='. It
> should use 'ne'.
done
>
> Please avoid the extra set of parentheses, even around && (below). Also, in
> this code base, we do not have spaces around the condition inside {}.
done
>
> > + set reg_expr_rename_to {^rename to (.*)}
> > + set rename_to_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_to $rename_from_text_index]
> > + if { ($rename_from_text_index != {}) && ($rename_to_text_index != {})
> } {
> > + lappend renamed_filenames [$ctext get "$rename_from_text_index
> + $rename_from_text_identifier_length chars" "$rename_from_text_index
> lineend"]
> > + lappend renamed_filenames [$ctext get "$rename_to_text_index +
> $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> > + }
> > + return $renamed_filenames
> > + }
> > + set reg_expr_rename_to {^rename to (.*$filename)}
> > + set reg_expr_rename_to [subst -nobackslashes -nocommands
> $reg_expr_rename_to]
> > + set rename_to_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_to 0.0]
> > + if { ($rename_to_text_index != {})} {
> > + set reg_expr_rename_from {^rename from (.*)}
> > + set rename_from_text_index [$ctext search -backwards -elide -regexp -
> - $reg_expr_rename_from $rename_to_text_index]
> > + if { ($rename_to_text_index != {}) && ($rename_from_text_index != {})
> } {
> > + lappend renamed_filenames [$ctext get "$rename_from_text_index
> + $rename_from_text_identifier_length chars" "$rename_from_text_index
> lineend"]
> > + lappend renamed_filenames [$ctext get "$rename_to_text_index +
> $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> > + }
> > + return $renamed_filenames
> > + }
> > +}
> > +
>
> Can we please have shorter variable names? They are all local variables.
> I have to spend so mucht time to find the end of the variable names before I
> can understand what the lines do...
done
>
> > proc external_diff {} {
> > global nullid nullid2
> > global flist_menu_file
> > @@ -3836,8 +3869,16 @@ proc external_diff {} {
> > if {$diffdir eq {}} return
> >
> > # gather files to diff
> > - set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file
> $diffdir]
> > - set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> > + set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
> > + set rename_from_filename [lindex $renamed_filenames 1]
> > + set rename_to_filename [lindex $renamed_filenames 2]
> > + if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
> > + set difffromfile [external_diff_get_one_file $diffidfrom
> $rename_from_filename $diffdir]
> > + set difftofile [external_diff_get_one_file $diffidto $rename_to_filename
> $diffdir]
> > + } else {
> > + set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file
> $diffdir]
> > + set difftofile [external_diff_get_one_file $diffidto $flist_menu_file
> $diffdir]
> > + }
> >
> > if {$difffromfile ne {} && $difftofile ne {}} {
> > set cmd [list [shellsplit $extdifftool] $difffromfile
> > $difftofile]
> >
> > base-commit: 5b97a56fa0e7d580dc8865b73107407c9b3f0eff
>
> -- Hannes
-------------------------------------------------------------------------------------------------
imperial-Werke oHG, Sitz Bünde, Registergericht Bad Oeynhausen - HRA 4825 |
On the Git mailing list, "tobias.boesch@miele.com" wrote (reply to this): Hi Hannes,
please ignore the V5 patch.
I totally missed to check for the file of interest when checking for renames.
I'll correct that and send an update.
Best wishes
Tobias
> -----Ursprüngliche Nachricht-----
> Von: ToBoMi via GitGitGadget <gitgitgadget@gmail.com>
> Gesendet: Dienstag, 10. Juni 2025 10:30
> An: git@vger.kernel.org
> Cc: Johannes Sixt <j6t@kdbg.org>; Boesch, Tobias
> <tobias.boesch@miele.com>; Boesch, Tobias <tobias.boesch@miele.com>;
> Boesch, Tobias <tobias.boesch@miele.com>
> Betreff: [PATCH v5] gitk: add external diff file rename detection
>
> From: Tobias Boesch <tobias.boesch@miele.com>
>
> If a file is renamed between commits and an external diff is started through
> gitk on the original or the renamed file name, gitk is unable to open the
> renamed file in the external diff editor.
> It fails to fetch the renamed file from git, because it fetches it using its original
> path in contrast to using the renamed path of the file.
> Detect the rename and open the external diff with the original and the
> renamed file instead of no file (fetch the renamed file path and name from git)
> no matter if the original or the renamed file is selected in gitk.
> Since moved or renamed file are handled the same way do this also for moved
> files.
>
> Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
> ---
> gitk: add external diff file rename detection
>
> Changes since v1:
>
> * Commit message ident
> * Commit message line length
>
> Changes since v2:
>
> * Removed option for rename detection (Adding GUI options seems to be
> not desired - which is understandable)
> * Rebased on current master of git-for-windows
> * Renamed variables for a better understanding
> * Made rename detection also work when the renamed file is selected in
> gitk
>
> Changes since v3:
>
> * Changed message to use present tense, removed bullet points and
> described changes in imperative mood
>
> Changes sine v4:
>
> * Use a git command to gather the changed file paths rather than
> parsing the text from the diff window panel for efficiency and to
> avoid regex containing the filename as a variable.
> * Change != to ne in string comparison
> * removed extra set of parentheses around &&
> * shorter variable names
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-
> 1774%2FToBoMi%2Fdetect_renamed_files_when_opening_diff-v5
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-
> 1774/ToBoMi/detect_renamed_files_when_opening_diff-v5
> Pull-Request: https://github.com/gitgitgadget/git/pull/1774
>
> Range-diff vs v4:
>
> 1: 948b94bef5c ! 1: 0d28f189dc3 gitk: add external diff file rename
> detection
> @@ gitk-git/gitk: proc external_diff_get_one_file {diffid filename diffdir} {
> "revision $diffid"]
> }
>
> -+proc check_for_renames_in_diff {filepath} {
> -+ global ctext
> ++proc check_for_renames_in_diff {diffidfrom diffidto filepath} {
> ++ global nullid nullid2
> +
> -+ set renamed_filenames [list {}]
> -+ set filename [file tail $filepath]
> -+ set rename_from_text_identifier_length 12
> -+ set rename_to_text_identifier_length 10
> -+ set reg_expr_rename_from {^rename from (.*$filename)}
> -+ set reg_expr_rename_from [subst -nobackslashes -nocommands
> $reg_expr_rename_from]
> -+ set rename_from_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_from 0.0]
> -+ if { ($rename_from_text_index != {})} {
> -+ set reg_expr_rename_to {^rename to (.*)}
> -+ set rename_to_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_to $rename_from_text_index]
> -+ if { ($rename_from_text_index != {}) && ($rename_to_text_index !=
> {}) } {
> -+ lappend renamed_filenames [$ctext get
> "$rename_from_text_index + $rename_from_text_identifier_length chars"
> "$rename_from_text_index lineend"]
> -+ lappend renamed_filenames [$ctext get "$rename_to_text_index +
> $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> -+ }
> -+ return $renamed_filenames
> ++ if {$diffidfrom eq $nullid} {
> ++ set rev [list $diffidto -R]
> ++ } elseif {$diffidfrom eq $nullid2} {
> ++ set rev [list $diffidto --cached -R]
> ++ } elseif {$diffidto eq $nullid} {
> ++ set rev [list $diffidfrom]
> ++ } elseif {$diffidto eq $nullid2} {
> ++ set rev [list $diffidfrom --cached]
> ++ } else {
> ++ set rev [list $diffidfrom..$diffidto]
> + }
> -+ set reg_expr_rename_to {^rename to (.*$filename)}
> -+ set reg_expr_rename_to [subst -nobackslashes -nocommands
> $reg_expr_rename_to]
> -+ set rename_to_text_index [$ctext search -elide -regexp --
> $reg_expr_rename_to 0.0]
> -+ if { ($rename_to_text_index != {})} {
> -+ set reg_expr_rename_from {^rename from (.*)}
> -+ set rename_from_text_index [$ctext search -backwards -elide -regexp
> -- $reg_expr_rename_from $rename_to_text_index]
> -+ if { ($rename_to_text_index != {}) && ($rename_from_text_index !=
> {}) } {
> -+ lappend renamed_filenames [$ctext get
> "$rename_from_text_index + $rename_from_text_identifier_length chars"
> "$rename_from_text_index lineend"]
> -+ lappend renamed_filenames [$ctext get "$rename_to_text_index +
> $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
> ++
> ++ set renames [list {}]
> ++ if {[catch {eval exec git diff $rev --find-renames --stat --raw --diff-
> filter=R} cmd_result]} {
> ++ error_popup "[mc "Error getting file rename info for file \"%s\" from
> commit %s to %s." \
> ++ $filepath $diffidfrom $diffidto] $cmd_result.\n\n"
> ++ }
> ++ set filename [file tail $filepath]
> ++ set regex_ren {\d+\s\d+\s\S+\s\S+\s\S+\s+(\S+)\s+(\S+)}
> ++ set regex_ren [subst -nobackslashes -nocommands $regex_ren]
> ++ if {[regexp -line -- $regex_ren $cmd_result whole_match ren_from
> ren_to]} {
> ++ if {$ren_from ne {} && $ren_to ne {}} {
> ++ lappend renames $ren_from
> ++ lappend renames $ren_to
> + }
> -+ return $renamed_filenames
> + }
> ++ return $renames
> +}
> +
> proc external_diff {} {
> @@ gitk-git/gitk: proc external_diff {} {
> # gather files to diff
> - set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file
> $diffdir]
> - set difftofile [external_diff_get_one_file $diffidto $flist_menu_file
> $diffdir]
> -+ set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
> ++ set renamed_filenames [check_for_renames_in_diff $diffidfrom
> $diffidto $flist_menu_file]
> + set rename_from_filename [lindex $renamed_filenames 1]
> + set rename_to_filename [lindex $renamed_filenames 2]
> + if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
>
>
> gitk-git/gitk | 44 ++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/gitk-git/gitk b/gitk-git/gitk index 19689765cde..f97904f5fa2
> 100755
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -3775,6 +3775,38 @@ proc external_diff_get_one_file {diffid filename
> diffdir} {
> "revision $diffid"]
> }
>
> +proc check_for_renames_in_diff {diffidfrom diffidto filepath} {
> + global nullid nullid2
> +
> + if {$diffidfrom eq $nullid} {
> + set rev [list $diffidto -R]
> + } elseif {$diffidfrom eq $nullid2} {
> + set rev [list $diffidto --cached -R]
> + } elseif {$diffidto eq $nullid} {
> + set rev [list $diffidfrom]
> + } elseif {$diffidto eq $nullid2} {
> + set rev [list $diffidfrom --cached]
> + } else {
> + set rev [list $diffidfrom..$diffidto]
> + }
> +
> + set renames [list {}]
> + if {[catch {eval exec git diff $rev --find-renames --stat --raw --diff-filter=R}
> cmd_result]} {
> + error_popup "[mc "Error getting file rename info for file \"%s\" from
> commit %s to %s." \
> + $filepath $diffidfrom $diffidto] $cmd_result.\n\n"
> + }
> + set filename [file tail $filepath]
> + set regex_ren {\d+\s\d+\s\S+\s\S+\s\S+\s+(\S+)\s+(\S+)}
> + set regex_ren [subst -nobackslashes -nocommands $regex_ren]
> + if {[regexp -line -- $regex_ren $cmd_result whole_match ren_from ren_to]}
> {
> + if {$ren_from ne {} && $ren_to ne {}} {
> + lappend renames $ren_from
> + lappend renames $ren_to
> + }
> + }
> + return $renames
> +}
> +
> proc external_diff {} {
> global nullid nullid2
> global flist_menu_file
> @@ -3805,8 +3837,16 @@ proc external_diff {} {
> if {$diffdir eq {}} return
>
> # gather files to diff
> - set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file
> $diffdir]
> - set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> + set renamed_filenames [check_for_renames_in_diff $diffidfrom $diffidto
> $flist_menu_file]
> + set rename_from_filename [lindex $renamed_filenames 1]
> + set rename_to_filename [lindex $renamed_filenames 2]
> + if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
> + set difffromfile [external_diff_get_one_file $diffidfrom
> $rename_from_filename $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $rename_to_filename
> $diffdir]
> + } else {
> + set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file
> $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $flist_menu_file
> $diffdir]
> + }
>
> if {$difffromfile ne {} && $difftofile ne {}} {
> set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
>
> base-commit: 14de3eb34435db79c6e7edc8082c302a26a8330a
> --
> gitgitgadget
-------------------------------------------------------------------------------------------------
imperial-Werke oHG, Sitz Bünde, Registergericht Bad Oeynhausen - HRA 4825 |
If a file is renamed between commits and an external diff is started through gitk on the original or the renamed file name, gitk is unable to open the renamed file in the external diff editor. It fails to fetch the renamed file from git, because it fetches it using its original path in contrast to using the renamed path of the file. Detect the rename and open the external diff with the original and the renamed file instead of no file (fetch the renamed file path and name from git) no matter if the original or the renamed file is selected in gitk. Since moved or renamed file are handled the same way do this also for moved files. Signed-off-by: Tobias Boesch <tobias.boesch@miele.com>
0d28f18
to
f1c71e5
Compare
/preview |
Preview email sent as pull.1774.v6.git.1750751741977.gitgitgadget@gmail.com |
/submit |
Submitted as pull.1774.v6.git.1750755954011.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Johannes Sixt wrote (reply to this): Am 24.06.25 um 11:05 schrieb ToBoMi via GitGitGadget:
> From: Tobias Boesch <tobias.boesch@miele.com>
>
> If a file is renamed between commits and an external diff is started
> through gitk on the original or the renamed file name,
> gitk is unable to open the renamed file in the external diff editor.
> It fails to fetch the renamed file from git, because it fetches it
> using its original path in contrast to using the renamed path of the
> file.
> Detect the rename and open the external diff with the original and
> the renamed file instead of no file (fetch the renamed file path and
> name from git) no matter if the original or the renamed file is
> selected in gitk.
> Since moved or renamed file are handled the same way do this also
> for moved files.
In Git parlance, when we talk about "renamed" files, we always mean
files that have any part of the path name changed (and not just the last
path component). Therefore, this last sentence is redundant.
> Changes sine v4:
>
> * Use a git command to gather the changed file paths rather than
> parsing the text from the diff window panel for efficiency and to
> avoid regex containing the filename as a variable.
An earlier round parsed the rename information from the patch text
panel. I argued that it should not be necessary, because the file list
already knows how to scroll the diff text panel to the correct section
and should already what was renamed. It turns out it's not that simple.
But I still think that this information can be leveraged for this new
purpose and that it is not necessary to invoke an external process. At a
minimum, it should be possible to parse off the rename information from
a smaller section of the patch text, because we know where the section
pertaining to the file of interest starts. Look for uses of the variable
'difffilestart'.
I think that the goal of this patch can be achieved easier by parsing
the patch text panel rather than parsing the output of another `git`
command. I'll still comment on the presented solution just in case it
turns out we must invoke `git` anyway.
> + set renames [list {}]
This constructs a list with one element that is the empty string. I
assume you meant one of these:
set renames [list]
set renames {}
> + if {[catch {eval exec git diff $rev --find-renames --stat --raw --diff-filter=R} cmd_result]} {
A few things I have to note here:
- Don't use porcelain commands, use plumbing commands, i.e., `git
diff-tree`, `git diff-index`, and `git diff-files` instead of `git diff`.
- Place non-option arguments after all options.
- Why use --stat?
- --numstat may be easier to parse than --raw, but see below.
> + error_popup "[mc "Error getting file rename info for file \"%s\" from commit %s to %s." \
> + $filepath $diffidfrom $diffidto] $cmd_result.\n\n"
> + }
> + set filename [file tail $filepath]
> + set esc_chars {\\ | ? ^ * . $ \[ \] + \( \) \{ \}}
> + foreach char $esc_chars {
> + set filename [string map [list $char \\$char] $filename]
> + }
> + set regex_base {\d+\s\d+\s\S+\s\S+\s\S+\s+}
> + set regex_ren_from $regex_base[subst -nobackslashes -nocommands {(\S+$filename)\s+(\S+)}]
This regular expression wants to parse the first of the two file names
that are on the output line. But it assumes that the second of the two
names cannot contain spaces: '(\S+)'. This is not a valid assumption.
Note that the output format of --raw is very restricted. In particular,
the file names are separated from the rest not by space of any kind, but
by TAB. A much stricter regular expression can be used. But still, TAB
is a character that is permitted in file names, and the regular
expression could match still match incorrectly. You can use -z to
separate the parts with a zero byte in an unambiguous way and split the
parts without a regular expression.
> + set regex_ren_to $regex_base[subst -nobackslashes -nocommands {(\S+)\s+(\S+$filename)}]
I don't understand the purpose of 'subst' here. Is this not just
set regex_ren_to $regex_base{(\S+)\s+(\S+}$filename{)}
> @@ -3805,8 +3847,16 @@ proc external_diff {} {
> if {$diffdir eq {}} return
>
> # gather files to diff
> - set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
> - set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> + set renamed_filenames [check_for_renames_in_diff $diffidfrom $diffidto $flist_menu_file]
> + set rename_from_filename [lindex $renamed_filenames 1]
> + set rename_to_filename [lindex $renamed_filenames 2]
> + if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
This expression doesn't follow the pattern that we see elsewhere, e.g.,
in the context below.
Please lose the redundant "_filename" in the variable names. In this
context, it's clear that these are names, not indices or somehthing
else. Also, when you look around, you notice that we normally don't use
the underscore in variable names.
> + set difffromfile [external_diff_get_one_file $diffidfrom $rename_from_filename $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $rename_to_filename $diffdir]
> + } else {
> + set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
> + set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
> + }
>
> if {$difffromfile ne {} && $difftofile ne {}} {
> set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
-- Hannes
|
Changes since v1:
Changes since v2:
Changes since v3:
Changes sine v4:
Changes sine v5:
cc: Johannes Sixt j6t@kdbg.org
cc: "tobias.boesch@miele.com" tobias.boesch@miele.com