mirror of
https://github.com/git/git
synced 2024-11-04 16:17:49 +00:00
revision: optionally record matches with pathspec elements
Unlike "git add" and other end-user facing commands, where it is diagnosed as an error to give a pathspec with an element that does not match any path, the diff machinery does not care if some elements of the pathspec do not match. Given that the diff machinery is heavily used in pathspec-limited "git log" machinery, and it is common for a path to come and go while traversing the project history, this is usually a good thing. However, in some cases we would want to know if all the pathspec elements matched. For example, "git add -u <pathspec>" internally uses the machinery used by "git diff-files" to decide contents from what paths to add to the index, and as an end-user facing command, "git add -u" would want to report an unmatched pathspec element. Add a new .ps_matched member next to the .prune_data member in "struct rev_info" so that we can optionally keep track of the use of .prune_data pathspec elements that can be inspected by the caller. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d6fd04375f
commit
86829f3f3e
7 changed files with 23 additions and 10 deletions
|
@ -553,8 +553,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
exit_status |= renormalize_tracked_files(&pathspec, flags);
|
exit_status |= renormalize_tracked_files(&pathspec, flags);
|
||||||
else
|
else
|
||||||
exit_status |= add_files_to_cache(the_repository, prefix,
|
exit_status |= add_files_to_cache(the_repository, prefix,
|
||||||
&pathspec, include_sparse,
|
&pathspec, NULL,
|
||||||
flags);
|
include_sparse, flags);
|
||||||
|
|
||||||
if (add_new_files)
|
if (add_new_files)
|
||||||
exit_status |= add_files(&dir, flags);
|
exit_status |= add_files(&dir, flags);
|
||||||
|
|
|
@ -878,7 +878,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
|
||||||
* entries in the index.
|
* entries in the index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
add_files_to_cache(the_repository, NULL, NULL, 0, 0);
|
add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
|
||||||
|
0);
|
||||||
init_merge_options(&o, the_repository);
|
init_merge_options(&o, the_repository);
|
||||||
o.verbosity = 0;
|
o.verbosity = 0;
|
||||||
work = write_in_core_index_as_tree(the_repository);
|
work = write_in_core_index_as_tree(the_repository);
|
||||||
|
|
|
@ -444,7 +444,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
|
||||||
repo_hold_locked_index(the_repository, &index_lock,
|
repo_hold_locked_index(the_repository, &index_lock,
|
||||||
LOCK_DIE_ON_ERROR);
|
LOCK_DIE_ON_ERROR);
|
||||||
add_files_to_cache(the_repository, also ? prefix : NULL,
|
add_files_to_cache(the_repository, also ? prefix : NULL,
|
||||||
&pathspec, 0, 0);
|
&pathspec, NULL, 0, 0);
|
||||||
refresh_cache_or_die(refresh_flags);
|
refresh_cache_or_die(refresh_flags);
|
||||||
cache_tree_update(&the_index, WRITE_TREE_SILENT);
|
cache_tree_update(&the_index, WRITE_TREE_SILENT);
|
||||||
if (write_locked_index(&the_index, &index_lock, 0))
|
if (write_locked_index(&the_index, &index_lock, 0))
|
||||||
|
|
11
diff-lib.c
11
diff-lib.c
|
@ -127,7 +127,16 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
|
||||||
if (diff_can_quit_early(&revs->diffopt))
|
if (diff_can_quit_early(&revs->diffopt))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!ce_path_match(istate, ce, &revs->prune_data, NULL))
|
/*
|
||||||
|
* NEEDSWORK:
|
||||||
|
* Here we filter with pathspec but the result is further
|
||||||
|
* filtered out when --relative is in effect. To end-users,
|
||||||
|
* a pathspec element that matched only to paths outside the
|
||||||
|
* current directory is like not matching anything at all;
|
||||||
|
* the handling of ps_matched[] here may become problematic
|
||||||
|
* if/when we add the "--error-unmatch" option to "git diff".
|
||||||
|
*/
|
||||||
|
if (!ce_path_match(istate, ce, &revs->prune_data, revs->ps_matched))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (revs->diffopt.prefix &&
|
if (revs->diffopt.prefix &&
|
||||||
|
|
|
@ -480,8 +480,8 @@ extern int verify_ce_order;
|
||||||
int cmp_cache_name_compare(const void *a_, const void *b_);
|
int cmp_cache_name_compare(const void *a_, const void *b_);
|
||||||
|
|
||||||
int add_files_to_cache(struct repository *repo, const char *prefix,
|
int add_files_to_cache(struct repository *repo, const char *prefix,
|
||||||
const struct pathspec *pathspec, int include_sparse,
|
const struct pathspec *pathspec, char *ps_matched,
|
||||||
int flags);
|
int include_sparse, int flags);
|
||||||
|
|
||||||
void overlay_tree_on_index(struct index_state *istate,
|
void overlay_tree_on_index(struct index_state *istate,
|
||||||
const char *tree_name, const char *prefix);
|
const char *tree_name, const char *prefix);
|
||||||
|
|
|
@ -3958,8 +3958,8 @@ static void update_callback(struct diff_queue_struct *q,
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_files_to_cache(struct repository *repo, const char *prefix,
|
int add_files_to_cache(struct repository *repo, const char *prefix,
|
||||||
const struct pathspec *pathspec, int include_sparse,
|
const struct pathspec *pathspec, char *ps_matched,
|
||||||
int flags)
|
int include_sparse, int flags)
|
||||||
{
|
{
|
||||||
struct update_callback_data data;
|
struct update_callback_data data;
|
||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
|
@ -3971,8 +3971,10 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
|
||||||
|
|
||||||
repo_init_revisions(repo, &rev, prefix);
|
repo_init_revisions(repo, &rev, prefix);
|
||||||
setup_revisions(0, NULL, &rev, NULL);
|
setup_revisions(0, NULL, &rev, NULL);
|
||||||
if (pathspec)
|
if (pathspec) {
|
||||||
copy_pathspec(&rev.prune_data, pathspec);
|
copy_pathspec(&rev.prune_data, pathspec);
|
||||||
|
rev.ps_matched = ps_matched;
|
||||||
|
}
|
||||||
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
||||||
rev.diffopt.format_callback = update_callback;
|
rev.diffopt.format_callback = update_callback;
|
||||||
rev.diffopt.format_callback_data = &data;
|
rev.diffopt.format_callback_data = &data;
|
||||||
|
|
|
@ -142,6 +142,7 @@ struct rev_info {
|
||||||
/* Basic information */
|
/* Basic information */
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
const char *def;
|
const char *def;
|
||||||
|
char *ps_matched; /* optionally record matches of prune_data */
|
||||||
struct pathspec prune_data;
|
struct pathspec prune_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue