aboutsummaryrefslogtreecommitdiff
path: root/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-10-11 18:45:33 -0700
committerJunio C Hamano <junkio@cox.net>2005-10-11 18:45:33 -0700
commit3e09cdfd114651fc61656dbd45d5ec3d9352cb2b (patch)
treec72ab5b681371a4a78fe3fdc1c2843cd531d75d4 /update-index.c
parent5cbb401dbaff5fd810a85b84333cb0c22d264f36 (diff)
downloadgit-3e09cdfd114651fc61656dbd45d5ec3d9352cb2b.tar.gz
git-3e09cdfd114651fc61656dbd45d5ec3d9352cb2b.tar.xz
Use core.filemode.
With "[core] filemode = false", you can tell git to ignore differences in the working tree file only in executable bit. * "git-update-index --refresh" does not say "needs update" if index entry and working tree file differs only in executable bit. * "git-update-index" on an existing path takes executable bit from the existing index entry, if the path and index entry are both regular files. * "git-diff-files" and "git-diff-index" without --cached flag pretend the path on the filesystem has the same executable bit as the existing index entry, if the path and index entry are both regular files. If you are on a filesystem with unreliable mode bits, you may need to force the executable bit after registering the path in the index. * "git-update-index --chmod=+x foo" flips the executable bit of the index file entry for path "foo" on. Use "--chmod=-x" to flip it off. Note that --chmod only works in index file and does not look at nor update the working tree. So if you are on a filesystem and do not have working executable bit, you would do: 1. set the appropriate .git/config option; 2. "git-update-index --add new-file.c" 3. "git-ls-files --stage new-file.c" to see if it has the desired mode bits. If not, e.g. to drop executable bit picked up from the filesystem, say "git-update-index --chmod=-x new-file.c". Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r--update-index.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/update-index.c b/update-index.c
index 01b4088ad..1eeb45dbb 100644
--- a/update-index.c
+++ b/update-index.c
@@ -67,13 +67,23 @@ static int add_file_to_cache(const char *path)
return error("lstat(\"%s\"): %s", path,
strerror(errno));
}
+
namelen = strlen(path);
size = cache_entry_size(namelen);
ce = xmalloc(size);
memset(ce, 0, size);
memcpy(ce->name, path, namelen);
fill_stat_cache_info(ce, &st);
+
ce->ce_mode = create_ce_mode(st.st_mode);
+ if (!trust_executable_bit) {
+ /* If there is an existing entry, pick the mode bits
+ * from it.
+ */
+ int pos = cache_name_pos(path, namelen);
+ if (0 <= pos)
+ ce->ce_mode = active_cache[pos]->ce_mode;
+ }
ce->ce_flags = htons(namelen);
if (index_path(ce->sha1, path, &st, !info_only))
@@ -253,8 +263,32 @@ static int add_cacheinfo(const char *arg1, const char *arg2, const char *arg3)
return add_cache_entry(ce, option);
}
-static struct cache_file cache_file;
+static int chmod_path(int flip, const char *path)
+{
+ int pos;
+ struct cache_entry *ce;
+ unsigned int mode;
+ pos = cache_name_pos(path, strlen(path));
+ if (pos < 0)
+ return -1;
+ ce = active_cache[pos];
+ mode = ntohl(ce->ce_mode);
+ if (!S_ISREG(mode))
+ return -1;
+ switch (flip) {
+ case '+':
+ ce->ce_mode |= htonl(0111); break;
+ case '-':
+ ce->ce_mode &= htonl(~0111); break;
+ default:
+ return -1;
+ }
+ active_cache_changed = 1;
+ return 0;
+}
+
+static struct cache_file cache_file;
static void update_one(const char *path, const char *prefix, int prefix_length)
{
@@ -328,6 +362,8 @@ int main(int argc, const char **argv)
const char *prefix = setup_git_directory();
int prefix_length = prefix ? strlen(prefix) : 0;
+ git_config(git_default_config);
+
newfd = hold_index_file_for_update(&cache_file, get_index_file());
if (newfd < 0)
die("unable to create new cachefile");
@@ -376,6 +412,14 @@ int main(int argc, const char **argv)
i += 3;
continue;
}
+ if (!strcmp(path, "--chmod=-x") ||
+ !strcmp(path, "--chmod=+x")) {
+ if (argc <= i+1)
+ die("git-update-index: %s <path>", path);
+ if (chmod_path(path[8], argv[++i]))
+ die("git-update-index: %s cannot chmod %s", path, argv[i]);
+ continue;
+ }
if (!strcmp(path, "--info-only")) {
info_only = 1;
continue;