{"thread":{"id":"33333","subject":"[PATCH 2/2] optimize adjust_shared_perm() in path.c:","startedAt":"2013-03-30T09:53:47Z","lastAt":"2013-04-03T03:55:24Z","messageCount":2,"participants":["Torsten Bögershausen","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"212697","messageId":"201303301053.49140.tboegi@web.de","threadId":"33333","inReplyTo":null,"subject":"[PATCH 2/2] optimize adjust_shared_perm() in path.c:","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-03-30T09:53:47Z","receivedAt":"2013-03-30T09:53:47Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"sometimes the chown() function is called even when not needed.\n(This can be provoced by running t1301, and adding some debug code)\n\nSave a chmod from 400 to 400, or from 600->600 on these files:\n .git/info/refs+\n .git/objects/info/packs+\n\nSave chmod on directories from 2770 to 2770:\n .git/refs\n .git/refs/heads\n .git/refs/tags\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n path.c | 42 +++++++++++++++++++++++-------------------\n 1 file changed, 23 insertions(+), 19 deletions(-)\n\ndiff --git a/path.c b/path.c\nindex 427312e..33fa880 100644\n--- a/path.c\n+++ b/path.c\n@@ -396,22 +396,14 @@ const char *enter_repo(const char *path, int strict)\n \treturn NULL;\n }\n \n-int adjust_shared_perm(const char *path)\n+static int calc_shared_perm(int mode)\n {\n-\tint tweak, shared, orig_mode, mode;\n+\tint tweak;\n \n-\tif (!shared_repository) {\n-\t\treturn 0;\n-\t}\n-\tif (get_st_mode_bits(path, &mode) < 0)\n-\t\treturn -1;\n-\n-\torig_mode = mode;\n \tif (shared_repository < 0)\n-\t\tshared = -shared_repository;\n+\t\ttweak = -shared_repository;\n \telse\n-\t\tshared = shared_repository;\n-\ttweak = shared;\n+\t\ttweak = shared_repository;\n \n \tif (!(mode & S_IWUSR))\n \t\ttweak &= ~0222;\n@@ -423,16 +415,28 @@ int adjust_shared_perm(const char *path)\n \telse\n \t\tmode |= tweak;\n \n-\tif (S_ISDIR(mode)) {\n+\treturn mode;\n+}\n+\n+\n+int adjust_shared_perm(const char *path)\n+{\n+\tint old_mode, new_mode;\n+\n+\tif (!shared_repository)\n+\t\treturn 0;\n+\tif (get_st_mode_bits(path, &old_mode) < 0)\n+\t\treturn -1;\n+\n+\tnew_mode = calc_shared_perm(old_mode);\n+\tif (S_ISDIR(old_mode)) {\n \t\t/* Copy read bits to execute bits */\n-\t\tmode |= (shared & 0444) >> 2;\n-\t\tmode |= FORCE_DIR_SET_GID;\n+\t\tnew_mode |= (new_mode & 0444) >> 2;\n+\t\tnew_mode |= FORCE_DIR_SET_GID;\n \t}\n \n-\tif (((shared_repository < 0\n-\t      ? (orig_mode & (FORCE_DIR_SET_GID | 0777))\n-\t      : (orig_mode & mode)) != mode) &&\n-\t    chmod(path, (mode & ~S_IFMT)) < 0)\n+\tif (((old_mode ^ new_mode) & ~S_IFMT) &&\n+\t\t\tchmod(path, (new_mode & ~S_IFMT)) < 0)\n \t\treturn -2;\n \treturn 0;\n }\n-- \n1.8.2.341.g543621f\n"},{"id":"213019","messageId":"CAPig+cT1quUK52hXnQE6-jVTMi7GUjtgL9njmRvNe6+mPNNvUg@mail.gmail.com","threadId":"33333","inReplyTo":"201303301053.49140.tboegi@web.de","subject":"Re: [PATCH 2/2] optimize adjust_shared_perm() in path.c:","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-04-03T03:55:24Z","receivedAt":"2013-04-03T03:55:24Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Mar 30, 2013 at 5:53 AM, Torsten Bögershausen <tboegi@web.de> wrote:\n> sometimes the chown() function is called even when not needed.\n> (This can be provoced by running t1301, and adding some debug code)\n\ns/provoced/provoked/\n\n> Save a chmod from 400 to 400, or from 600->600 on these files:\n>  .git/info/refs+\n>  .git/objects/info/packs+\n>\n> Save chmod on directories from 2770 to 2770:\n>  .git/refs\n>  .git/refs/heads\n>  .git/refs/tags\n"}]}