{"thread":{"id":"43520","subject":"[PATCH] sanitize --abbrev option for describe","startedAt":"2006-11-02T01:15:30Z","lastAt":"2006-11-02T01:15:30Z","messageCount":1,"participants":["Han-Wen Nienhuys"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"295255","messageId":"eibgqu$rsh$1@sea.gmane.org","threadId":"43520","inReplyTo":null,"subject":"[PATCH] sanitize --abbrev option for describe","fromName":"Han-Wen Nienhuys","fromEmail":"hanwen@xs4all.nl","sentAt":"2006-11-02T01:15:30Z","receivedAt":"2006-11-02T01:15:30Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"\nHi,\n\nthe --abbrev option doesn't allow a 40 digit SHA1 output.\n\nThe following patch fixes this, and uses a IMHO more logical way to \ncompute the abbrev parameter, so --abbrev=52 will still yield a 40 digit \nSHA1.\n\n\n-- \n  Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n\n\ncommit 62ab49fb3a050cb2a4c96fa0ab8064742544369b\nAuthor: Han-Wen Nienhuys <hanwen@lilypond.org>\nDate:   Thu Nov 2 02:12:11 2006 +0100\n\n    use constant variable for storing \"--abbrev=\".  Use 40 and\n    MINIMUM_ABBREV as bounds for --abbrev= argument.\n\ndiff --git a/describe.c b/describe.c\nindex ab192f8..973520c 100644\n--- a/describe.c\n+++ b/describe.c\n@@ -141,6 +141,7 @@ static void describe(const char *arg, in\n \n int main(int argc, char **argv)\n {\n+\tchar const *abbrev_option = \"--abbrev=\";\n \tint i;\n \n \tfor (i = 1; i < argc; i++) {\n@@ -152,10 +153,10 @@ int main(int argc, char **argv)\n \t\t\tall = 1;\n \t\telse if (!strcmp(arg, \"--tags\"))\n \t\t\ttags = 1;\n-\t\telse if (!strncmp(arg, \"--abbrev=\", 9)) {\n-\t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n-\t\t\tif (abbrev < MINIMUM_ABBREV || 40 < abbrev)\n-\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\telse if (!strncmp(arg, abbrev_option, strlen (abbrev_option))) {\n+\t\t\tabbrev = strtoul(arg + strlen (abbrev_option), NULL, 10);\n+\t\t\tabbrev = MAX(MINIMUM_ABBREV, abbrev);\n+\t\t\tabbrev = MIN(40, abbrev);\n \t\t}\n \t\telse\n \t\t\tusage(describe_usage);\n"}]}