Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to disable check for renames?#1195

AnsweredbyByron
dudicoco asked this question inQ&A
Discussion options

Hi,

I've tried to use the following to disable git diff renamed files search:

repo.index.diff('origin/HEAD', no_renames=True)

This did not work, and after some digging, i've found that GitPython hardcodes the-M flag:
https://github.com/gitpython-developers/GitPython/blob/master/git/diff.py#L106

Why is this flag hardcoded and is there a way around it?

Thanks

You must be logged in to vote

With this API there is no way around it unless the git command is used directly such as inrepo.git.diff(…).
If there is motivation, a PR could be added to disable rename tracking which I presume is in the interest of increased performance.

Replies: 3 comments 13 replies

Comment options

With this API there is no way around it unless the git command is used directly such as inrepo.git.diff(…).
If there is motivation, a PR could be added to disable rename tracking which I presume is in the interest of increased performance.

You must be logged in to vote
1 reply
@dudicoco
Comment options

@Byron there are two issues here:

  1. Sometimes it is necessary to to addno-renames to prevent false positives in git's rename detection - for example, deleting a file and creating another file with similar content (this will be detected as rename, rather than delete + add).
  2. It seems that there is a bug GitPython's diff filter when used with renames. To recreate, delete a file and create another file with similar contents, compare the result ofgit diff --name-only --diff-filter=M -M with GitPython'siter_change_type('M'). GitPython will show the deleted/renamed file as modified.
Answer selected byByron
Comment options

Hello! I've hit this issue as well. I'd like to try the repo.git.diff() approach as a workaround. Using the results from repo.git.diff(), is there an easy way to build a DiffIndex()?
Thanks!

You must be logged in to vote
11 replies
@mellowed100
Comment options

        # remove -M arg if user supplies 'no_renames' or 'M' kwargs         if not any(x in kwargs for x in ('no_renames','M')):            args.append("-M")  # check for renames, in both formats                # manually convert '-M'        if 'M' in kwargs:            args.append(f"-M{str(kwargs['M'])}")            del(kwargs['M'])

commitA.diff(commitB, M='75%')
produces:
git diff-tree 58259d006066372eb337cce81caf97365eb30f1e 22315b3c433865970e0a2fcd1b599786c2e01703 -r --abbrev=40 --full-index -M75% --raw -z --no-color

commitA.diff(commitB, no_renames=True)
produces:
git diff-tree --no-renames 58259d006066372eb337cce81caf97365eb30f1e 22315b3c433865970e0a2fcd1b599786c2e01703 -r --abbrev=40 --full-index --raw -z --no-color

default behavior stays the same
commitA.diff(commitB)
produces:
git diff-tree 58259d006066372eb337cce81caf97365eb30f1e 22315b3c433865970e0a2fcd1b599786c2e01703 -r --abbrev=40 --full-index -M --raw -z --no-color

@Byron
Comment options

Maybe that could be generalized (and tested) to become a contribution - it looks like a genuine improvement without adding too much complexity.

@mellowed100
Comment options

Hey Bryon,

So I took another look into the command line formatting issue. It turns out there is an option to format those single char kawrgs.
split_single_char_options controls the inclusion of a space character when constructing the git command line.

original:
commitA.diff(commitB, M='75%')

produces the-M 75%: (space included)
git diff-tree -M 75% 69a8e0b10c8695d7f073c3b32c647aa8e892b1e2 140ef4c33fa5a899cd8d1dfb15a03c342a49a95c -r --abbrev=40 --full-index --raw -z --no-color

Including option to format single char kwargs:
commitA.diff(commitB,split_single_char_options=False ,M='75%')
produces the-M75% (space removed)
git diff-tree -M75% 69a8e0b10c8695d7f073c3b32c647aa8e892b1e2 140ef4c33fa5a899cd8d1dfb15a03c342a49a95c -r --abbrev=40 --full-index --raw -z --no-color

So it looks like all we need is to remove the default-M when the user wants to override it with either--find-renames= or-M or--no-renames

    # remove default '-M' arg (check for renames) if user is overriding it    if not any(x in kwargs for x in ('find_renames', 'no_renames','M')):        args.append("-M")

The remaining kwargs can be processed through the normal routines.

@mellowed100
Comment options

It may also be worth adding thesplit_single_char_options option in the docs.

@Byron
Comment options

I see, thanks so much for investigating this. A PR to improve the situation would definitely be welcome. Thank you.

Comment options

would also like for this to be added!

You must be logged in to vote
1 reply
@mellowed100
Comment options

Hey nwcm! The PR was finished last week. You can probably download the source now, or wait for the official 3.1.31 release.
#1551
Usage examples can be found in test/test_diff.py test_rename_override().

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
4 participants
@dudicoco@Byron@mellowed100@nwcm
Converted from issue

This discussion was converted from issue #1194 on March 12, 2021 01:57.


[8]ページ先頭

©2009-2025 Movatter.jp