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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: make got add * easier to use
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Wed, 21 Jun 2023 16:33:05 +1000

Download raw body.

Thread
Stefan Sperling <stsp@stsp.name> wrote:
> This fixes an issue reported to me by Robert, who was running
> got add patches/patch-* in the ports tree and saw pointless errors.
> 
> ok?

Yes! This has got me a few times too, I like it :)

ok

> -----------------------------------------------
>  make 'got add' more forgiving about unversioned paths on the command line
>  
>  When users run 'got add *' the shell may pick up already versioned files
>  and trigger errors about paths being in an unexpected status. Expand the
>  check which previously only allowed files in added status to be double-added
>  to cover the following status codes which are all safe to ignore: A M C m
>  This should make bulk additions of files a bit easier in most cases.
>  
>  Problem reported by robert@
>  
> diff 9fc9df27559545b0cacca46fc6d8db711fdcaf41 f239f9cab93df2194dffc45336375966f58ba9bc
> commit - 9fc9df27559545b0cacca46fc6d8db711fdcaf41
> commit + f239f9cab93df2194dffc45336375966f58ba9bc
> blob - ee5ecec15b1c9954ab672ace7b9165717723b7d2
> blob + 8122fe9273cc37091dc13c83016ef03a2a436be5
> --- got/got.1
> +++ got/got.1
> @@ -1412,6 +1412,25 @@ The options for
>  .Cm got status
>  ignore pattern will not be added.
>  .Pp
> +If a
> +.Ar path
> +mentioned in the command line is not an unversioned file then
> +.Cm got add
> +may raise an error.
> +To avoid unnecessary errors from paths picked up by file globbing patterns
> +in the shell, paths in the argument list will be silently ignored if they
> +are not reported by
> +.Cm got status
> +at all, or if they are reported with one of the following status codes
> +and do not have changes staged via
> +.Cm got stage :
> +.Bl -column YXZ description
> +.It M Ta modified file
> +.It A Ta file scheduled for addition in next commit
> +.It C Ta modified or added file which contains merge conflicts
> +.It m Ta modified file modes (executable bit only)
> +.El
> +.Pp
>  The options for
>  .Cm got add
>  are as follows:
> blob - 95e2e6bfa46ac12fd077b083c122ade77e54106f
> blob + 158ecdaac43d28f8eb32bc6f3acf1cfda482fcaf
> --- lib/worktree.c
> +++ lib/worktree.c
> @@ -4197,6 +4197,16 @@ static const struct got_error *
>  	struct got_repository *repo;
>  };
>  
> +static int
> +add_noop_status(unsigned char status)
> +{
> +	return (status == GOT_STATUS_ADD ||
> +	    status == GOT_STATUS_MODIFY ||
> +	    status == GOT_STATUS_CONFLICT ||
> +	    status == GOT_STATUS_MODE_CHANGE ||
> +	    status == GOT_STATUS_NO_CHANGE);
> +}
> +
>  static const struct got_error *
>  schedule_addition(void *arg, unsigned char status, unsigned char staged_status,
>      const char *relpath, struct got_object_id *blob_id,
> @@ -4220,7 +4230,8 @@ schedule_addition(void *arg, unsigned char status, uns
>  		if (err)
>  			goto done;
>  		/* Re-adding an existing entry is a no-op. */
> -		if (status == GOT_STATUS_ADD)
> +		if (staged_status == GOT_STATUS_NO_CHANGE &&
> +		    add_noop_status(status))
>  			goto done;
>  		err = got_error_path(relpath, GOT_ERR_FILE_STATUS);
>  		if (err)
> @@ -4253,7 +4264,7 @@ done:
>  	free(ondisk_path);
>  	if (err)
>  		return err;
> -	if (status == GOT_STATUS_ADD)
> +	if (staged_status == GOT_STATUS_NO_CHANGE && add_noop_status(status))
>  		return NULL;
>  	return (*a->progress_cb)(a->progress_arg, GOT_STATUS_ADD, relpath);
>  }
> blob - eabde9c24df6b9d72582040315ce0f913a98716c
> blob + 230e87510d8cfc3bfd45d3bbfc058b91d0a05e6e
> --- regress/cmdline/add.sh
> +++ regress/cmdline/add.sh
> @@ -120,6 +120,7 @@ test_add_multiple() {
>  		return 1
>  	fi
>  
> +	echo "changed file" > $testroot/wt/alpha
>  	echo "new file" > $testroot/wt/bax
>  	(cd $testroot/wt && got add -R * > $testroot/stdout)
>  	ret=$?