git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] reflog: drop usage of global variables

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 10, 2025, 11:41 UTC
Message-ID
<CAOLa=ZRqMnus=MZV1ASce4pxnMkVRGqhZZ+vZNcGhWdUQE-JRg@mail.gmail.com>
In-Reply-To
<xmqqo6ycczdr.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 26 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> The 'builtin/reflog.c' file uses the 'the_repository' global variable
>> directly and also via 'git_config()'. Since this is a builtin command
>> which has access to the 'struct repository', drop usage of the global
>> variable and use the available repository struct.
>>
>> With this, remove the 'USE_THE_REPOSITORY_VARIABLE' macro from the file.
>
> I suspect that this is not quite right.
>
>     $ cd w/git.git/; make
>     $ ./git-reflog list -h
>     usage: git reflog list
>     $ cd .. # not a repository
>     $ git.git/git-reflog list -h
>     fatal: not a git repository (or any of the parent directories): .git
>     $ git.git/git-reflog -h
>     usage: git reflog [show] ...
>
> but I also suspect that it is mostly due to the original program
> structure that uses OPT_SUBCOMMAND() that the subcommands fail to
> respond to "-h" unlike the top-level command, so this may not be a
> regression.  I do think however that this change is making it harder
> to fix.
>
Hmm. But this is the existing behavior, no?
  # Inside a git directory
  $ eza .git
  b4.template  branches  COMMIT_EDITMSG  config  description
FETCH_HEAD  filter-repo  HEAD  hooks  index  info  objects  refs
reftable  rr-cache
  $ git reflog -h
  usage: git reflog [show] [<log-options>] [<ref>]
     or: git reflog list
     or: git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                           [--rewrite] [--updateref] [--stale-fix]
                           [--dry-run | -n] [--verbose] [--all
[--single-worktree] | <refs>...]
     or: git reflog delete [--rewrite] [--updateref]
                           [--dry-run | -n] [--verbose] <ref>@{<specifier>}...
     or: git reflog exists <ref>
  $ git reflog list -h
  usage: git reflog list
  $ ~/code/git/build/bin-wrappers/git reflog -h
  usage: git reflog [show] [<log-options>] [<ref>]
     or: git reflog list
     or: git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                           [--rewrite] [--updateref] [--stale-fix]
                           [--dry-run | -n] [--verbose] [--all
[--single-worktree] | <refs>...]
     or: git reflog delete [--rewrite] [--updateref]
                           [--dry-run | -n] [--verbose] <ref>@{<specifier>}...
     or: git reflog exists <ref>
     or: git reflog drop [--all | <refs>...]
  $ ~/code/git/build/bin-wrappers/git reflog list -h
  usage: git reflog list
  # Outside a git repository
  $ eza .git
  ".git": No such file or directory (os error 2)
  $ git reflog -h
  usage: git reflog [show] [<log-options>] [<ref>]
     or: git reflog list
     or: git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                           [--rewrite] [--updateref] [--stale-fix]
                           [--dry-run | -n] [--verbose] [--all
[--single-worktree] | <refs>...]
     or: git reflog delete [--rewrite] [--updateref]
                           [--dry-run | -n] [--verbose] <ref>@{<specifier>}...
     or: git reflog exists <ref>
  $ git reflog list -h
  fatal: not a git repository (or any of the parent directories): .git
  $ ~/code/git/build/bin-wrappers/git reflog -h
  usage: git reflog [show] [<log-options>] [<ref>]
     or: git reflog list
     or: git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                           [--rewrite] [--updateref] [--stale-fix]
                           [--dry-run | -n] [--verbose] [--all
[--single-worktree] | <refs>...]
     or: git reflog delete [--rewrite] [--updateref]
                           [--dry-run | -n] [--verbose] <ref>@{<specifier>}...
     or: git reflog exists <ref>
     or: git reflog drop [--all | <refs>...]
  $ ~/code/git/build/bin-wrappers/git reflog list -h
  fatal: not a git repository (or any of the parent directories): .git
Seems like the behavior is the same with as with (git 2.48.1).
Show 12 quoted lines
> In any case, when you are adding a new feature, I would strongly
> prefer you did *not* take it hostage to unrelated internal clean-up
> with a dubious value.  For the library-ish parts of the system
> (e.g. reflog.c at the top-level), not depending on the_repository is
> absolutely the good thing to do, but the top level cmd_foo() are not
> meant to be called as helper functions repeatedly with arbirary
> repository instance, and a churn like this one, only to mollify the
> USE_THE_REPOSITORY_VARIABLE macro, does not deserve to take a more
> interesting (in the sense that it improves the life of end users)
> change hostage by pretending to be its prerequisite clean-up.
>
> Thanks.
But point taken, I'll drop this patch in the next version! Thanks
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 30 in “EDITME: cover title for 493-add-command-to-purge-reflog-entries”
  1. 0/2 EDITME: cover title for 493-add-command-to-purge-reflog-entriesKarthik Nayak, Mar 7, 2025
  2. 1/2 reflog: drop usage of global variablesKarthik Nayak, Mar 7, 2025
  3. Junio C HamanoMar 7, 2025
  4. Karthik NayakMar 10, 2025
  5. Junio C HamanoMar 10, 2025
  6. Karthik NayakMar 13, 2025
  7. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 7, 2025
  8. Patrick SteinhardtMar 7, 2025
  9. Karthik NayakMar 7, 2025
  10. Patrick SteinhardtMar 7, 2025
  11. Karthik NayakMar 7, 2025
  12. Karthik NayakMar 7, 2025
  13. Junio C HamanoMar 7, 2025
  14. Karthik NayakMar 10, 2025
  15. Kristoffer HaugsbakkMar 10, 2025
  16. Karthik NayakMar 10, 2025
  17. Junio C HamanoMar 10, 2025
  18. reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 10, 2025
  19. Patrick SteinhardtMar 12, 2025
  20. Karthik NayakMar 13, 2025
  21. Patrick SteinhardtMar 13, 2025
  22. 0/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  23. 1/2 reflog: improve error for when reflog is not foundKarthik Nayak, Mar 14, 2025
  24. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  25. Christian CouderMar 18, 2025
  26. Junio C HamanoMar 18, 2025
  27. Christian CouderMar 19, 2025
  28. Karthik NayakMar 19, 2025
  29. Toon ClaesMar 18, 2025
  30. Karthik NayakMar 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.