Re: [PATCH 1/2] pathspec: allow querying for attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brandon Williams <bmwill@xxxxxxxxxx> writes:

> +struct attr_check *attr_check_dup(const struct attr_check *check)
> +{
> +	struct attr_check *ret;
> +
> +	if (!check)
> +		return NULL;
> +
> +	ret = attr_check_alloc();
> +
> +	ret->nr = check->nr;
> +	ret->alloc = check->alloc;
> +	ALLOC_ARRAY(ret->items, ret->nr);
> +	COPY_ARRAY(ret->items, check->items, ret->nr);
> +
> +	return ret;
> +}

Because an attr_check instance cannot be shared and used by multiple
threads, we expect that the callers that go multi-thread to copy
pathspec to each worker, and preload_index(), which is an existing
example of such a caller, already does so with copy_pathspec().

Makes sense.

> @@ -565,26 +653,47 @@ void parse_pathspec(struct pathspec *pathspec,
>  
>  void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
>  {
> -	int i;
> +	int i, j;
>  
>  	*dst = *src;
>  	ALLOC_ARRAY(dst->items, dst->nr);
>  	COPY_ARRAY(dst->items, src->items, dst->nr);
>  
>  	for (i = 0; i < dst->nr; i++) {
> -		dst->items[i].match = xstrdup(src->items[i].match);
> -		dst->items[i].original = xstrdup(src->items[i].original);
> +		struct pathspec_item *d = &dst->items[i];
> +		struct pathspec_item *s = &src->items[i];
> +
> +		d->match = xstrdup(s->match);
> +		d->original = xstrdup(s->original);
> +
> +		ALLOC_ARRAY(d->attr_match, d->attr_match_nr);
> +		COPY_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr);
> +		for (j = 0; j < d->attr_match_nr; j++) {
> +			const char *value = s->attr_match[j].value;
> +			if (value)
> +				d->attr_match[j].value = xstrdup(value);

We have xstrdup_or_null(), which may help here.

> +		}
> +
> +		d->attr_check = attr_check_dup(s->attr_check);
>  	}
>  }
>  
>  void clear_pathspec(struct pathspec *pathspec)
>  {
> -	int i;
> +	int i, j;
>  
>  	for (i = 0; i < pathspec->nr; i++) {
>  		free(pathspec->items[i].match);
>  		free(pathspec->items[i].original);
> +
> +		for (j = 0; j < pathspec->items[j].attr_match_nr; j++)
> +			free(pathspec->items[i].attr_match[j].value);
> +		free(pathspec->items[i].attr_match);
> +
> +		if (pathspec->items[i].attr_check)
> +			attr_check_free(pathspec->items[i].attr_check);
>  	}
> +
>  	free(pathspec->items);
>  	pathspec->items = NULL;
>  	pathspec->nr = 0;

OK, makes sense.

> diff --git a/t/t6135-pathspec-with-attrs.sh b/t/t6135-pathspec-with-attrs.sh
> new file mode 100755
> index 000000000..b5e5a0607
> --- /dev/null
> +++ b/t/t6135-pathspec-with-attrs.sh
> @@ -0,0 +1,181 @@
> +#!/bin/sh
> +
> +test_description='test labels in pathspecs'
> +. ./test-lib.sh
> +
> +test_expect_success 'setup a tree' '
> +	cat <<-EOF >expect &&

Minor style nit. Quote the 'EOF' marker and you signal to readers
that what they'll see are literally the values, and they do not have
to worry about $variable_interpolation.  I.e.

	cat <<-\EOF >expect &&

> +test_expect_success 'fail if attr magic is used places not implemented' '
> +	# The main purpose of this test is to check that we actually fail
> +	# when you attempt to use attr magic in commands that do not implement
> +	# attr magic. This test does not advocate git-add to stay that way,
> +	# though, but git-add is convenient as it has its own internal pathspec
> +	# parsing.

That's thought-provoking ;-) Would it help to add a test-pathspec
helper, similar to test-config helper, that serves as a vehicle to
test this?

> +	test_must_fail git add ":(attr:labelB)" 2>actual &&
> +	test_i18ngrep "unsupported magic" actual
> +'

Thanks.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]