case DIFF_STATUS_UNMERGED:
case DIFF_STATUS_MODIFIED:
case DIFF_STATUS_TYPE_CHANGED:
- if (add_file_to_cache(path, data->flags & ADD_FILES_VERBOSE)) {
- if (!(data->flags & ADD_FILES_IGNORE_ERRORS))
- add_file_to_cache(path, flags);
++ if (add_file_to_cache(path, data->flags)) {
++ if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
+ die("updating files failed");
+ data->add_errors++;
+ }
break;
case DIFF_STATUS_DELETED:
- remove_file_from_cache(path);
- if (data->flags & ADD_FILES_VERBOSE)
- if (!(flags & ADD_CACHE_PRETEND))
++ if (!(data->flags & ADD_CACHE_PRETEND))
+ remove_file_from_cache(path);
- if (flags)
++ if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
printf("remove '%s'\n", path);
break;
}
newfd = hold_locked_index(&lock_file, 1);
- (show_only ? ADD_CACHE_PRETEND : 0));
+ flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
++ (show_only ? ADD_CACHE_PRETEND : 0) |
++ (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0));
+
if (take_worktree_changes) {
- int flags = 0;
const char **pathspec;
if (read_cache() < 0)
die("index file corrupt");
pathspec = get_pathspec(prefix, argv);
-
- if (verbose)
- flags |= ADD_FILES_VERBOSE;
- if (ignore_add_errors)
- flags |= ADD_FILES_IGNORE_ERRORS;
-
- add_files_to_cache(prefix, pathspec, flags);
+ exit_status = add_files_to_cache(prefix, pathspec, flags);
goto finish;
}
}
for (i = 0; i < dir.nr; i++)
- if (add_file_to_cache(dir.entries[i]->name, verbose)) {
- add_file_to_cache(dir.entries[i]->name, flags);
++ if (add_file_to_cache(dir.entries[i]->name, flags)) {
+ if (!ignore_add_errors)
+ die("adding files failed");
+ exit_status = 1;
+ }
finish:
if (active_cache_changed) {
for (i = 0; i < added.nr; i++) {
const char *path = added.items[i].path;
- if (add_file_to_cache(path, verbose))
- add_file_to_cache(path, verbose ? ADD_CACHE_VERBOSE : 0);
++ if (add_file_to_cache(path, verbose ? ADD_CACHE_VERBOSE : 0))
+ die("updating index entries failed");
}
for (i = 0; i < deleted.nr; i++)
extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
extern int remove_index_entry_at(struct index_state *, int pos);
extern int remove_file_from_index(struct index_state *, const char *path);
- extern int add_to_index(struct index_state *, const char *path, struct stat *, int verbose);
- extern int add_file_to_index(struct index_state *, const char *path, int verbose);
+ #define ADD_CACHE_VERBOSE 1
+ #define ADD_CACHE_PRETEND 2
++#define ADD_CACHE_IGNORE_ERRORS 4
+ extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
+ extern int add_file_to_index(struct index_state *, const char *path, int flags);
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
/* add */
- #define ADD_FILES_VERBOSE 01
- #define ADD_FILES_IGNORE_ERRORS 02
-void add_files_to_cache(const char *prefix, const char **pathspec, int flags);
+/*
+ * return 0 if success, 1 - if addition of a file failed and
+ * ADD_FILES_IGNORE_ERRORS was specified in flags
+ */
+int add_files_to_cache(const char *prefix, const char **pathspec, int flags);
/* diff.c */
extern int diff_auto_refresh_index;
mode_t st_mode = st->st_mode;
struct cache_entry *ce, *alias;
unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_RACY_IS_DIRTY;
+ int verbose = flags & (ADD_CACHE_VERBOSE | ADD_CACHE_PRETEND);
+ int pretend = flags & ADD_CACHE_PRETEND;
if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
- die("%s: can only add regular files, symbolic links or git-directories", path);
+ return error("%s: can only add regular files, symbolic links or git-directories", path);
namelen = strlen(path);
if (S_ISDIR(st_mode)) {
if (ignore_case && alias && different_name(ce, alias))
ce = create_alias_ce(ce, alias);
ce->ce_flags |= CE_ADDED;
- if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
+
+ /* It was suspected to be recily clean, but it turns out to be Ok */
+ was_same = (alias &&
+ !ce_stage(alias) &&
+ !hashcmp(alias->sha1, ce->sha1) &&
+ ce->ce_mode == alias->ce_mode);
+
+ if (pretend)
+ ;
+ else if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
- die("unable to add %s to index",path);
+ return error("unable to add %s to index",path);
- if (verbose)
+ if (verbose && !was_same)
printf("add '%s'\n", path);
return 0;
}