Re: [PATCH v2 10/14] For each exclude pattern, store information about where it came from

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

 



Adam Spiers <git@xxxxxxxxxxxxxx> writes:

>  void add_exclude(const char *string, const char *base,
> -		 int baselen, struct exclude_list *el)
> +		 int baselen, struct exclude_list *el, const char *src, int srcpos)
>  {
>  	struct exclude *x;
>  	size_t len;
> @@ -341,6 +341,8 @@ void add_exclude(const char *string, const char *base,
>  	x->base = base;
>  	x->baselen = baselen;
>  	x->flags = flags;
> +	x->src = src;
> +	x->srcpos = srcpos;

Hrm, don't all elements "x" in "el" share the same "src", even if
their srcpos may be different?

>  	if (!strchr(string, '/'))
>  		x->flags |= EXC_FLAG_NODIR;
>  	x->nowildcardlen = simple_length(string);
> @@ -393,7 +395,7 @@ int add_excludes_from_file_to_list(const char *fname,
>  				   int check_index)
>  {
>  	struct stat st;
> -	int fd, i;
> +	int fd, i, lineno = 1;
>  	size_t size = 0;
>  	char *buf, *entry;
>  
> @@ -438,8 +440,9 @@ int add_excludes_from_file_to_list(const char *fname,
>  		if (buf[i] == '\n') {
>  			if (entry != buf + i && entry[0] != '#') {
>  				buf[i - (i && buf[i-1] == '\r')] = 0;
> -				add_exclude(entry, base, baselen, el);
> +				add_exclude(entry, base, baselen, el, fname, lineno);
>  			}
> +			lineno++;
>  			entry = buf + i + 1;
>  		}
>  	}
> @@ -474,8 +477,10 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
>  		    !strncmp(dir->basebuf, base, stk->baselen))
>  			break;
>  		dir->exclude_stack = stk->prev;
> -		while (stk->exclude_ix < el->nr)
> -			free(el->excludes[--el->nr]);
> +		while (stk->exclude_ix < el->nr) {
> +			struct exclude *exclude = el->excludes[--el->nr];
> +			free(exclude);
> +		}
>  		free(stk->filebuf);
>  		free(stk);
>  	}
> @@ -502,7 +507,15 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
>  		memcpy(dir->basebuf + current, base + current,
>  		       stk->baselen - current);
>  		strcpy(dir->basebuf + stk->baselen, dir->exclude_per_dir);
> -		add_excludes_from_file_to_list(dir->basebuf,
> +
> +		/* dir->basebuf gets reused by the traversal, but we
> +		 * need fname to remain unchanged to ensure the src
> +		 * member of each struct exclude correctly back-references
> +		 * its source file.
> +		 */
> +		char *fname = strdup(dir->basebuf);


	/*
         * We try to format our multi-line comments
         * like this.
         *
         * By the way, who owns x->src and who is responsible for
         * freeing it when the exclude-stack is popped to make them
         * no longer necessary?
         *
         * Oh, by the way, that is a decl-after-statement.
         */

> +
> +		add_excludes_from_file_to_list(fname,
>  					       dir->basebuf, stk->baselen,
>  					       &stk->filebuf, el, 1);
>  		dir->exclude_stack = stk;
> diff --git a/dir.h b/dir.h
> index 19beddb..ebb0367 100644
> --- a/dir.h
> +++ b/dir.h
> @@ -31,6 +31,9 @@ struct exclude_list {
>  		int baselen;
>  		int to_exclude;
>  		int flags;
> +		const char *src;
> +		int srcpos; /* counting starts from 1 for line numbers in ignore files,
> +			       and from -1 decrementing for patterns from CLI (--exclude) */
>  	} **excludes;
>  };
>  
> @@ -123,7 +126,7 @@ extern int add_excludes_from_file_to_list(const char *fname, const char *base, i
>  					  char **buf_p, struct exclude_list *el, int check_index);
>  extern void add_excludes_from_file(struct dir_struct *, const char *fname);
>  extern void add_exclude(const char *string, const char *base,
> -			int baselen, struct exclude_list *el);
> +			int baselen, struct exclude_list *el, const char *src, int srcpos);
>  extern void free_excludes(struct exclude_list *el);
>  extern int file_exists(const char *);
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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]