Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Shashank S <shashu8660@gmail.com>
Cc: Patrick Steinhardt <ps@pks.im>,
	 Shashank S via GitGitGadget <gitgitgadget@gmail.com>,
	 git@vger.kernel.org,
	 Kaartic Sivaraam <kaartic.sivaraam@gmail.com>,
	 Christian Couder <christian.couder@gmail.com>,
	 Siddharth Asthana <siddharthasthana31@gmail.com>,
	 Usman Akinyemi <usmanakinyemi202@gmail.com>
Subject: Re: [PATCH] prune-packed: remove USE_THE_REPOSITORY_VARIABLE
Date: Mon, 19 Oct 2026 14:05:45 -0700	[thread overview]
Message-ID: <xmqqqzhl2yfq.fsf@gitster.g> (raw)
In-Reply-To: <CANHmUQTj8nR1GmPD2FW3+yfsgdgNh_vwRCcxRhS8GcY4VHDb8g@mail.gmail.com> (Shashank S.'s message of "Mon, 19 Oct 2026 22:08:54 +0530")

Shashank S <shashu8660@gmail.com> writes:

>> The question isn't really whether we can safely remove the UNUSED macro.
>> The question is rather whether we can assume that `repo` always points
>> to a proper repository. And for that you need to research whether these
>> commands can be invoked outside of a repository, because if so the repo
>> may be `NULL`.
>
> I have checked git.c file in that file I went through this commands .
> prune , prune-packed and repack which are .
> { "prune", cmd_prune, RUN_SETUP },
> { "prune-packed", cmd_prune_packed, RUN_SETUP },
> { "repack", cmd_repack, RUN_SETUP },
> All this commands are all registered with a special flags '
> RUN_SETUP'. This flags search for .git folder . If it finds a .git
> folder Git successfully initializes the repo struct and passes that to
> valid pointer to your builtin . If it does not find a .git folder (if
> they ran it outside the repository) Git immediately stops and shows
> the error . It never run the code .

The analysis is not entirely correct.  Assuming that your system
administrator is not insane enough and did not make the entire
filesystem as a working tree of a repository,

    $ cd / && git repack -h

does call cmd_repack() with "repo" set to NULL.

The call to parse_options() will give the short help and exit.
Becaues the references to "repo" you added all happen after the code
already called parse_options(), your update will not make the code
dereference NULL.  Some subcommands with tricky call sequence into
parse_options() _may_ have to be a bit more careful than just
checking "are we using RUN_SETUP?".  Of course RUN_SETUP_GENTLY is
an explicit sign that you have to be prepared to see NULL in "repo".

Thanks.




  reply	other threads:[~2026-10-19 21:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18 16:31 [PATCH] prune-packed: remove USE_THE_REPOSITORY_VARIABLE Shashank S via GitGitGadget
2026-10-19  7:09 ` Patrick Steinhardt
2026-10-19 16:38   ` Shashank S
2026-10-19 21:05     ` Junio C Hamano [this message]
2026-10-20 16:27       ` Shashank S
2026-10-19 16:53 ` [PATCH v2] [Outreachy Patch] " Shashank S via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqqzhl2yfq.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=ps@pks.im \
    --cc=shashu8660@gmail.com \
    --cc=siddharthasthana31@gmail.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox