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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: add got_patch_process_cb
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Mon, 14 Mar 2022 22:28:02 +0100

Download raw body.

Thread
On Mon, Mar 14, 2022 at 10:18:15PM +0100, Omar Polo wrote:
> blob - 6e5ec0f2143d39ff9eeca89060522c5155706a77
> blob + a10f54062e0e80aa2a49665b6f36f51f610d9350
> --- lib/patch.c
> +++ lib/patch.c
> @@ -66,12 +66,19 @@ struct got_patch_hunk {
>  };
>  
>  struct got_patch {
> +	got_patch_progress_cb cb;
> +	void	*arg;

These should no longer be needed? ^

Oh wait, you did not go all the way.
patch_add() was not updated to use struct patch_args. More below.

>  	int	 nop;
>  	char	*old;
>  	char	*new;
>  	STAILQ_HEAD(, got_patch_hunk) head;
>  };
>  
> +struct patch_args {
> +	got_patch_progress_cb progress_cb;
> +	void	*progress_arg;
> +};
> +
>  static const struct got_error *
>  send_patch(struct imsgbuf *ibuf, int fd)
>  {
> @@ -565,13 +572,29 @@ check_file_status(struct got_patch *p, int file_rename
>  }
>  
>  static const struct got_error *
> +patch_delete(void *arg, unsigned char status, unsigned char staged_status,
> +    const char *path)
> +{
> +	struct patch_args *pa = arg;
> +
> +	return pa->progress_cb(pa->progress_arg, path, NULL, status);
> +}
> +
> +static const struct got_error *
> +patch_add(void *arg, unsigned char status, const char *path)
> +{
> +	struct got_patch *p = arg;
> +
> +	return p->cb(p->arg, NULL, path, status);
> +}

> @@ -654,9 +681,8 @@ done:
>  
>  const struct got_error *
>  got_patch(int fd, struct got_worktree *worktree, struct got_repository *repo,
> -    int nop, got_worktree_delete_cb delete_cb, void *delete_arg,
> -    got_worktree_checkout_cb add_cb, void *add_arg, got_cancel_cb cancel_cb,
> -    void *cancel_arg)
> +    int nop, got_patch_progress_cb progress_cb, void *progress_arg,
> +    got_cancel_cb cancel_cb, void *cancel_arg)
>  {
>  	const struct got_error *err = NULL;
>  	struct imsgbuf *ibuf;
> @@ -704,9 +730,10 @@ got_patch(int fd, struct got_worktree *worktree, struc
>  		if (err || done)
>  			break;
>  
> +		p.cb = progress_cb;
> +		p.arg = progress_arg;
>  		p.nop = nop;

Could we pass progress_cb, progress_arg, and nop as separate arguments
to apply_patch(), instead of stashing them into struct got_patch?

> -		err = apply_patch(worktree, repo, &p, delete_cb, delete_arg,
> -		    add_cb, add_arg, cancel_cb, cancel_arg);
> +		err = apply_patch(worktree, repo, &p, cancel_cb, cancel_arg);
>  		patch_free(&p);
>  		if (err)
>  			break;
> 
> 
>