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

fix files list on file rename#1537

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intogitpython-developers:mainfromteknoraver:main
Jan 14, 2023
Merged

fix files list on file rename#1537

Byron merged 1 commit intogitpython-developers:mainfromteknoraver:main
Jan 14, 2023

Conversation

teknoraver
Copy link
Contributor

@teknoraverteknoraver commentedJan 12, 2023
edited
Loading

GitPython parses the output ofgit diff --no-renames to get the files changed in a commit.
This breaks when a commit contains a file rename, because the output ofgit diff is different than expected.
This is the output of a normal commit:

$ git diff --numstat 6ab9810cfe6c^ 6ab9810cfe6c5       2       drivers/clk/zynqmp/divider.c

And this a commit containing a rename:

$ git diff --numstat db401875f438^ db401875f4381       1       tools/testing/selftests/drivers/net/mlxsw/{spectrum-2 => }/devlink_trap_tunnel_ipip6.sh

This can be triggered by this code:

forcommitinrepo.iter_commits():print(commit.hexsha)forfileincommit.stats.files:print(file)

Which will print for the normal commit:

6ab9810cfe6c8f3d8b8750c827d7870abd3751b9'drivers/clk/zynqmp/divider.c'

And when there is a rename:

db401875f438168c5804b295b93a28c7730bb57a('tools/testing/selftests/drivers/net/mlxsw/{spectrum-2 => ''}/devlink_trap_tunnel_ipip6.sh')

Fix this by pasing the --no-renames option togit diff which ignores renames and print the same output as if the file was deleted from the old path and created in the new one:

$ git diff --numstat --no-renames db401875f438^ db401875f438250     0       tools/testing/selftests/drivers/net/mlxsw/devlink_trap_tunnel_ipip6.sh0       250     tools/testing/selftests/drivers/net/mlxsw/spectrum-2/devlink_trap_tunnel_ipip6.sh

@ByronByron added this to thev3.1.31 - Bugfixes milestoneJan 12, 2023
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

It should be straightforward to add a test that motivates this changes. The test-suite uses fixture files which could be derived from an example repository.

With a test that fails without this change, the fix can be merged.

Thank you

@teknoraver
Copy link
ContributorAuthor

@Byron done, and I rewrote the commit message using GitPython hashes, so is simpler for anyone to test

Copy link
Member

@ByronByron left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks a lot, this looks like the way to go!

Instead of checking what it shouldn't be (which is a huge set of possible values), could you instead check what it should be? How does a rename look like with the current interface, I'd be very interested to see that.

For posterity, here is whatgit thinks about the commit being used in the test:

commit 185d847ec7647fd2642a82d9205fb3d07ea71715Author: Dominic <<redacted>@gmail.com>Date:   Mon Jul 12 17:02:21 2021 +0100    Update and rename test_pytest.yml to Future.ymldiff --git a/.github/workflows/test_pytest.yml b/.github/workflows/Future.ymlsimilarity index 92%rename from .github/workflows/test_pytest.ymlrename to .github/workflows/Future.ymlindex 627e720f..39146533 100644--- a/.github/workflows/test_pytest.yml+++ b/.github/workflows/Future.yml@@ -5,7 +5,9 @@ name: Future  on:   push:-    branches: [main]+    branches: [ main ]+  pull_request:+    branches: [ main ]  jobs:   build:

@teknoraver
Copy link
ContributorAuthor

This is the output ofgit show, gitpython doesgit diff --numstat $commit^ $commit which gives:

3       1       .github/workflows/{test_pytest.yml => Future.yml}

And with--no-renames added:

57      0       .github/workflows/Future.yml0       55      .github/workflows/test_pytest.yml

GitPython parses the output of `git diff --numstat` to get thefiles changed in a commit.This breaks when a commit contains a file rename, because the outputof `git diff` is different than expected.This is the output of a normal commit:    $ git diff --numstat8f41a39^8f41a39    30      5       test/test_repo.pyAnd this a commit containing a rename:    $ git diff --numstat185d847^185d847    3       1       .github/workflows/{test_pytest.yml => Future.yml}This can be triggered by this code:    for commit in repo.iter_commits():        print(commit.hexsha)            for file in commit.stats.files:                print(file)Which will print for the normal commit:8f41a39    'test/test_repo.py'And when there is a rename:185d847    '.github/workflows/{test_pytest.yml => Future.yml}'Additionally, when a path member is removed, the file list becomea list of strings, breaking even more the caller. This is in theLinux kernel tree:    $ git diff --numstat db401875f438^ db401875f438    1       1       tools/testing/selftests/drivers/net/mlxsw/{spectrum-2 => }/devlink_trap_tunnel_ipip6.shand GitPython parses it as:    db401875f438168c5804b295b93a28c7730bb57a    ('tools/testing/selftests/drivers/net/mlxsw/{spectrum-2 => '    '}/devlink_trap_tunnel_ipip6.sh')Fix this by pasing the --no-renames option to `git diff` which ignoresrenames and print the same output as if the file was deleted from theold path and created in the new one:    $ git diff --numstat --no-renames185d847^185d847    57      0       .github/workflows/Future.yml    0       55      .github/workflows/test_pytest.yml
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

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

Thanks a million, that is what I had in mind.

Thanks again for contributing!

teknoraver reacted with thumbs up emoji
@ByronByron merged commit3901d4c intogitpython-developers:mainJan 14, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron approved these changes

Assignees
No one assigned
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
@teknoraver@Byron

[8]ページ先頭

©2009-2025 Movatter.jp