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

Re: [PATCH] sequencer: ensure labels that are object IDs are rewritten

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 30, 2018, 09:54 UTC
Message-ID
<nycvar.QRO.7.76.6.1805301144470.82@tvgsbejvaqbjf.bet>
In-Reply-To
<20180529163236.646275-1-sandals@crustytoothpaste.net>
Hi Brian,
On Tue, 29 May 2018, brian m. carlson wrote:
Show 10 quoted lines
> When writing the todo script for --rebase-merges, we try to find a label
> for certain commits.  If the label ends up being a valid object ID, such
> as when we merge a detached commit, we want to rewrite it so it is no
> longer a valid object ID.
> 
> However, the code path that does this checks for its length to be
> equivalent to GIT_SHA1_RAWSZ, which isn't correct, since what we are
> reading is a hex object ID.  Instead, check for the length being
> equivalent to that of a hex object ID.  Use the_hash_algo so this code
> works regardless of the hash size.
D'oh. Thank you so much for this fix.
> I noticed this while cleaning up a few instances of GIT_SHA1_* constants
> and thought I'd send a patch.
You thought well!
Show 10 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index 1ce63261a3..75ed86a94e 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -3636,7 +3636,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
>  				p[i] = save;
>  			}
>  		}
> -	} else if (((len = strlen(label)) == GIT_SHA1_RAWSZ &&
> +	} else if (((len = strlen(label)) == the_hash_algo->hexsz &&
Obviously good!
Show 20 quoted lines
>  		    !get_oid_hex(label, &dummy)) ||
>  		   (len == 1 && *label == '#') ||
>  		   hashmap_get_from_hash(&state->labels,
> diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
> index 3d4dfdf7be..472ad9463c 100755
> --- a/t/t3430-rebase-merges.sh
> +++ b/t/t3430-rebase-merges.sh
> @@ -70,6 +70,7 @@ test_expect_success 'create completely different structure' '
>  	merge -C H second
>  	merge onebranch # Merge the topic branch '\''onebranch'\''
>  	EOF
> +	cp script-from-scratch script-from-scratch-orig &&
>  	test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
>  	test_tick &&
>  	git rebase -i -r A &&
> @@ -241,4 +242,20 @@ test_expect_success 'refuse to merge ancestors of HEAD' '
>  	test_cmp_rev HEAD $before
>  '
>  
> +test_expect_success 'labels that are object IDs are rewritten' '

Thanks for writing a test, I had been meaning to, but it slipped from my mind.

> +	git checkout -b third B &&
> +	test_tick &&
> +	test_commit I &&
The test_tick before test_commit is unnecessary.
Show 5 quoted lines
> +	third=$(git rev-parse HEAD) &&
> +	git checkout -b labels master &&
> +	git merge --no-commit third &&
> +	test_tick &&
> +	git commit -m "Merge commit '\''$third'\'' into labels" &&
Here, the test_tick is required because we commit via `git commit`.

BTW another thing that I had been meaning to address but totally forgot is this '\'' ugliness. I had been meaning to define SQ="'" before all test cases and then use $SQ everywhere. Not your problem, though.

> +	cp script-from-scratch-orig script-from-scratch &&
There is nothing in that script that you need. Why not simply
	echo noop >script-from-scratch
or if you care about the branch,
	echo reset $third >script-from-scratch
> +	test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
> +	test_tick &&
> +	git rebase -i -r A &&
> +	! grep "^label $third$" .git/ORIGINAL-TODO

I would like to verify in addition that /^label $third-/ is present in ORIGINAL-TODO, what do you think?

Thank you, Dscho

Previous: brian m. carlsonNext: brian m. carlson
Message 2 of 6 in “sequencer: ensure labels that are object IDs are rewritten”
  1. sequencer: ensure labels that are object IDs are rewrittenbrian m. carlson, May 29, 2018
  2. Johannes SchindelinMay 30, 2018
  3. brian m. carlsonMay 30, 2018
  4. Johannes SchindelinMay 31, 2018
  5. sequencer: ensure labels that are object IDs are rewrittenbrian m. carlson, Jun 1, 2018
  6. Johannes SchindelinJun 1, 2018

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.