summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorTorsten Bögershausen <tboegi@web.de>2013-03-30 09:53:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-04-05 19:39:38 (GMT)
commitcbe43b847379e8d3db6aab2913b29b730fa5ca45 (patch)
tree589827aad1a219d4e708ff06f8d15cb3cb6e68ae /path.c
parent3a429d3b8d03c98fbc775eb34a54b7b2bd74e02b (diff)
downloadgit-cbe43b847379e8d3db6aab2913b29b730fa5ca45.zip
git-cbe43b847379e8d3db6aab2913b29b730fa5ca45.tar.gz
git-cbe43b847379e8d3db6aab2913b29b730fa5ca45.tar.bz2
path.c: optimize adjust_shared_perm()
Sometimes the chown() function is called even when not needed (This can be provoked by running t1301, and adding some debug code). Save a chmod from 400 to 400, or from 600 to 600 on these files: .git/info/refs+ .git/objects/info/packs+ Save chmod on directories from 2770 to 2770: .git/refs .git/refs/heads .git/refs/tags Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/path.c b/path.c
index e27959a..04ff148 100644
--- a/path.c
+++ b/path.c
@@ -396,22 +396,14 @@ const char *enter_repo(const char *path, int strict)
return NULL;
}
-int adjust_shared_perm(const char *path)
+static int calc_shared_perm(int mode)
{
- int tweak, shared, orig_mode, mode;
+ int tweak;
- if (!shared_repository) {
- return 0;
- }
- if (get_st_mode_bits(path, &mode) < 0)
- return -1;
-
- orig_mode = mode;
if (shared_repository < 0)
- shared = -shared_repository;
+ tweak = -shared_repository;
else
- shared = shared_repository;
- tweak = shared;
+ tweak = shared_repository;
if (!(mode & S_IWUSR))
tweak &= ~0222;
@@ -423,16 +415,28 @@ int adjust_shared_perm(const char *path)
else
mode |= tweak;
- if (S_ISDIR(mode)) {
+ return mode;
+}
+
+
+int adjust_shared_perm(const char *path)
+{
+ int old_mode, new_mode;
+
+ if (!shared_repository)
+ return 0;
+ if (get_st_mode_bits(path, &old_mode) < 0)
+ return -1;
+
+ new_mode = calc_shared_perm(old_mode);
+ if (S_ISDIR(old_mode)) {
/* Copy read bits to execute bits */
- mode |= (shared & 0444) >> 2;
- mode |= FORCE_DIR_SET_GID;
+ new_mode |= (new_mode & 0444) >> 2;
+ new_mode |= FORCE_DIR_SET_GID;
}
- if (((shared_repository < 0
- ? (orig_mode & (FORCE_DIR_SET_GID | 0777))
- : (orig_mode & mode)) != mode) &&
- chmod(path, (mode & ~S_IFMT)) < 0)
+ if (((old_mode ^ new_mode) & ~S_IFMT) &&
+ chmod(path, (new_mode & ~S_IFMT)) < 0)
return -2;
return 0;
}