author | Junio C Hamano <gitster@pobox.com> | |
Sun, 25 May 2008 21:03:50 +0000 (14:03 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 25 May 2008 21:03:50 +0000 (14:03 -0700) |
* 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
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
1 | 2 | |||
---|---|---|---|---|
builtin-add.c | patch | | diff1 | | diff2 | | blob | history |
builtin-mv.c | patch | | diff1 | | diff2 | | blob | history |
cache.h | patch | | diff1 | | diff2 | | blob | history |
read-cache.c | patch | | diff1 | | diff2 | | blob | history |
diff --cc builtin-add.c
index 73235ed08a9d60f8134235d9b68632303f359ca9,8f81f3fbfb06d0acb7df9a14fc3a873834cfecf0..6e4e645cb7ba1624825fac9ff3f1d9bce5e93689
--- 1/builtin-add.c
--- 2/builtin-add.c
+++ b/builtin-add.c
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) {
diff --cc builtin-mv.c
index fb8ffb41aaba5f6e2a8cc13207a2f2c407d6c91d,df9ea97744f0473f1ee4a7c7c8e78a87ccb22865..fb906b3fc7838dd81add9d87e5001d70e83e1e48
--- 1/builtin-mv.c
--- 2/builtin-mv.c
+++ b/builtin-mv.c
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 3d4e8e77d8d47f1861af6488aacb1e8a9a57ac8f,b1a8427b9193ed49ba3afd8a31e278b268616ad5..943bee9e7da6ce2b903ab9331b35430ecb09644e
+++ b/cache.h
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;
diff --cc read-cache.c
index bc039819ee24083f13fee4558e51f16dee72a918,5d967e8ec9520a54fe615c4aef6fa6c8e5294dc6..ac9a8e7e323bb7b0728b2b199ab4f4a9bc5ce22f
--- 1/read-cache.c
--- 2/read-cache.c
+++ b/read-cache.c
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;
}