{"thread":{"id":"45524","subject":"[PATCH] [GSOC] get_non_kept_pack_filenames(): reimplement using iterators","startedAt":"2017-03-28T01:40:49Z","lastAt":"2017-03-28T18:23:31Z","messageCount":2,"participants":["Robert Stanca","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"315550","messageId":"1490665185-11809-1-git-send-email-robert.stanca7@gmail.com","threadId":"45524","inReplyTo":null,"subject":"[PATCH] [GSOC] get_non_kept_pack_filenames(): reimplement using iterators","fromName":"Robert Stanca","fromEmail":"robert.stanca7@gmail.com","sentAt":"2017-03-28T01:39:45Z","receivedAt":"2017-03-28T01:40:49Z","isPatch":true,"sender":{"key":"robert.stanca7@gmail.com","avatar":null},"body":"Replaces recursive traversing of opendir with dir_iterator.\n\nSigned-off-by: Robert Stanca <robert.stanca7@gmail.com>\n---\n builtin/repack.c | 15 ++++++---------\n 1 file changed, 6 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 677bc7c..27a5597 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -7,6 +7,8 @@\n #include \"strbuf.h\"\n #include \"string-list.h\"\n #include \"argv-array.h\"\n+#include \"iterator.h\"\n+#include \"dir-iterator.h\"\n \n static int delta_base_offset = 1;\n static int pack_kept_objects = -1;\n@@ -86,26 +88,21 @@ static void remove_pack_on_signal(int signo)\n  */\n static void get_non_kept_pack_filenames(struct string_list *fname_list)\n {\n-\tDIR *dir;\n-\tstruct dirent *e;\n+\tstruct dir_iterator *diter = dir_iterator_begin(packdir);\n \tchar *fname;\n \n-\tif (!(dir = opendir(packdir)))\n-\t\treturn;\n-\n-\twhile ((e = readdir(dir)) != NULL) {\n+\twhile (dir_iterator_advance(diter) == ITER_OK) {\n \t\tsize_t len;\n-\t\tif (!strip_suffix(e->d_name, \".pack\", &len))\n+\t\tif (!strip_suffix(diter->relative_path, \".pack\", &len))\n \t\t\tcontinue;\n \n-\t\tfname = xmemdupz(e->d_name, len);\n+\t\tfname = xmemdupz(diter->relative_path, len);\n \n \t\tif (!file_exists(mkpath(\"%s/%s.keep\", packdir, fname)))\n \t\t\tstring_list_append_nodup(fname_list, fname);\n \t\telse\n \t\t\tfree(fname);\n \t}\n-\tclosedir(dir);\n }\n \n static void remove_redundant_pack(const char *dir_name, const char *base_name)\n-- \n2.7.4\n\n\n\n\nHi , this is my first patch submission for Git Gsoc. I ran full tests and local tests with\nprove --timer --jobs 15 ./t*pack*.sh .\n\nHave a great day,\n             Robert.\n"},{"id":"315584","messageId":"CAGZ79kbtXEBKBaw75-tLay4LO1F3i3nDz6CU8FgTkJ7iwEY5QQ@mail.gmail.com","threadId":"45524","inReplyTo":"1490665185-11809-1-git-send-email-robert.stanca7@gmail.com","subject":"Re: [PATCH] [GSOC] get_non_kept_pack_filenames(): reimplement using iterators","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-03-28T18:23:15Z","receivedAt":"2017-03-28T18:23:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Mar 27, 2017 at 6:39 PM, Robert Stanca <robert.stanca7@gmail.com> wrote:\n> Replaces recursive traversing of opendir with dir_iterator.\n>\n> Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>\n> ---\n>  builtin/repack.c | 15 ++++++---------\n>  1 file changed, 6 insertions(+), 9 deletions(-)\n>\n> diff --git a/builtin/repack.c b/builtin/repack.c\n> index 677bc7c..27a5597 100644\n> --- a/builtin/repack.c\n> +++ b/builtin/repack.c\n> @@ -7,6 +7,8 @@\n>  #include \"strbuf.h\"\n>  #include \"string-list.h\"\n>  #include \"argv-array.h\"\n> +#include \"iterator.h\"\n> +#include \"dir-iterator.h\"\n>\n>  static int delta_base_offset = 1;\n>  static int pack_kept_objects = -1;\n> @@ -86,26 +88,21 @@ static void remove_pack_on_signal(int signo)\n>   */\n>  static void get_non_kept_pack_filenames(struct string_list *fname_list)\n>  {\n> -       DIR *dir;\n> -       struct dirent *e;\n> +       struct dir_iterator *diter = dir_iterator_begin(packdir);\n>         char *fname;\n>\n> -       if (!(dir = opendir(packdir)))\n> -               return;\n> -\n> -       while ((e = readdir(dir)) != NULL) {\n> +       while (dir_iterator_advance(diter) == ITER_OK) {\n>                 size_t len;\n> -               if (!strip_suffix(e->d_name, \".pack\", &len))\n> +               if (!strip_suffix(diter->relative_path, \".pack\", &len))\n>                         continue;\n>\n> -               fname = xmemdupz(e->d_name, len);\n> +               fname = xmemdupz(diter->relative_path, len);\n>\n>                 if (!file_exists(mkpath(\"%s/%s.keep\", packdir, fname)))\n>                         string_list_append_nodup(fname_list, fname);\n>                 else\n>                         free(fname);\n>         }\n> -       closedir(dir);\n>  }\n>\n>  static void remove_redundant_pack(const char *dir_name, const char *base_name)\n> --\n> 2.7.4\n>\n>\n>\n>\n> Hi , this is my first patch submission for Git Gsoc. I ran full tests and local tests with\n> prove --timer --jobs 15 ./t*pack*.sh .\n>\n> Have a great day,\n>              Robert.\n\nHi and welcome to the Git community!\n\nThe patch looks like a faithful conversion with no side effects to me.\nReviewed-by: Stefan Beller <sbeller@google.com>\n\nNote: mail readers usually collapse long signatures (e.g. everything\nafter \"--\\n2.7.4\"  in this email. So I did not know or even read your\ncomments on how you tested this patch before hitting reply.\nYou can also put these lines after the \"---\" after the sign off,\nright before the diff stat.  A good example is\nhttps://public-inbox.org/git/20170324231013.23346-1-avarab@gmail.com/\nas the patch is also long enough, such that people may not scroll to the\nbottom.  Once you're used to it, it is very easy to spot the chatter\nthat will not be part of the commit message, though.\n\nThanks,\nStefan\n"}]}