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

Refreshing doesn't invalidate cached version_info #1829

Closed
@EliahKagan

Description

@EliahKagan

Theversion_info property ofGit instances is cached per-instance, while thegit.refresh function andGit.refresh class method modify global state. Whenversion_info has been read on aGit instance, refreshing affects the behavior of that instance, but does not invalidate the cache, causing theversion_info property and dynamicversion 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 systemgit and a newer upstreamgit installed:

ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython❯ type -a gitgit is /home/ek/bin/gitgit is /usr/bin/gitek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython❯ git --versiongit version 2.43.0ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython❯ /usr/bin/git --versiongit version 1.8.3.1ek in 🌐 Eald in GitPython on  main via 🐍 v3.12.1 via 🅒 GitPython❯ pythonPython 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0] on linuxType "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 accessedg1.version_info before refreshing, the stale version information is handed back even after the refresh.

This is admittedly consistent with howversion_info is documented:

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 theversion_info property docstring, or the behavior should be changed so that refreshing invalidates allGit instances' cachedversion_info properties. I am not sure which is better, because I don't know whyversion_info is cached (and cached per instance).

This issue can probably be considered minor. In particular, this does not preventFetchInfo.refresh (whichgit.refresh calls after callingGit.refresh) from updatingFetchInfo._flag_map correctly, becauseFetchInfo.refresh accessesversion_info on a newly createdGit instance:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp