GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — How to get git patch-id? · gitpython-developers/GitPython · Discussion #1974

How to get git patch-id? #1974

Answered by jayjoshi64
jayjoshi64 asked this question in Q&A
How to get git patch-id? #1974
@jayjoshi64 jayjoshi64
Oct 17, 2024 · 2 comments
Answered by jayjoshi64 Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

jayjoshi64
Oct 17, 2024

This is command-line syntax to get patch-id for a commit

git show HEAD | git patch-id 

Reference: https://git-scm.com/docs/git-patch-id

Q: How can I get the same output using GitPython?

You must be logged in to vote
All reactions
Answered by jayjoshi64 Oct 18, 2024

I got it to work with this:

def get_patch_id(commit: str) -> str:
    """
    Get patch-id of a commit.
    a patch id is a unique ID for a patch (git show)
    ref: https://git-scm.com/docs/git-patch-id
    """
    with Repo(repo_path) as repo:
        with tempfile.TemporaryFile() as temp_file:
            # output_stream = BytesIO()
            repo.git.show(commit, output_stream=temp_file)
            temp_file.seek(0)
            return repo.git.patch_id(istream=temp_file).split()[0]
View full answer

Replies: 2 comments

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

Byron
Oct 18, 2024
Maintainer

You would have to use repo.patch_id() directly and add options to receive the running process, through which one then can pass the commit to generate a patch-id for. It's cumbersome, and probably easier just to Popen to run git directly.

You must be logged in to vote
All reactions
0 replies
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

jayjoshi64
Oct 18, 2024
Author

I got it to work with this:

def get_patch_id(commit: str) -> str:
    """
    Get patch-id of a commit.
    a patch id is a unique ID for a patch (git show)
    ref: https://git-scm.com/docs/git-patch-id
    """
    with Repo(repo_path) as repo:
        with tempfile.TemporaryFile() as temp_file:
            # output_stream = BytesIO()
            repo.git.show(commit, output_stream=temp_file)
            temp_file.seek(0)
            return repo.git.patch_id(istream=temp_file).split()[0]
You must be logged in to vote
All reactions
0 replies
Answer selected by jayjoshi64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
@jayjoshi64 @Byron
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.