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 — Refreshing doesn't invalidate cached version_info · Issue #1829 · gitpython-developers/GitPython

Refreshing doesn't invalidate cached version_info #1829

New issue
Copy link
New issue
Copy link
Closed
#1838
Closed
Refreshing doesn't invalidate cached version_info#1829
#1838
Copy link
Labels
acknowledgedhelp wanted

Description

@EliahKagan
EliahKagan
opened on Feb 19, 2024
Issue body actions

The version_info property of Git instances is cached per-instance, while the git.refresh function and Git.refresh class method modify global state. When version_info has been read on a Git instance, refreshing affects the behavior of that instance, but does not invalidate the cache, causing the version_info property and dynamic version method to give inconsistent results even when no changes to environment variables or the filesystem have occurred.

Here's an example produced on a CentOS 7 system where I have both the system git and a newer upstream git installed:

ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython
❯ type -a git
git is /home/ek/bin/git
git is /usr/bin/git

ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython
❯ git --version
git version 2.43.0

ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython
❯ /usr/bin/git --version
git version 1.8.3.1

ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython
❯ python
Python 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> g1 = git.Git()
>>> g2 = git.Git()
>>> g1.version_info
(2, 43, 0)
>>> git.refresh("/usr/bin/git")
>>> g1.version()
'git version 1.8.3.1'
>>> g2.version()
'git version 1.8.3.1'
>>> g1.version_info
(2, 43, 0)
>>> g2.version_info
(1, 8, 3, 1)

Because I had accessed g1.version_info before refreshing, the stale version information is handed back even after the refresh.

This is admittedly consistent with how version_info is documented:

GitPython/git/cmd.py

Line 839 in afa5754

This value is generated on demand and is cached.

But it seems to me that the documentation, as currently written, does not prevent it from being surprising. I think that either this should be made clear in the version_info property docstring, or the behavior should be changed so that refreshing invalidates all Git instances' cached version_info properties. I am not sure which is better, because I don't know why version_info is cached (and cached per instance).

This issue can probably be considered minor. In particular, this does not prevent FetchInfo.refresh (which git.refresh calls after calling Git.refresh) from updating FetchInfo._flag_map correctly, because FetchInfo.refresh accesses version_info on a newly created Git instance:

GitPython/git/remote.py

Line 346 in afa5754

if Git().version_info[:2] >= (2, 10):

Reacted by Sebastian Thiel

Activity

  1. Byron
    added
    acknowledged
    help wanted
    on Feb 19, 2024
  2. Byron commented on Feb 19, 2024

    @Byron
    Byron
    on Feb 19, 2024
    Member
    More actions

    Thanks for investigating!

    Indeed, since version_info is also used within GitPython, it's definitely a mistake to leave it stale. But even if it wasn't, users might well rely on it.

    The reason this didn't come up earlier is probably that people rather restart the program than refreshing the Git version after changes.

    Reacted by Eliah Kagan
  3. EliahKagan
    added 5 commits that reference this issue on Feb 22, 2024

    Test that refreshing invalidates cached version_info

    2908789

    Invalidate all cached version_info on refresh

    9e23782

    Invalidate all cached version_info on refresh

    f130c66

    Test that refreshing invalidates cached version_info

    626a550

    Invalidate all cached version_info on refresh

    24b065e
  4. Byron
    closed this as completedin #1838on Feb 23, 2024
  5. EliahKagan
    added a commit that references this issue on Feb 26, 2024

    Fix typos and further clarify Git.refresh docstring

    9b5531b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.