All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Emin Özata via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Emin Özata" <eminozata@proton.me>
Subject: Re: [PATCH v2] stash: add 'reword' subcommand
Date: Tue, 28 Jul 2026 08:42:23 -0700	[thread overview]
Message-ID: <xmqq4ihjf7ds.fsf@gitster.g> (raw)
In-Reply-To: <xmqqbjbsmkom.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 27 Jul 2026 10:00:57 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> I wonder if the reflog API needs to be extended before we can
> implement this properly.  I imagine a set of functions like (there
> may be others)
>
>  * refs_reflog_replace(ref_stash, idx, &reflog_data);
>  * refs_reflog_edit_in_bulk(ref_stash, num_edit, reflog_edit[]);
>
> will become the foundations of such a feature.

On further thought, I think this fits pretty well into the general
architecture of the refs subsystem.  Both backends would need
refs_reflog_edit_in_bulk() in their vtable, while the single-entry
edit can just be a thin wrapper passing a single-element
reflog_edit[] array with a 'replace' operation.

If someone is interested in implementing this, there are a few
tricky details to be careful about:

 * With delete/insert, indices drift.  In "insert at stash@{5},
   replace stash@{10}", the second instruction targets what was
   originally position #10, which becomes #11 after the insertion
   at #5.  Pre-scanning the reflog_edit[] array in user order to
   annotate each element with an effective '.idx' value should
   resolve this, or something along those lines.

 * Multiple reflog_edit[] elements may target the same '.idx'.  In
   "replace stash@{4} with 'hello', replace stash@{4} with 'bye'",
   stash@{4} should end up as 'bye'.  If a backend sorts
   reflog_edit[] by '.idx' (or in reverse, as the files backend
   might do when copying from largest index to smallest),
   processing must produce the same result as unsorted execution.
   The sort needs to be stable, probably keyed on effective '.idx'
   and tiebroken by original array position.

 * A reflog_edit[] array with "delete stash@{4}" followed by
   "replace stash@{4}" asks for an impossible operation and must
   error out.  Swapping the order (edit then delete) is technically
   valid, though it feels like a user mistake.  I am undecided on
   that one.

Although "git stash reword" needs only 'replace', edit_in_bulk()
could consolidate existing operations like "reflog delete", "stash
drop", and "stash pop", and help clean up refs_reflog_expire().
Even if initial support is limited to 'replace', designing for
'delete' and 'insert' upfront saves us from a future rewrite.

As for "git stash reword" handling multi-line messages, the
flat-file reflog format pretty much expects single-line entries.
Since "git stash push -m" already squishes contiguous whitespace
(including newlines) into a single space, "stash reword" should
probably follow suit.

That is about all for now.

      reply	other threads:[~2026-07-28 15:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  8:31 [PATCH] stash: add 'rename' subcommand Emin Özata via GitGitGadget
2026-07-16 10:08 ` Patrick Steinhardt
2026-07-16 17:46   ` Junio C Hamano
2026-07-16 21:08     ` brian m. carlson
2026-07-17  1:11       ` Junio C Hamano
2026-07-26  9:00         ` erik88
2026-07-27  5:45           ` Junio C Hamano
2026-07-27  9:18             ` Emin
2026-07-27 10:54 ` [PATCH v2] stash: add 'reword' subcommand Emin Özata via GitGitGadget
2026-07-27 17:00   ` Junio C Hamano
2026-07-28 15:42     ` 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=xmqq4ihjf7ds.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=eminozata@proton.me \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.