Skip to content

Commit

Permalink
Add struct pathspec
Browse files Browse the repository at this point in the history
The old pathspec structure remains as pathspec.raw[]. New things are
stored in pathspec.items[]. There's no guarantee that the pathspec
order in raw[] is exactly as in items[].

raw[] is external (source) data and is untouched by pathspec
manipulation functions. It eases migration from old const char ** to
this new struct.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Feb 3, 2011
1 parent 7ed863a commit 0602f3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ extern int index_name_is_other(const struct index_state *, const char *, int);
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);

struct pathspec {
const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
int nr;
struct pathspec_item {
const char *match;
int len;
} *items;
};

extern int init_pathspec(struct pathspec *, const char **);
extern void free_pathspec(struct pathspec *);
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
Expand Down
31 changes: 31 additions & 0 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,34 @@ int remove_path(const char *name)
return 0;
}

int init_pathspec(struct pathspec *pathspec, const char **paths)
{
const char **p = paths;
int i;

memset(pathspec, 0, sizeof(*pathspec));
if (!p)
return 0;
while (*p)
p++;
pathspec->raw = paths;
pathspec->nr = p - paths;
if (!pathspec->nr)
return 0;

pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
for (i = 0; i < pathspec->nr; i++) {
struct pathspec_item *item = pathspec->items+i;
const char *path = paths[i];

item->match = path;
item->len = strlen(path);
}
return 0;
}

void free_pathspec(struct pathspec *pathspec)
{
free(pathspec->items);
pathspec->items = NULL;
}

0 comments on commit 0602f3e

Please sign in to comment.