{"thread":{"id":"55805","subject":"[GSOC] Git Blog 2","startedAt":"2021-05-30T14:36:10Z","lastAt":"2021-05-31T11:05:06Z","messageCount":3,"participants":["ZheNing Hu","Felipe Contreras"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"425923","messageId":"CAOLTT8T0XtmpH3cHDBOfcX5nmCzfyrKby4TrFkHtA9H3dDN63A@mail.gmail.com","threadId":"55805","inReplyTo":null,"subject":"[GSOC] Git Blog 2","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-05-30T14:35:56Z","receivedAt":"2021-05-30T14:36:10Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"My second week blog finished:\nThe web version is here:\nhttps://adlternative.github.io/GSOC-Git-Blog-2/\n\n-------\n## Week2: learning the slang of a new city\n\n### What happened this week\n- In [[PATCH 1/2] [GSOC] ref-filter: add %(raw)\natom](https://lore.kernel.org/git/b3848f24f2d3f91fc96f20b5a08cbfbe721acbd6.1622126603.git.gitgitgadget@gmail.com/),\nI made a license-related mistake this week. When I was\nimplementing `%(raw)` atom for ref-filter, I noticed that\n`glibc` did not provide us with `memcasecmp()` which\ncan be used to compare two pieces of memory and\nignore case, so I found `memcasecmp()` implemented\nby `gnulib` on the Internet, and copy it to git to use.\nBut unfortunately, I should not copy it so \"conveniently\".\nGit use `gpl-v2` and `gunlib` use `gpl-v3`, they are\nincompatible. Since I used to write code for my own use,\nI am not very sensitive to licenses problems. Thanks to\n`Felipe Contreras` for correcting me. Therefore, from today\nonwards, I will be more careful about the license.\n- On the other hand, I realized that clean code is also a\nvery important thing. In `cmp_ref_sorting()`, I want to use\n`memcmp()/memcasecmp()` to compare two strings.\n\nBAD VERSION:\n  ```c\n                        int (*cmp_fn)(const void *, const void *, size_t);\n                        cmp_fn = s->sort_flags & REF_SORTING_ICASE\n                                ? memcasecmp : memcmp;\n\n                        if (va->s_size != ATOM_VALUE_S_SIZE_INIT &&\n                            vb->s_size != ATOM_VALUE_S_SIZE_INIT) {\n                                cmp = cmp_fn(va->s, vb->s, va->s_size\n> vb->s_size ?\n                                       vb->s_size : va->s_size);\n                        } else if (va->s_size == ATOM_VALUE_S_SIZE_INIT) {\n                                slen = strlen(va->s);\n                                cmp = cmp_fn(va->s, vb->s, slen > vb->s_size ?\n                                             vb->s_size : slen);\n                        } else {\n                                slen = strlen(vb->s);\n                                cmp = cmp_fn(va->s, vb->s, slen > va->s_size ?\n                                             slen : va->s_size);\n                        }\n                        cmp = cmp ? cmp : va->s_size - vb->s_size;\n                }\n  ```\nIt's complicated and buggy.\n\nGOOD VERSION:\n  ```c\n\n                        int (*cmp_fn)(const void *, const void *, size_t);\n                        cmp_fn = s->sort_flags & REF_SORTING_ICASE\n                                ? memcasecmp : memcmp;\n                        size_t a_size = va->s_size == ATOM_VALUE_S_SIZE_INIT ?\n                                        strlen(va->s) : va->s_size;\n                        size_t b_size = vb->s_size == ATOM_VALUE_S_SIZE_INIT ?\n                                        strlen(vb->s) : vb->s_size;\n\n                        cmp = cmp_fn(va->s, vb->s, b_size > a_size ?\n                                     a_size : b_size);\n                        if (!cmp) {\n                                if (a_size > b_size)\n                                        cmp = 1;\n                                else if (a_size < b_size)\n                                        cmp = -1;\n                        }\n\n  ```\nIt's relatively refreshing a lot.\n\nSo how to cultivate a good coding style? As\n`Felipe Contreras` said: \"It's like learning the\nslang of a new city; it takes a while.\"\n\n\n### What's the next step\nThere are still some flaws in the %(raw)\nimplementation, but let's look ahead and see what\nwe can do. We check the atoms with `verify_ref_format()`\nand pass object oid and grub corresponding object data\nthrough `format_ref_array_item()`:\n\n|Git command|Atoms|\n|-|-|\n|`git cat-file --batch-check` | `%(objectname) %(objecttype) %(objectsize)`|\n|`git cat-file --batch --symlink`| `%(objectname) %(objecttype) %(objectsize)`|\n|`git cat-file --batch` | `%(objectname) %(objecttype) %(objectsize)\\n%(raw)`|\n|`git cat-file --batch --textconv` | `%(objectname) %(objecttype)\n%(objectsize)\\n%(raw:textconv)`|\n|`git cat-file --batch --filter` | `%(objectname) %(objecttype)\n%(objectsize)\\n%(raw:filter)`|\n|`git cat-file --batch=\"%(rest)\"` | `%(rest)`|\n\nNo additional operation is required in\n`git cat-file --batch --symlink`, because\n`get_oid_with_context(...,GET_OID_FOLLOW_SYMLINKS,...)`\ncan help us do that.\n\nI have leave the rough implementation here:\n[adlternative:cat-file-temp](https://github.com/gitgitgadget/git/compare/master...adlternative:cat-file-temp).\nits performance is 25% worse than before.\n\nRather than posting it to the mailing list, because I still\nneed to implement the previous dependencies step by step...\n\nThanks!\n\n--\nZheNing Hu\n"},{"id":"425925","messageId":"60b3b513537ca_b8852081a@natae.notmuch","threadId":"55805","inReplyTo":"CAOLTT8T0XtmpH3cHDBOfcX5nmCzfyrKby4TrFkHtA9H3dDN63A@mail.gmail.com","subject":"RE: [GSOC] Git Blog 2","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-30T15:53:55Z","receivedAt":"2021-05-30T15:54:00Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"ZheNing Hu wrote:\n> My second week blog finished:\n> The web version is here:\n> https://adlternative.github.io/GSOC-Git-Blog-2/\n> \n> -------\n> ## Week2: learning the slang of a new city\n> \n> ### What happened this week\n> - In [[PATCH 1/2] [GSOC] ref-filter: add %(raw)\n> atom](https://lore.kernel.org/git/b3848f24f2d3f91fc96f20b5a08cbfbe721acbd6.1622126603.git.gitgitgadget@gmail.com/),\n> I made a license-related mistake this week. When I was\n> implementing `%(raw)` atom for ref-filter, I noticed that\n> `glibc` did not provide us with `memcasecmp()` which\n> can be used to compare two pieces of memory and\n> ignore case, so I found `memcasecmp()` implemented\n> by `gnulib` on the Internet, and copy it to git to use.\n> But unfortunately, I should not copy it so \"conveniently\".\n> Git use `gpl-v2` and `gunlib` use `gpl-v3`,\n\nMinor nit: some projects are GPLv2+, and those projects are compatible\nwith GPLv3, but others (like Linux and Git) are GPLv2-only, those are\nnot compatible.\n\nSo say GPLv2-only.\n\n(In practice I don't think it matters because at this point probably\nmost GPLv2 projects are GPLv2-only)\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"425995","messageId":"CAOLTT8RWY2AOoXb1DM_dpxQ=Bi26Dj0_W_bZNU9rqeNqDp7ZgA@mail.gmail.com","threadId":"55805","inReplyTo":"60b3b513537ca_b8852081a@natae.notmuch","subject":"Re: [GSOC] Git Blog 2","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-05-31T11:04:42Z","receivedAt":"2021-05-31T11:05:06Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> 于2021年5月30日周日 下午11:53写道：\n>\n> Minor nit: some projects are GPLv2+, and those projects are compatible\n> with GPLv3, but others (like Linux and Git) are GPLv2-only, those are\n> not compatible.\n>\n> So say GPLv2-only.\n>\n> (In practice I don't think it matters because at this point probably\n> most GPLv2 projects are GPLv2-only)\n>\n\nThanks for your supplement, I will correct it in time.\n\n> Cheers.\n>\n> --\n> Felipe Contreras\n\n--\nZheNing Hu\n"}]}