Skip to content

Commit

Permalink
Fix add_files_to_cache() to take pathspec, not user specified list of…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
Junio C Hamano committed Nov 23, 2007
1 parent ee425e4 commit b6ec1d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ static void update_callback(struct diff_queue_struct *q,
}
}

void add_files_to_cache(int verbose, const char *prefix, const char **files)
void add_files_to_cache(int verbose, const char *prefix, const char **pathspec)
{
struct rev_info rev;
init_revisions(&rev, prefix);
setup_revisions(0, NULL, &rev, NULL);
rev.prune_data = get_pathspec(prefix, files);
rev.prune_data = pathspec;
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = &verbose;
Expand Down Expand Up @@ -180,9 +180,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
newfd = hold_locked_index(&lock_file, 1);

if (take_worktree_changes) {
const char **pathspec;
if (read_cache() < 0)
die("index file corrupt");
add_files_to_cache(verbose, prefix, argv);
pathspec = get_pathspec(prefix, argv);
add_files_to_cache(verbose, prefix, pathspec);
goto finish;
}

Expand Down
4 changes: 3 additions & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,15 @@ extern void trace_argv_printf(const char **argv, int count, const char *format,
extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst);
extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);

/* add */
void add_files_to_cache(int verbose, const char *prefix, const char **pathspec);

/* diff.c */
extern int diff_auto_refresh_index;

/* match-trees.c */
void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);


/* ls-files */
int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
Expand Down
1 change: 0 additions & 1 deletion commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int in_merge_bases(struct commit *, struct commit **, int);

extern int interactive_add(void);
extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
extern int rerere(void);

static inline int single_parent(struct commit *commit)
Expand Down

0 comments on commit b6ec1d6

Please sign in to comment.