From: "Torsten Bögershausen" <tboegi@web.de>
To: gitster@pobox.com
Cc: git@vger.kernel.org, j6t@kdbg.org, kusmabite@gmail.com,
mlevedahl@gmail.com, ramsay@ramsay1.demon.co.uk, tboegi@web.de,
sunshine@sunshineco.com
Subject: [PATCH 2/2] optimize adjust_shared_perm() in path.c:
Date: Sat, 30 Mar 2013 10:53:47 +0100 [thread overview]
Message-ID: <201303301053.49140.tboegi@web.de> (raw)
sometimes the chown() function is called even when not needed.
(This can be provoced by running t1301, and adding some debug code)
Save a chmod from 400 to 400, or from 600->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>
---
path.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/path.c b/path.c
index 427312e..33fa880 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;
}
--
1.8.2.341.g543621f
next reply other threads:[~2013-03-30 9:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-30 9:53 Torsten Bögershausen [this message]
2013-04-03 3:55 ` [PATCH 2/2] optimize adjust_shared_perm() in path.c: Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201303301053.49140.tboegi@web.de \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=kusmabite@gmail.com \
--cc=mlevedahl@gmail.com \
--cc=ramsay@ramsay1.demon.co.uk \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).