summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-05-25 21:03:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-05-25 21:03:50 (GMT)
commit0166592495e21b075fa48225ff21568269bf51d4 (patch)
tree21c295f211ad2aeaa798222e7c5564f17a90a429 /read-cache.c
parent488ee2fe21ca69b90aa2b43dc9e30279a12cca63 (diff)
parent205ffa94be8f6492eef4bdaa3315e7fdc7e64e0b (diff)
downloadgit-0166592495e21b075fa48225ff21568269bf51d4.zip
git-0166592495e21b075fa48225ff21568269bf51d4.tar.gz
git-0166592495e21b075fa48225ff21568269bf51d4.tar.bz2
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
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/read-cache.c b/read-cache.c
index bc03981..ac9a8e7 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -462,12 +462,14 @@ static struct cache_entry *create_alias_ce(struct cache_entry *ce, struct cache_
return new;
}
-int add_to_index(struct index_state *istate, const char *path, struct stat *st, int verbose)
+int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags)
{
- int size, namelen;
+ int size, namelen, was_same;
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))
return error("%s: can only add regular files, symbolic links or git-directories", path);
@@ -509,19 +511,28 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
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))
return error("unable to add %s to index",path);
- if (verbose)
+ if (verbose && !was_same)
printf("add '%s'\n", path);
return 0;
}
-int add_file_to_index(struct index_state *istate, const char *path, int verbose)
+int add_file_to_index(struct index_state *istate, const char *path, int flags)
{
struct stat st;
if (lstat(path, &st))
die("%s: unable to stat (%s)", path, strerror(errno));
- return add_to_index(istate, path, &st, verbose);
+ return add_to_index(istate, path, &st, flags);
}
struct cache_entry *make_cache_entry(unsigned int mode,