"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: got patch: merge patches with diff3
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 17 Jun 2022 13:22:34 +0200

Download raw body.

Thread
On Fri, Jun 17, 2022 at 01:04:50PM +0200, Omar Polo wrote:
> +open_blob(char **path, FILE **fp, const char *blobid,
> +    struct got_repository *repo)
>  {
>  	const struct got_error *err = NULL;
> -	int file_renamed = 0;
> +	struct got_object_id *id = NULL;
> +	struct got_blob_object *blob = NULL;
> +
> +	*fp = NULL;
> +	*path = NULL;
> +
> +	err = got_repo_match_object_id(&id, NULL, blobid,
> +	    GOT_OBJ_TYPE_BLOB, NULL /* do not resolve tags */,
> +	    repo);
> +	if (err)
> +		return err;
> +
> +	err = got_object_open_as_blob(&blob, repo, id, 8192);

I think it would be better to use got_parse_sha1_digest() instead
of got_repo_match_object_id(). You can copy the result to id->sha1.
Inside lib/ code it is fine to declare 'struct got_object_id id'
on the stack and use it like this:

	if (!got_parse_sha1_digest(id.sha1, blobid))
		return got_error(GOT_ERR_BAD_OBJ_ID_STR);

	err = got_object_open_as_blob(&blob, repo, &id, 8192);
	if (err)
		goto done;


> @@ -147,13 +150,19 @@ find_patch(int *done, FILE *fp)
>  		} else if (!strncmp(line, "+++ ", 4)) {
>  			free(new);
>  			err = filename(line+4, &new);
> +		} else if (!git && !strncmp(line, "blob - ", 7)) {
> +			free(blob);
> +			err = filename(line + 7, &blob);

You could validate the blob ID here by checking if
got_parse_sha1_digest() can successfully parse it.

> +	# XXX: prefixing every line with a tab otherwise got thinks
> +	# the file has conflicts in it.

:)

> +	cat <<-EOF > $testroot/wt/numbers.expected
> +	1
> +	2
> +	3
> +	4
> +	5
> +	<<<<<<< --- numbers
> +	six
> +	||||||| f00c965d8307308469e537302baa73048488f162

The label should indicate what kind of object this is:

	||||||| blob f00c965d8307308469e537302baa73048488f162

Perhaps people would have an easier time looking up commit IDs
and then find the file by path? Pretty much all you can do with
just one blob ID is to use 'got cat' on it. So instead you could
parse the commit ID from the patch as well and show it here:

	||||||| commit abcde...

> +	6
> +	=======
> +	3+3
> +	>>>>>>> +++ numbers
> +	7
> +	8
> +	9
> +	10
> +EOF