@matheusbsbs / matheus-bagliano / commits / b6ec1d619f
Fork 0

Fix add_files_to_cache() to take pathspec, not user specified list of files

This separates the logic to limit the extent of change to the index by where you are (controlled by "prefix") and what you specify from the command line (controlled by "pathspec"). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 18, 2007 at 01:12 UTC b6ec1d619fb54642388063a88e2255556cf5de06
3 files changed +8 -5
builtin-add.c
+5 -3
@@ -105,12 +105,12 @@ static void update_callback(struct diff_queue_struct *q,
105 }
106 }
107
108 -void add_files_to_cache(int verbose, const char *prefix, const char **files)
108 +void add_files_to_cache(int verbose, const char *prefix, const char **pathspec)
109 {
110 struct rev_info rev;
111 init_revisions(&rev, prefix);
112 setup_revisions(0, NULL, &rev, NULL);
113 - rev.prune_data = get_pathspec(prefix, files);
113 + rev.prune_data = pathspec;
114 rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
115 rev.diffopt.format_callback = update_callback;
116 rev.diffopt.format_callback_data = &verbose;
@@ -180,9 +180,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
180 newfd = hold_locked_index(&lock_file, 1);
181
182 if (take_worktree_changes) {
183 + const char **pathspec;
184 if (read_cache() < 0)
185 die("index file corrupt");
185 - add_files_to_cache(verbose, prefix, argv);
186 + pathspec = get_pathspec(prefix, argv);
187 + add_files_to_cache(verbose, prefix, pathspec);
188 goto finish;
189 }
190
cache.h
+3 -1
@@ -604,13 +604,15 @@ extern void trace_argv_printf(const char **argv, int count, const char *format,
604 extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst);
605 extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
606
607 +/* add */
608 +void add_files_to_cache(int verbose, const char *prefix, const char **pathspec);
609 +
610 /* diff.c */
611 extern int diff_auto_refresh_index;
612
613 /* match-trees.c */
614 void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
615
613 -
616 /* ls-files */
617 int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
618 int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
commit.h
-1
@@ -114,7 +114,6 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
114 int in_merge_bases(struct commit *, struct commit **, int);
115
116 extern int interactive_add(void);
117 -extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
117 extern int rerere(void);
118
119 static inline int single_parent(struct commit *commit)