@matheusbsbs / matheus-bagliano / commits / 0602f3e916
Fork 0

Add struct pathspec

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>

Nguyễn Thái Ngọc Duy committed Dec 15, 2010 at 22:02 UTC 0602f3e916a2727dfc4954b81ce5aacd69d9692c
2 files changed +42
cache.h
+11
@@ -500,6 +500,17 @@ extern int index_name_is_other(const struct index_state *, const char *, int);
500 extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
501 extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
502
503 +struct pathspec {
504 + const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
505 + int nr;
506 + struct pathspec_item {
507 + const char *match;
508 + int len;
509 + } *items;
510 +};
511 +
512 +extern int init_pathspec(struct pathspec *, const char **);
513 +extern void free_pathspec(struct pathspec *);
514 extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
515 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
516 extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
dir.c
+31
@@ -1151,3 +1151,34 @@ int remove_path(const char *name)
1151 return 0;
1152 }
1153
1154 +int init_pathspec(struct pathspec *pathspec, const char **paths)
1155 +{
1156 + const char **p = paths;
1157 + int i;
1158 +
1159 + memset(pathspec, 0, sizeof(*pathspec));
1160 + if (!p)
1161 + return 0;
1162 + while (*p)
1163 + p++;
1164 + pathspec->raw = paths;
1165 + pathspec->nr = p - paths;
1166 + if (!pathspec->nr)
1167 + return 0;
1168 +
1169 + pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
1170 + for (i = 0; i < pathspec->nr; i++) {
1171 + struct pathspec_item *item = pathspec->items+i;
1172 + const char *path = paths[i];
1173 +
1174 + item->match = path;
1175 + item->len = strlen(path);
1176 + }
1177 + return 0;
1178 +}
1179 +
1180 +void free_pathspec(struct pathspec *pathspec)
1181 +{
1182 + free(pathspec->items);
1183 + pathspec->items = NULL;
1184 +}