aboutsummaryrefslogtreecommitdiff
path: root/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-09-19 15:11:15 -0700
committerJunio C Hamano <junkio@cox.net>2005-09-20 15:07:53 -0700
commitb0391890d25d9e7ca8f7df2199292df68ead8093 (patch)
tree9562d2c1387af4afb6f72317e8e1155b4b7fca48 /update-index.c
parent1991b223c05d45d2a915842990b2a7c4819dcbcf (diff)
downloadgit-b0391890d25d9e7ca8f7df2199292df68ead8093.tar.gz
git-b0391890d25d9e7ca8f7df2199292df68ead8093.tar.xz
Show modified files in git-ls-files
Add -m/--modified to show files that have been modified wrt. the index. [jc: The original came from Brian Gerst on Sep 1st but it only checked if the paths were cache dirty without actually checking the files were modified. I also added the usage string and a new test.] Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r--update-index.c67
1 files changed, 1 insertions, 66 deletions
diff --git a/update-index.c b/update-index.c
index 60c841749..cb0265bdf 100644
--- a/update-index.c
+++ b/update-index.c
@@ -112,47 +112,6 @@ static int add_file_to_cache(char *path)
return 0;
}
-static int compare_data(struct cache_entry *ce, struct stat *st)
-{
- int match = -1;
- int fd = open(ce->name, O_RDONLY);
-
- if (fd >= 0) {
- unsigned char sha1[20];
- if (!index_fd(sha1, fd, st, 0, NULL))
- match = memcmp(sha1, ce->sha1, 20);
- close(fd);
- }
- return match;
-}
-
-static int compare_link(struct cache_entry *ce, unsigned long expected_size)
-{
- int match = -1;
- char *target;
- void *buffer;
- unsigned long size;
- char type[10];
- int len;
-
- target = xmalloc(expected_size);
- len = readlink(ce->name, target, expected_size);
- if (len != expected_size) {
- free(target);
- return -1;
- }
- buffer = read_sha1_file(ce->sha1, type, &size);
- if (!buffer) {
- free(target);
- return -1;
- }
- if (size == expected_size)
- match = memcmp(buffer, target, size);
- free(buffer);
- free(target);
- return match;
-}
-
/*
* "refresh" does not calculate a new sha1 file or bring the
* cache up-to-date for mode/content changes. But what it
@@ -177,33 +136,9 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce)
if (!changed)
return ce;
- /*
- * If the mode or type has changed, there's no point in trying
- * to refresh the entry - it's not going to match
- */
- if (changed & (MODE_CHANGED | TYPE_CHANGED))
- return ERR_PTR(-EINVAL);
-
- /* Immediately after read-tree or update-index --cacheinfo,
- * the length field is zero. For other cases the ce_size
- * should match the SHA1 recorded in the index entry.
- */
- if ((changed & DATA_CHANGED) && ce->ce_size != htonl(0))
+ if (ce_modified(ce, &st))
return ERR_PTR(-EINVAL);
- switch (st.st_mode & S_IFMT) {
- case S_IFREG:
- if (compare_data(ce, &st))
- return ERR_PTR(-EINVAL);
- break;
- case S_IFLNK:
- if (compare_link(ce, st.st_size))
- return ERR_PTR(-EINVAL);
- break;
- default:
- return ERR_PTR(-EINVAL);
- }
-
size = ce_size(ce);
updated = xmalloc(size);
memcpy(updated, ce, size);