{"thread":{"id":"33638","subject":"[PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","startedAt":"2013-04-27T18:42:01Z","lastAt":"2013-04-30T17:00:02Z","messageCount":8,"participants":["Ramsay Jones","Eric Sunshine","Torsten Bögershausen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"215722","messageId":"517C1BF9.2050604@ramsay1.demon.co.uk","threadId":"33638","inReplyTo":null,"subject":"[PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-04-27T18:42:01Z","receivedAt":"2013-04-27T18:42:01Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nOn MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\nit be static?\" warning. The MinGW and MSVC builds do not see the\ndeclaration of this function, within git-compat-util.h, due to it's\nplacement within an preprocessor conditional. (So, one solution would\nbe to simply move the declaration to the top level of the header.)\n\nIn order to suppress the warning, since this symbol does not need\nmore than file visibility, we simply remove the declaration from\nthe header and add the static modifier to the function definition.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n git-compat-util.h | 1 -\n path.c            | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e955bb5..3a990b3 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -163,7 +163,6 @@\n typedef long intptr_t;\n typedef unsigned long uintptr_t;\n #endif\n-int get_st_mode_bits(const char *path, int *mode);\n #if defined(__CYGWIN__)\n #undef _XOPEN_SOURCE\n #include <grp.h>\ndiff --git a/path.c b/path.c\nindex 04ff148..cc2e9ac 100644\n--- a/path.c\n+++ b/path.c\n@@ -11,7 +11,7 @@\n  * may return wrong permission bits. Most of the time we do not care,\n  * but the callsites of this wrapper do care.\n  */\n-int get_st_mode_bits(const char *path, int *mode)\n+static int get_st_mode_bits(const char *path, int *mode)\n {\n \tstruct stat st;\n \tif (lstat(path, &st) < 0)\n-- \n1.8.2\n"},{"id":"215783","messageId":"CAPig+cS0dwm_aHCx6zUCCKnrWk1WXMaO54FOKtkwXXftDLr=og@mail.gmail.com","threadId":"33638","inReplyTo":"517C1BF9.2050604@ramsay1.demon.co.uk","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-04-28T02:26:23Z","receivedAt":"2013-04-28T02:26:23Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Apr 27, 2013 at 2:42 PM, Ramsay Jones\n<ramsay@ramsay1.demon.co.uk> wrote:\n>\n> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n> it be static?\" warning. The MinGW and MSVC builds do not see the\n> declaration of this function, within git-compat-util.h, due to it's\n\ns/it's/its/\n\n> placement within an preprocessor conditional. (So, one solution would\n> be to simply move the declaration to the top level of the header.)\n>\n> In order to suppress the warning, since this symbol does not need\n> more than file visibility, we simply remove the declaration from\n> the header and add the static modifier to the function definition.\n>\n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n"},{"id":"215784","messageId":"517CBB6E.205@web.de","threadId":"33638","inReplyTo":"517C1BF9.2050604@ramsay1.demon.co.uk","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-04-28T06:02:22Z","receivedAt":"2013-04-28T06:02:22Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2013-04-27 20.42, Ramsay Jones wrote:\n> \n> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n> it be static?\" warning. The MinGW and MSVC builds do not see the\n> declaration of this function, within git-compat-util.h, due to it's\n> placement within an preprocessor conditional. (So, one solution would\n> be to simply move the declaration to the top level of the header.)\n> \n> In order to suppress the warning, since this symbol does not need\n> more than file visibility, we simply remove the declaration from\n> the header and add the static modifier to the function definition.\n> \n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n> ---\n>  git-compat-util.h | 1 -\n>  path.c            | 2 +-\n>  2 files changed, 1 insertion(+), 2 deletions(-)\n> \n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index e955bb5..3a990b3 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -163,7 +163,6 @@\n>  typedef long intptr_t;\n>  typedef unsigned long uintptr_t;\n>  #endif\n> -int get_st_mode_bits(const char *path, int *mode);\n>  #if defined(__CYGWIN__)\n>  #undef _XOPEN_SOURCE\n>  #include <grp.h>\n> diff --git a/path.c b/path.c\n> index 04ff148..cc2e9ac 100644\n> --- a/path.c\n> +++ b/path.c\n> @@ -11,7 +11,7 @@\n>   * may return wrong permission bits. Most of the time we do not care,\n>   * but the callsites of this wrapper do care.\n>   */\n> -int get_st_mode_bits(const char *path, int *mode)\n> +static int get_st_mode_bits(const char *path, int *mode)\n>  {\n>  \tstruct stat st;\n>  \tif (lstat(path, &st) < 0)\n> \nSorry for breaking the MiNGW/MSVC builds.\nIt seams that the get_st_mode_bits is badly placed.\n\nIt should be in git compat-util.h, so that both compat/cygwin.c and path.c can see it.\nSo from my understanding, it should be placed here:\n(I will send an official patch later)\n/Torsten\n \n\ndiff -C 3 git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ git-compat-util.h.new\n*** git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ 2013-04-28 07:53:28.000000000 +0200\n--- git-compat-util.h.new       2013-04-28 07:53:58.000000000 +0200\n***************\n*** 127,132 ****\n--- 127,133 ----\n  #else\n  #include <poll.h>\n  #endif\n+ int get_st_mode_bits(const char *path, int *mode);\n  #if defined(__MINGW32__)\n  /* pull in Windows compatibility stuff */\n  #include \"compat/mingw.h\"\n***************\n*** 163,169 ****\n  typedef long intptr_t;\n  typedef unsigned long uintptr_t;\n  #endif\n- int get_st_mode_bits(const char *path, int *mode);\n  #if defined(__CYGWIN__)\n  #undef _XOPEN_SOURCE\n  #include <grp.h>\n"},{"id":"215791","messageId":"517D08BA.6060508@web.de","threadId":"33638","inReplyTo":"517CBB6E.205@web.de","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-04-28T11:32:10Z","receivedAt":"2013-04-28T11:32:10Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2013-04-28 08.02, Torsten Bögershausen wrote:\n> On 2013-04-27 20.42, Ramsay Jones wrote:\n>>\n>> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n>> it be static?\" warning. The MinGW and MSVC builds do not see the\n>> declaration of this function, within git-compat-util.h, due to it's\n>> placement within an preprocessor conditional. (So, one solution would\n>> be to simply move the declaration to the top level of the header.)\n>>\n>> In order to suppress the warning, since this symbol does not need\n>> more than file visibility, we simply remove the declaration from\n>> the header and add the static modifier to the function definition.\n>>\n>> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n>> ---\n>>  git-compat-util.h | 1 -\n>>  path.c            | 2 +-\n>>  2 files changed, 1 insertion(+), 2 deletions(-)\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index e955bb5..3a990b3 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -163,7 +163,6 @@\n>>  typedef long intptr_t;\n>>  typedef unsigned long uintptr_t;\n>>  #endif\n>> -int get_st_mode_bits(const char *path, int *mode);\n>>  #if defined(__CYGWIN__)\n>>  #undef _XOPEN_SOURCE\n>>  #include <grp.h>\n>> diff --git a/path.c b/path.c\n>> index 04ff148..cc2e9ac 100644\n>> --- a/path.c\n>> +++ b/path.c\n>> @@ -11,7 +11,7 @@\n>>   * may return wrong permission bits. Most of the time we do not care,\n>>   * but the callsites of this wrapper do care.\n>>   */\n>> -int get_st_mode_bits(const char *path, int *mode)\n>> +static int get_st_mode_bits(const char *path, int *mode)\n>>  {\n>>  \tstruct stat st;\n>>  \tif (lstat(path, &st) < 0)\n>>\n> Sorry for breaking the MiNGW/MSVC builds.\n> It seams that the get_st_mode_bits is badly placed.\n> \n> It should be in git compat-util.h, so that both compat/cygwin.c and path.c can see it.\n> So from my understanding, it should be placed here:\n> (I will send an official patch later)\n> /Torsten\n>  \n> \n> diff -C 3 git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ git-compat-util.h.new\n> *** git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ 2013-04-28 07:53:28.000000000 +0200\n> --- git-compat-util.h.new       2013-04-28 07:53:58.000000000 +0200\n> ***************\n> *** 127,132 ****\n> --- 127,133 ----\n>   #else\n>   #include <poll.h>\n>   #endif\n> + int get_st_mode_bits(const char *path, int *mode);\n>   #if defined(__MINGW32__)\n>   /* pull in Windows compatibility stuff */\n>   #include \"compat/mingw.h\"\n> ***************\n> *** 163,169 ****\n>   typedef long intptr_t;\n>   typedef unsigned long uintptr_t;\n>   #endif\n> - int get_st_mode_bits(const char *path, int *mode);\n>   #if defined(__CYGWIN__)\n>   #undef _XOPEN_SOURCE\n>   #include <grp.h>\n\nI probably change my mind:\n  Declaring get_st_mode_bits() static in path.c makes sense.\n\n  And for cygwin we have the re-define in compat/cygwin.h:\n  int cygwin_get_st_mode_bits(const char *path, int *mode);\n  #define get_st_mode_bits(p,m) cygwin_get_st_mode_bits((p),(m))\n\nSo, (besides the typo found by Eric),\nThanks. Reviewed,and tested OK here. In short:\n\nAcked-By: Torsten Bögershausen <tboegi@web.de>\n"},{"id":"215799","messageId":"7vip36qxui.fsf@alter.siamese.dyndns.org","threadId":"33638","inReplyTo":"517C1BF9.2050604@ramsay1.demon.co.uk","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-28T19:06:13Z","receivedAt":"2013-04-28T19:06:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n\n> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n> it be static?\" warning. The MinGW and MSVC builds do not see the\n> declaration of this function, within git-compat-util.h, due to it's\n> placement within an preprocessor conditional. (So, one solution would\n> be to simply move the declaration to the top level of the header.)\n\nWell, the idea was that the user of this function in path.c will\ncall get_st_mode_bits(), and whatever platform that provides a\nreplacement implementation would do\n\n\t#define get_st_mode_bits(a,b) cygwin_get_st_mode_bits((a),(b))\n\nso that the calling site in path.c will end up calling that\nreplacement implementation.  So if anything get_st_mode_bits()\ndeclaration may want to go at the _end_ (not top) after including\nall the compatibility crufts.\n\nWe could make the declaration static to path.c, but then nobody\nother than path.c would be able to make use of it in the future,\nand we'll have the same discussion when somebody wants to hoist the\ndeclaration to git-compat-util.h, no?\n"},{"id":"215937","messageId":"517EECD4.800@ramsay1.demon.co.uk","threadId":"33638","inReplyTo":"517CBB6E.205@web.de","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-04-29T21:57:40Z","receivedAt":"2013-04-29T21:57:40Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Torsten Bögershausen wrote:\n> On 2013-04-27 20.42, Ramsay Jones wrote:\n>>\n>> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n>> it be static?\" warning. The MinGW and MSVC builds do not see the\n>> declaration of this function, within git-compat-util.h, due to it's\n>> placement within an preprocessor conditional. (So, one solution would\n>> be to simply move the declaration to the top level of the header.)\n>>\n>> In order to suppress the warning, since this symbol does not need\n>> more than file visibility, we simply remove the declaration from\n>> the header and add the static modifier to the function definition.\n>>\n>> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n>> ---\n>>  git-compat-util.h | 1 -\n>>  path.c            | 2 +-\n>>  2 files changed, 1 insertion(+), 2 deletions(-)\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index e955bb5..3a990b3 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -163,7 +163,6 @@\n>>  typedef long intptr_t;\n>>  typedef unsigned long uintptr_t;\n>>  #endif\n>> -int get_st_mode_bits(const char *path, int *mode);\n>>  #if defined(__CYGWIN__)\n>>  #undef _XOPEN_SOURCE\n>>  #include <grp.h>\n>> diff --git a/path.c b/path.c\n>> index 04ff148..cc2e9ac 100644\n>> --- a/path.c\n>> +++ b/path.c\n>> @@ -11,7 +11,7 @@\n>>   * may return wrong permission bits. Most of the time we do not care,\n>>   * but the callsites of this wrapper do care.\n>>   */\n>> -int get_st_mode_bits(const char *path, int *mode)\n>> +static int get_st_mode_bits(const char *path, int *mode)\n>>  {\n>>  \tstruct stat st;\n>>  \tif (lstat(path, &st) < 0)\n>>\n> Sorry for breaking the MiNGW/MSVC builds.\n> It seams that the get_st_mode_bits is badly placed.\n\nYou didn't break the build; simply provoked a warning.\n\nAs I said in the commit message, an alternative is to\nsimply move the declaration to the top level of the\nheader (out of the preprocessor conditional).\n\nATB,\nRamsay Jones\n"},{"id":"215935","messageId":"517EF9D4.50105@ramsay1.demon.co.uk","threadId":"33638","inReplyTo":"7vip36qxui.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-04-29T22:53:08Z","receivedAt":"2013-04-29T22:53:08Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Junio C Hamano wrote:\n> Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n> \n>> On MinGW, sparse issues an \"'get_st_mode_bits' not declared. Should\n>> it be static?\" warning. The MinGW and MSVC builds do not see the\n>> declaration of this function, within git-compat-util.h, due to it's\n>> placement within an preprocessor conditional. (So, one solution would\n>> be to simply move the declaration to the top level of the header.)\n> \n> Well, the idea was that the user of this function in path.c will\n> call get_st_mode_bits(), and whatever platform that provides a\n> replacement implementation would do\n> \n> \t#define get_st_mode_bits(a,b) cygwin_get_st_mode_bits((a),(b))\n> \n> so that the calling site in path.c will end up calling that\n> replacement implementation.  So if anything get_st_mode_bits()\n> declaration may want to go at the _end_ (not top) after including\n> all the compatibility crufts.\n> \n> We could make the declaration static to path.c, but then nobody\n> other than path.c would be able to make use of it in the future,\n> and we'll have the same discussion when somebody wants to hoist the\n> declaration to git-compat-util.h, no?\n\nI don't have a problem with keeping the declaration in git-compat-util.h\n(after moving it so that the MinGW and MSVC builds can see it, of course)\nif you would rather do that.\n\nHowever, I'm always a little wary when I hear someone say \"this may be\nuseful to others in the future, so lets do X to make it easier ...\".\nI have noticed that, much more often than not, that future user never\ndoes materialise ... ;-)\n\nHaving said that ...\n\nBack in 2011, when I was trying to fix t7606-merge-custom.sh (see\ncommit b8a9733377, \"help.c: Fix detection of custom merge strategy\non cygwin\", 16-06-2011), I had a patch that looked very similar to\nthe solution Torsten has arrived at here! (The main difference was\nthat I called stat() rather than lstat() to get the mode bits).\n\nI decided to go with the simpler solution in commit b8a9733377.\n\nATB,\nRamsay Jones\n"},{"id":"216003","messageId":"7v1u9seyy5.fsf@alter.siamese.dyndns.org","threadId":"33638","inReplyTo":"517EF9D4.50105@ramsay1.demon.co.uk","subject":"Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-30T17:00:02Z","receivedAt":"2013-04-30T17:00:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:\n\n> However, I'm always a little wary when I hear someone say \"this may be\n> useful to others in the future, so lets do X to make it easier ...\".\n> I have noticed that, much more often than not, that future user never\n> does materialise ... ;-)\n\nI do not think you are reading the reason for the function\ncorrectly.  It is not \"We may find it useful elsewhere\".\n\nIt is \"We knew Windows benefits from having a 'quick, incorrect, but\nthe incorrectness happens not matter to the caller' hack, and we\nused to use it everywhere.  But we identified one location we need\nto disable the hack for correctness, hence this 'slow-but-correct'\nfunction.  There may still be other places that needs fixing by\ncalling it\".\n"}]}