From: Junio C Hamano Date: Sun, 25 May 2008 21:03:50 +0000 (-0700) Subject: Merge branch 'jc/add-n-u' X-Git-Tag: v1.5.6-rc0~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0166592495e21b075fa48225ff21568269bf51d4;p=git.git Merge branch 'jc/add-n-u' * jc/add-n-u: Make git add -n and git -u -n output consistent "git-add -n -u" should not add but just report Conflicts: builtin-add.c builtin-mv.c cache.h read-cache.c --- 0166592495e21b075fa48225ff21568269bf51d4 diff --cc builtin-add.c index 73235ed08,8f81f3fbf..6e4e645cb --- a/builtin-add.c +++ b/builtin-add.c @@@ -100,15 -94,12 +100,16 @@@ static void update_callback(struct diff 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; } @@@ -233,19 -209,15 +235,16 @@@ int cmd_add(int argc, const char **argv newfd = hold_locked_index(&lock_file, 1); + flags = ((verbose ? ADD_CACHE_VERBOSE : 0) | - (show_only ? ADD_CACHE_PRETEND : 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; } @@@ -287,11 -248,7 +275,11 @@@ } 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) { diff --cc builtin-mv.c index fb8ffb41a,df9ea9774..fb906b3fc --- a/builtin-mv.c +++ b/builtin-mv.c @@@ -256,8 -256,7 +256,8 @@@ int cmd_mv(int argc, const char **argv 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++) diff --cc cache.h index 3d4e8e77d,b1a8427b9..943bee9e7 --- a/cache.h +++ b/cache.h @@@ -371,8 -366,10 +371,11 @@@ extern int add_index_entry(struct index 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); @@@ -791,13 -784,7 +794,11 @@@ extern int convert_to_git(const char *p 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; diff --cc read-cache.c index bc039819e,5d967e8ec..ac9a8e7e3 --- a/read-cache.c +++ b/read-cache.c @@@ -468,9 -468,11 +468,11 @@@ int add_to_index(struct index_state *is 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)) { @@@ -509,9 -511,18 +511,18 @@@ 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; }