Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Patrick Steinhardt <ps@pks.im>,
	Junio C Hamano <gitster@pobox.com>,
	Phillip Wood <phillip.wood123@gmail.com>
Subject: [PATCH v3 0/2] status: improve rebase todo list parsing
Date: Mon, 22 Jun 2026 09:36:02 +0100	[thread overview]
Message-ID: <cover.1782117361.git.phillip.wood@dunelm.org.uk> (raw)
In-Reply-To: <cover.1776697483.git.phillip.wood@dunelm.org.uk>

When there is rebase in progress "git status" displays the last couple
of completed and the next couple of pending commands from the todo
list. When it does this is tries to abbreviate the object ids of
the commits to be picked. Unfortunately it does not abbreviate the
object ids when the line starts with "fixup -C" or "merge -C". It
also mistakenly replaces the refname in "reset main" and "update-ref
refs/heads/main" with the object id that the ref points to.

This series fixes that. The first patch factors out the sequencer
code that parses the command names in the todo list. The second patch
uses that function in "git status" to parse the command names so that
it knows whether the line may contain "-C" and whether there is an
object id that should be abbreviated.

Thanks to Junio for his comments on V2.

Changes since V2:

Patch 2 - Check if the object name is a label before trying to
          abbreviate it.

Note that a number of the CI jobs fail[1] due to the rather old base,
but a test merge of this branch with "master" passes[2]

[1] https://github.com/phillipwood/git/actions/runs/27906115900
[2] https://github.com/phillipwood/git/actions/runs/27908204055

Changes since V1:

Patch 1 - Expanded commit message and added a code comment.

Patch 2 - Fixed some typos, added a code comment and clarified that -Wswitch
          is included by -Wall.

Base-Commit: 8c9303b1ffae5b745d1b0a1f98330cf7944d8db0
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fimprove-status-todo-list-parsing%2Fv3
View-Changes-At: https://github.com/phillipwood/git/compare/8c9303b1f...b3514e9b1
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/improve-status-todo-list-parsing/v3


Phillip Wood (2):
  sequencer: factor out parsing of todo commands
  status: improve rebase todo list parsing

 sequencer.c            |  45 ++++++++----
 sequencer.h            |   8 +++
 t/t7512-status-help.sh |  74 +++++++++++++-------
 wt-status.c            | 154 +++++++++++++++++++++++++++++++++--------
 4 files changed, 213 insertions(+), 68 deletions(-)

Range-diff against v2:
1:  d27dddff931 = 1:  d27dddff931 sequencer: factor out parsing of todo commands
2:  b80bc1e0a29 ! 2:  b3514e9b1c9 status: improve rebase todo list parsing
    @@ Commit message
         the commits to be picked. Unfortunately it does not abbreviate the
         object ids when the line starts with "fixup -C" or "merge -C". It
         also mistakenly replaces the refname in "reset main" and "update-ref
    -    refs/heads/main" with the object id that the ref points to. Use
    -    the function added in the last commit to parse the command name and
    -    only try to abbreviate the argument for commands that take an object
    -    id. When trying to abbreviate an object id, only replace the object
    -    name if it starts with the abbreviated object id so that labels or
    -    branch names that contain only hex digits are left unchanged.
    +    refs/heads/main" with the object id that the ref points to.
    +
    +    Fix this by using the function added in the last commit to parse the
    +    command name and only try to abbreviate the argument for commands that
    +    take an object id. If a command accepts a label then try to resolve the
    +    object name as a label first and only if that fails try to resolve it
    +    as an object_id. When trying to abbreviate an object id, only replace
    +    the object name if it starts with the abbreviated object id so that
    +    tag or branch names that contain only hex digits are left unchanged.
     
         Comments are now processed after stripping any leading
         whitespace from the line. This matches what the sequencer does in
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     +}
     +
     +/*
    -+ * If the whitespace-delimited token starting at or just after *pp *
    -+ * is a hex object id that is longer than its default abbreviation, *
    ++ * If the whitespace-delimited token starting at or just after *pp
    ++ * is a hex object id that is longer than its default abbreviation,
     + * abbreviate it in-place, shrinking `line` accordingly. On return
     + * *pp points one past the (possibly abbreviated) token. Leaves both
     + * `line` and *pp-advanced-past-the-token unchanged in all other cases
    -+ * (non-hex token, unresolvable, or a refname that happens to consist
    -+ * only of hex digits).
    ++ * (non-hex token, label name, unresolvable, or a refname that happens
    ++ * to consist only of hex digits).
     + */
    -+static void abbrev_oid_in_line(struct repository *r,
    -+			       struct strbuf *line, char **pp)
    ++static void abbrev_oid_in_line(struct repository *r, struct strbuf *scratch,
    ++			       struct strbuf *line, bool maybe_label, char **pp)
     +{
     +	char *p = *pp;
     +	char *end_of_object_name, saved;
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     +	for (const char *q = p; q < end_of_object_name; q++) {
     +		if (!isxdigit(*q))
     +			goto out;
    ++	}
    ++	if (maybe_label) {
    ++		strbuf_reset(scratch);
    ++		strbuf_addf(scratch, "refs/rewritten/%.*s",
    ++			    (int)(end_of_object_name - p), p);
    ++		if (refs_ref_exists(get_main_ref_store(r), scratch->buf))
    ++			goto out; /* object name was a label */
     +	}
     +	saved = *end_of_object_name;
     +	*end_of_object_name = '\0';
     +	have_oid = !repo_get_oid(r, p, &oid);
     +	*end_of_object_name = saved;
     +	if (!have_oid)
    -+		goto out; /* object name was a label */
    ++		goto out; /* invalid object name */
     +	abbrev = repo_find_unique_abbrev(r, &oid, DEFAULT_ABBREV);
     +	if (!starts_with(p, abbrev))
     +		goto out; /* object name was a refname containing only xdigits */
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     +	*pp = end_of_object_name;
     +}
     +
    -+static void skip_dash_c(char **pp)
    ++/* Skip "[ \t]*(-[cC])?", returns true if "-c/-C" was skipped. */
    ++static bool skip_dash_c(char **pp)
     +{
    ++	bool ret;
     +	char *p = *pp;
     +
     +	p += strspn(p, " \t");
    -+	/* The (void) cast is required to silence -Wunused-value */
    -+	(void)(skip_prefix(p, "-C", &p) || skip_prefix(p, "-c", &p));
    ++	ret = skip_prefix(p, "-C", &p) || skip_prefix(p, "-c", &p);
     +	*pp = p;
    ++
    ++	return ret;
      }
      
      /*
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     -		strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV);
     -		for (size_t i = 2; i < split.nr; i++)
     -			strbuf_addf(line, " %s", split.items[i].string);
    +-	}
    +-	string_list_clear(&split, 0);
     +	enum todo_command cmd;
    ++	struct strbuf scratch = STRBUF_INIT;
     +	char *p = line->buf;
     +
     +	if (!sequencer_parse_todo_command((const char**)&p, &cmd))
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     +	case TODO_COMMENT:
     +		return false;
     +
    -+	case TODO_MERGE:
    -+		skip_dash_c(&p);
    ++	case TODO_MERGE: {
    ++		/*
    ++		 * The argument to -C cannot be a label, but the parents
    ++		 * can be labels.
    ++		 */
    ++		bool maybe_label = !skip_dash_c(&p);
    ++
     +		while (true) {
     +			p += strspn(p, " \t");
     +			if (!p[0] || (p[0] == '#' && (!p[1] || isspace(p[1]))))
     +				break;
    -+			abbrev_oid_in_line(r, line, &p);
    ++			abbrev_oid_in_line(r, &scratch, line, maybe_label, &p);
    ++			maybe_label = true;
     +		}
     +		break;
    ++	}
     +
     +	case TODO_FIXUP:
     +		skip_dash_c(&p);
     +		/* fallthrough */
     +	case TODO_DROP:
     +	case TODO_EDIT:
     +	case TODO_PICK:
    -+	case TODO_RESET:
     +	case TODO_REVERT:
     +	case TODO_REWORD:
     +	case TODO_SQUASH:
    -+		abbrev_oid_in_line(r, line, &p);
    ++		abbrev_oid_in_line(r, &scratch, line, false, &p);
     +		break;
     +
    ++	case TODO_RESET:
    ++		abbrev_oid_in_line(r, &scratch, line, true, &p);
    ++		break;
     +	/*
     +	 * Avoid "default" and instead list all the other commands so
     +	 * that -Wswitch (which is included in -Wall) warns if a new
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
     +	case TODO_NOOP:
     +	case TODO_UPDATE_REF:
     +		break;
    - 	}
    --	string_list_clear(&split, 0);
    ++	}
     +
    ++	strbuf_release(&scratch);
     +	return true;
      }
      
-- 
2.54.0.200.gfd8d68259e3


  parent reply	other threads:[~2026-06-22  8:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 15:04 [PATCH 0/2] status: improve rebase todo list parsing Phillip Wood
2026-04-20 15:04 ` [PATCH 1/2] sequencer: factor out parsing of todo commands Phillip Wood
2026-04-22  0:32   ` Elijah Newren
2026-04-20 15:04 ` [PATCH 2/2] status: improve rebase todo list parsing Phillip Wood
2026-04-20 16:38   ` Tian Yuchen
2026-04-21 16:03     ` Phillip Wood
2026-04-22  0:32   ` Elijah Newren
2026-04-22 13:28     ` Patrick Steinhardt
2026-04-22 14:14       ` Phillip Wood
2026-04-22 14:15     ` Phillip Wood
2026-05-01 15:16 ` [PATCH v2 0/2] " Phillip Wood
2026-05-01 15:16   ` [PATCH v2 1/2] sequencer: factor out parsing of todo commands Phillip Wood
2026-05-01 15:16   ` [PATCH v2 2/2] status: improve rebase todo list parsing Phillip Wood
2026-05-31  0:46     ` Junio C Hamano
2026-06-01 15:20       ` Phillip Wood
2026-06-11 16:08         ` Junio C Hamano
2026-06-22  8:36           ` Phillip Wood
2026-05-01 18:19   ` [PATCH v2 0/2] " Phillip Wood
2026-06-22  8:36 ` Phillip Wood [this message]
2026-06-22  8:36   ` [PATCH v3 1/2] sequencer: factor out parsing of todo commands Phillip Wood
2026-06-22 17:00     ` Junio C Hamano
2026-06-22  8:36   ` [PATCH v3 2/2] status: improve rebase todo list parsing Phillip Wood
2026-06-22 17:26     ` Junio C Hamano

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=cover.1782117361.git.phillip.wood@dunelm.org.uk \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /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