git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Cc: git@vger.kernel.org,  l.s.r@web.de,  smacdonald@kaimaging.com,
	sunshine@sunshineco.com
Subject: Re: [PATCH v3] stash: fix incorrect branch name in stash message
Date: Wed, 11 Jun 2025 09:00:37 -0700	[thread overview]
Message-ID: <xmqqqzzqi7yy.fsf@gitster.g> (raw)
In-Reply-To: <20250611014204.24994-1-jayatheerthkulkarni2005@gmail.com> (K. Jayatheerth's message of "Wed, 11 Jun 2025 07:12:03 +0530")

K Jayatheerth <jayatheerthkulkarni2005@gmail.com> writes:

> When creating a stash, Git uses the current branch name
> of the superproject to construct the stash commit message.
> However, in repositories with submodules,
> the message may mistakenly display the submodule branch name instead.
>
> This is because `refs_resolve_ref_unsafe()` returns a pointer to a static buffer.
> Subsequent calls to the same function overwrite the buffer,
> corrupting the originally fetched `branch_name` used for the stash message.
>
> Use `xstrdup()` to duplicate the branch name immediately after resolving it,
> so that later buffer overwrites do not affect the stash message.
>
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
> 1. Used the hook to remove trailing whitespaces

Huh?  The pre-commit hook trick I showed was to detect and prevent
you from creating such a commit; it does not remove them for you.
Your trailing whitespaces still remain in the patch just fine ;-)

> @@ -1401,11 +1402,15 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
>  		ret = 1;
>  		goto done;
>  	}
> -
> +	
>  	branch_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),

which causes

    .git/rebase-apply/patch:29: trailing whitespace.

    .git/rebase-apply/patch:39: trailing whitespace.

    warning: 2 lines applied after fixing whitespace errors.
    Applying: stash: fix incorrect branch name in stash message

Other than that, looing good.

Thanks, will queue.

      reply	other threads:[~2025-06-11 16:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 15:19 [BUG] git stash incorrectly showing submodule branch instead of superproject branch Stuart MacDonald
2025-05-12 16:12 ` Re " K Jayatheerth
2025-05-12 16:26   ` Stuart MacDonald
2025-05-12 16:40     ` [PATCH] stash: fix incorrect branch name in stash message K Jayatheerth
2025-05-12 16:42       ` JAYATHEERTH K
2025-05-12 17:09         ` Stuart MacDonald
2025-05-12 17:49       ` Junio C Hamano
2025-05-12 18:54         ` Eric Sunshine
2025-05-13  1:21           ` JAYATHEERTH K
2025-05-14 13:28             ` Junio C Hamano
2025-06-08  6:35               ` K Jayatheerth
2025-06-08 13:11                 ` René Scharfe
2025-06-08 14:45                   ` [PATCH v2] " K Jayatheerth
2025-06-08 16:20                     ` Junio C Hamano
2025-06-11  1:32                       ` JAYATHEERTH K
2025-06-11  1:42                       ` [PATCH v3] " K Jayatheerth
2025-06-11 16:00                         ` Junio C Hamano [this message]

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=xmqqqzzqi7yy.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jayatheerthkulkarni2005@gmail.com \
    --cc=l.s.r@web.de \
    --cc=smacdonald@kaimaging.com \
    --cc=sunshine@sunshineco.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;
as well as URLs for NNTP newsgroup(s).