{"thread":{"id":"36218","subject":"[PATCH] diff-no-index.c: rewrote read_directory() to use is_dot_or_dotdot() function.","startedAt":"2014-03-19T08:31:50Z","lastAt":"2014-03-19T09:51:39Z","messageCount":2,"participants":["Andrei Dinu","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"237047","messageId":"1395217910-7506-1-git-send-email-mandrei.dinu@gmail.com","threadId":"36218","inReplyTo":null,"subject":"[PATCH] diff-no-index.c: rewrote read_directory() to use is_dot_or_dotdot() function.","fromName":"Andrei Dinu","fromEmail":"mandrei.dinu@gmail.com","sentAt":"2014-03-19T08:31:50Z","receivedAt":"2014-03-19T08:31:50Z","isPatch":true,"sender":{"key":"mandrei.dinu@gmail.com","avatar":null},"body":"is_dot_or_dotdot() verifies if the name of the directory sent as parameter to this function is the same with '.' or '..' and returns 0 if that is true.\n\nThere is unnecessary to iterate each character of the char* argument and verify it with strcmp because if there is a match that is at the beginning of chars.\n\nSigned-off-by: Andrei Dinu <mandrei.dinu@gmail.com>\n\nI plan on applying to GSoc 2014\n---\n diff-no-index.c |   11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 8e10bff..83cdbf7 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -16,6 +16,15 @@\n #include \"builtin.h\"\n #include \"string-list.h\"\n \n+static int is_dot_or_dotdot(const char *path)\n+{\n+    if (path[0] == '.' && path[1] == '\\0')\n+        return 0;\n+    else if (path[0] == '.' && path[1] == '.' && path[2] == '\\0')\n+        return 0;\n+    return 1;\n+}\n+\n static int read_directory(const char *path, struct string_list *list)\n {\n \tDIR *dir;\n@@ -25,7 +34,7 @@ static int read_directory(const char *path, struct string_list *list)\n \t\treturn error(\"Could not open directory %s\", path);\n \n \twhile ((e = readdir(dir)))\n-\t\tif (strcmp(\".\", e->d_name) && strcmp(\"..\", e->d_name))\n+\t\tif (is_dot_or_dotdot(e->d_name))\n \t\t\tstring_list_insert(list, e->d_name);\n \n \tclosedir(dir);\n-- \n1.7.9.5\n"},{"id":"237053","messageId":"CAPig+cQynpEEg6NU08FX1ZHGGwU+xVDyUYEVNx9vogh6L1_QzA@mail.gmail.com","threadId":"36218","inReplyTo":"1395217910-7506-1-git-send-email-mandrei.dinu@gmail.com","subject":"Re: [PATCH] diff-no-index.c: rewrote read_directory() to use is_dot_or_dotdot() function.","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-19T09:51:39Z","receivedAt":"2014-03-19T09:51:39Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"Thanks for the submission. Comments below to give you a taste of the\nGit review process...\n\nOn Wed, Mar 19, 2014 at 4:31 AM, Andrei Dinu <mandrei.dinu@gmail.com> wrote:\n> Subject: diff-no-index.c: rewrote read_directory() to use is_dot_or_dotdot() function.\n\nUse imperative tone: \"rewrite\" instead of \"rewrote\". The subject is a\nbit long. Try to keep it to 65-70 characters. You might instead say:\n\n    diff-no-index: replace manual \".\"/\"..\" check with is_dot_or_dotdot()\n\n> is_dot_or_dotdot() verifies if the name of the directory sent as parameter to this function is the same with '.' or '..' and returns 0 if that is true.\n\nWrap commit message to 65-70 characters.\n\n> There is unnecessary to iterate each character of the char* argument and verify it with strcmp because if there is a match that is at the beginning of chars.\n\nYou may be able to drop most or all of this text. A subject such as\nthe one suggested above probably conveys enough information to explain\nand justify the patch without having to say anything more.\n\n> Signed-off-by: Andrei Dinu <mandrei.dinu@gmail.com>\n>\n> I plan on applying to GSoc 2014\n\nThis commentary about GSoC won't be interesting to people reading the\ncommit message months or years from now, so place it after the \"---\"\nline just below.\n\n> ---\n>  diff-no-index.c |   11 ++++++++++-\n>  1 file changed, 10 insertions(+), 1 deletion(-)\n>\n> diff --git a/diff-no-index.c b/diff-no-index.c\n> index 8e10bff..83cdbf7 100644\n> --- a/diff-no-index.c\n> +++ b/diff-no-index.c\n> @@ -16,6 +16,15 @@\n>  #include \"builtin.h\"\n>  #include \"string-list.h\"\n>\n> +static int is_dot_or_dotdot(const char *path)\n> +{\n> +    if (path[0] == '.' && path[1] == '\\0')\n> +        return 0;\n> +    else if (path[0] == '.' && path[1] == '.' && path[2] == '\\0')\n> +        return 0;\n> +    return 1;\n> +}\n\nGit already defines an is_dot_or_dotdot() function. Is there a reason\nyou chose to implement your own?\n\nIt is very unusual for a function asking \"is this true\" to return\nfalse when the condition is true, and vice versa. It is not a good\nidea to break expectations in this fashion.\n\n>  static int read_directory(const char *path, struct string_list *list)\n>  {\n>         DIR *dir;\n> @@ -25,7 +34,7 @@ static int read_directory(const char *path, struct string_list *list)\n>                 return error(\"Could not open directory %s\", path);\n>\n>         while ((e = readdir(dir)))\n> -               if (strcmp(\".\", e->d_name) && strcmp(\"..\", e->d_name))\n> +               if (is_dot_or_dotdot(e->d_name))\n>                         string_list_insert(list, e->d_name);\n>\n>         closedir(dir);\n> --\n> 1.7.9.5\n"}]}