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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: tog diff 'p' keymap: show id prefix in diff filename
To:
Mark Jamsek <mark@jamsek.com>
Cc:
gameoftrees@openbsd.org
Date:
Sat, 17 Aug 2024 14:14:12 +0200

Download raw body.

Thread
On Sat, Aug 17, 2024 at 09:02:55PM +1000, Mark Jamsek wrote:
> As suggested by stsp on IRC, this helps identify diffs when several have
> been written to /tmp with the 'p' keymap. For example, the attached diff
> was written to /tmp/tog-d6cf760a-22d21277-jtiFFdqfXy.diff
> 
> I couldn't decide on what label to use when there is no lhs/from version
> in the diff (e.g., root/initial commits). In the attached diff, we use
> the term "empty" but I was considering "devnull" as we use "/dev/null"
> in the diff headers. However, I plan to implement the ":empty" keyword
> to use as a commit argument in our -c options (cf. :base and :head) to
> mean no lhs/from version.  Although I'm not attached to the label if we
> can come up with something better.

Ok with me, thanks!

> 
> commit 22d21277d1b6185dad4b381ac7a0c59e918423c7
> from: Mark Jamsek <mark@jamsek.dev>
> date: Sat Aug 17 10:32:49 2024 UTC
> 
> tog diff 'p' keymap: show id prefix in diff filename
> 
> This helps identify diffs when several have been written.
> Suggested by stsp on IRC.
> 
> M  tog/tog.c  |  24+  5-
> 
> 1 file changed, 24 insertions(+), 5 deletions(-)
> 
> commit - d6cf760a654df954418c577a08765155985c095d
> commit + 22d21277d1b6185dad4b381ac7a0c59e918423c7
> blob - 0f0c5142c308899d47b16880bf3b26d868b72c92
> blob + d14762a6fbaec888585b06e5e467bf486f5d07d5
> --- tog/tog.c
> +++ tog/tog.c
> @@ -5817,11 +5817,12 @@ diff_write_patch(struct tog_view *view)
>  {
>  	const struct got_error		*err;
>  	struct tog_diff_view_state	*s = &view->state.diff;
> -	FILE				*f;
> -	char				 buf[BUFSIZ];
> -	char				*path;
> +	FILE				*f = NULL;
> +	char				 buf[BUFSIZ], pathbase[PATH_MAX];
> +	char				*idstr2, *idstr1 = NULL, *path = NULL;
>  	size_t				 r;
>  	off_t				 pos;
> +	int				 rc;
>  
>  	if (s->action != NULL) {
>  		free(s->action);
> @@ -5834,10 +5835,26 @@ diff_write_patch(struct tog_view *view)
>  	if (fseeko(s->f, 0L, SEEK_SET) == -1)
>  		return got_error_from_errno("fseeko");
>  
> -	err = got_opentemp_named(&path, &f, GOT_TMPDIR_STR "/tog", ".diff");
> +	if (s->id1 != NULL) {
> +		err = got_object_id_str(&idstr1, s->id1);
> +		if (err != NULL)
> +			return err;
> +	}
> +	err = got_object_id_str(&idstr2, s->id2);
>  	if (err != NULL)
> -		return err;
> +		goto done;
>  
> +	rc = snprintf(pathbase, sizeof(pathbase), "%s/tog-%.8s-%.8s",
> +	    GOT_TMPDIR_STR, idstr1 != NULL ? idstr1 : "empty", idstr2);
> +	if (rc < 0 || (size_t)rc >= sizeof(pathbase)) {
> +		err = got_error(rc < 0 ? GOT_ERR_IO : GOT_ERR_NO_SPACE);
> +		goto done;
> +	}
> +
> +	err = got_opentemp_named(&path, &f, pathbase, ".diff");
> +	if (err != NULL)
> +		goto done;
> +
>  	while ((r = fread(buf, 1, sizeof(buf), s->f)) > 0) {
>  		if (fwrite(buf, 1, r, f) != r) {
>  			err = got_ferror(f, GOT_ERR_IO);
> @@ -5870,6 +5887,8 @@ done:
>  	if (f != NULL && fclose(f) == EOF && err == NULL)
>  		err = got_error_from_errno2("fclose", path);
>  	free(path);
> +	free(idstr1);
> +	free(idstr2);
>  	return err;
>  }
>  
> 
> 
> -- 
> Mark Jamsek <https://bsdbox.org>
> GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68
> 
>