{"thread":{"id":"6166","subject":"[PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","startedAt":"2006-12-31T03:13:05Z","lastAt":"2006-12-31T06:48:39Z","messageCount":8,"participants":["Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"30542","messageId":"20061231031305.GA5620@spearce.org","threadId":"6166","inReplyTo":null,"subject":"[PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T03:13:05Z","receivedAt":"2006-12-31T03:13:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sometimes its necessary to supply a value as a power of two in a\nconfiguration parameter.  In this case the user may want to use the\nstandard suffixes such as K, M, or G to indicate that the numerical\nvalue should be multiplied by a constant base before being used.\n\nShell scripts/etc. can also benefit from this automatic option\nparsing with `git repo-config --int`.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n This is a resend of the prior version of this patch.  Junio\n convinced me on #git that this version might be better.  :-)\n\n Meant for the top of sp/mmap, but may be useful elsewhere.\n\n Documentation/git-repo-config.txt |    5 ++++-\n config.c                          |    8 ++++++++\n 2 files changed, 12 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt\nindex b379ec5..c55a8ba 100644\n--- a/Documentation/git-repo-config.txt\n+++ b/Documentation/git-repo-config.txt\n@@ -87,7 +87,10 @@ OPTIONS\n \tgit-repo-config will ensure that the output is \"true\" or \"false\"\n \n --int::\n-\tgit-repo-config will ensure that the output is a simple decimal number\n+\tgit-repo-config will ensure that the output is a simple\n+\tdecimal number.  An optional value suffix of 'k', 'm', or 'g'\n+\tin the config file will cause the value to be multiplied\n+\tby 1024, 1048576, or 1073741824 prior to output.\n \n \n ENVIRONMENT\ndiff --git a/config.c b/config.c\nindex 2e0d5a8..83ce9e1 100644\n--- a/config.c\n+++ b/config.c\n@@ -236,8 +236,16 @@ int git_config_int(const char *name, const char *value)\n \tif (value && *value) {\n \t\tchar *end;\n \t\tint val = strtol(value, &end, 0);\n+\t\twhile (isspace(*end))\n+\t\t\tend++;\n \t\tif (!*end)\n \t\t\treturn val;\n+\t\tif (!strcasecmp(end, \"k\"))\n+\t\t\treturn val * 1024;\n+\t\tif (!strcasecmp(end, \"m\"))\n+\t\t\treturn val * 1024 * 1024;\n+\t\tif (!strcasecmp(end, \"g\"))\n+\t\t\treturn val * 1024 * 1024 * 1024;\n \t}\n \tdie(\"bad config value for '%s' in %s\", name, config_file_name);\n }\n-- \n1.5.0.rc0.g6bb1\n"},{"id":"30558","messageId":"7vy7ooip6y.fsf@assigned-by-dhcp.cox.net","threadId":"6166","inReplyTo":"20061231031305.GA5620@spearce.org","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-31T05:56:05Z","receivedAt":"2006-12-31T05:56:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt\n> index b379ec5..c55a8ba 100644\n> --- a/Documentation/git-repo-config.txt\n> +++ b/Documentation/git-repo-config.txt\n> @@ -87,7 +87,10 @@ OPTIONS\n>  \tgit-repo-config will ensure that the output is \"true\" or \"false\"\n>  \n>  --int::\n> -\tgit-repo-config will ensure that the output is a simple decimal number\n> +\tgit-repo-config will ensure that the output is a simple\n> +\tdecimal number.  An optional value suffix of 'k', 'm', or 'g'\n> +\tin the config file will cause the value to be multiplied\n> +\tby 1024, 1048576, or 1073741824 prior to output.\n\nThanks.  I think this is applicable on top of 'master'.\n\n>  ENVIRONMENT\n> diff --git a/config.c b/config.c\n> index 2e0d5a8..83ce9e1 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -236,8 +236,16 @@ int git_config_int(const char *name, const char *value)\n>  \tif (value && *value) {\n>  \t\tchar *end;\n>  \t\tint val = strtol(value, &end, 0);\n> +\t\twhile (isspace(*end))\n> +\t\t\tend++;\n\nWhy?  Are you allowing \"1024 k\"?  Do we want to?\n\n>  \t\tif (!*end)\n>  \t\t\treturn val;\n> +\t\tif (!strcasecmp(end, \"k\"))\n> +\t\t\treturn val * 1024;\n> +\t\tif (!strcasecmp(end, \"m\"))\n> +\t\t\treturn val * 1024 * 1024;\n> +\t\tif (!strcasecmp(end, \"g\"))\n> +\t\t\treturn val * 1024 * 1024 * 1024;\n>  \t}\n>  \tdie(\"bad config value for '%s' in %s\", name, config_file_name);\n>  }\n> -- \n> 1.5.0.rc0.g6bb1\n"},{"id":"30561","messageId":"20061231061232.GC6106@spearce.org","threadId":"6166","inReplyTo":"7vy7ooip6y.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T06:12:32Z","receivedAt":"2006-12-31T06:12:32Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> > diff --git a/config.c b/config.c\n> > index 2e0d5a8..83ce9e1 100644\n> > --- a/config.c\n> > +++ b/config.c\n> > @@ -236,8 +236,16 @@ int git_config_int(const char *name, const char *value)\n> >  \tif (value && *value) {\n> >  \t\tchar *end;\n> >  \t\tint val = strtol(value, &end, 0);\n> > +\t\twhile (isspace(*end))\n> > +\t\t\tend++;\n> \n> Why?  Are you allowing \"1024 k\"?  Do we want to?\n\nYes.  Why not?\n\n-- \nShawn.\n"},{"id":"30562","messageId":"7vpsa0inwr.fsf@assigned-by-dhcp.cox.net","threadId":"6166","inReplyTo":"20061231061232.GC6106@spearce.org","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-31T06:23:48Z","receivedAt":"2006-12-31T06:23:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>\n>> Why?  Are you allowing \"1024 k\"?  Do we want to?\n>\n> Yes.  Why not?\n\nStricter input checking.  Allowing extra things later is far\neasier than later finding problems with a looser way we started\nfrom and having to tighten it.\n"},{"id":"30563","messageId":"20061231062618.GD6106@spearce.org","threadId":"6166","inReplyTo":"7vpsa0inwr.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T06:26:18Z","receivedAt":"2006-12-31T06:26:18Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \n> > Junio C Hamano <junkio@cox.net> wrote:\n> >\n> >> Why?  Are you allowing \"1024 k\"?  Do we want to?\n> >\n> > Yes.  Why not?\n> \n> Stricter input checking.  Allowing extra things later is far\n> easier than later finding problems with a looser way we started\n> from and having to tighten it.\n\nGood point.  I'm currently writing tests for this btw.\n\n-- \nShawn.\n"},{"id":"30564","messageId":"7vlkkoinla.fsf@assigned-by-dhcp.cox.net","threadId":"6166","inReplyTo":"20061231062618.GD6106@spearce.org","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-31T06:30:41Z","receivedAt":"2006-12-31T06:30:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>> \n>> > Junio C Hamano <junkio@cox.net> wrote:\n>> >\n>> >> Why?  Are you allowing \"1024 k\"?  Do we want to?\n>> >\n>> > Yes.  Why not?\n>> \n>> Stricter input checking.  Allowing extra things later is far\n>> easier than later finding problems with a looser way we started\n>> from and having to tighten it.\n>\n> Good point.  I'm currently writing tests for this btw.\n\nI have this already in the private 'master' I am prepareing for\npushout:\n\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex e48a4ec..a29caa0 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -391,5 +391,15 @@ EOF\n \n test_expect_success \"rename succeeded\" \"diff -u expect .git/config\"\n \n+test_expect_success numbers '\n+\n+\tgit-repo-config kilo.gram 1k &&\n+\tgit-repo-config mega.ton 1m &&\n+\tk=$(git-repo-config --int --get kilo.gram) &&\n+\ttest z1024 = \"z$k\" &&\n+\tm=$(git-repo-config --int --get mega.ton) &&\n+\ttest z1048576 = \"z$m\"\n+'\n+\n test_done\n \n-- \n1.5.0.rc0.g81760\n"},{"id":"30565","messageId":"20061231063625.GE6106@spearce.org","threadId":"6166","inReplyTo":"7vlkkoinla.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T06:36:25Z","receivedAt":"2006-12-31T06:36:25Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> I have this already in the private 'master' I am prepareing for\n> pushout:\n\nDoes it pass?  I can't get something similar to work here...\nI must be a moron or something.\n \n\n-- \nShawn.\n"},{"id":"30566","messageId":"20061231064839.GF6106@spearce.org","threadId":"6166","inReplyTo":"7vlkkoinla.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Teach Git how to parse standard power of 2 suffixes.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T06:48:39Z","receivedAt":"2006-12-31T06:48:39Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> +test_expect_success numbers '\n> +\n> +\tgit-repo-config kilo.gram 1k &&\n> +\tgit-repo-config mega.ton 1m &&\n> +\tk=$(git-repo-config --int --get kilo.gram) &&\n> +\ttest z1024 = \"z$k\" &&\n> +\tm=$(git-repo-config --int --get mega.ton) &&\n> +\ttest z1048576 = \"z$m\"\n> +'\n> +\n\nI'm a moron.  I copied and pasted test_expect_failure here in my\nown version.  Commit and push yours, its just as good as mine,\nbut is shorter.  :-)\n\n-- \nShawn.\n"}]}