{"thread":{"id":"59604","subject":"Regression introduced in 03267e8656truct object_id oid;","startedAt":"2023-04-16T17:26:58Z","lastAt":"2023-04-17T16:55:05Z","messageCount":3,"participants":["Lars Kellogg-Stedman","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"475492","messageId":"bt4342bdip3nzlikjsv6wozszmcbsc2av6cyo3z2lra4jhx3ii@ut2sl5h4f5xn","threadId":"59604","inReplyTo":null,"subject":"Regression introduced in 03267e8656truct object_id oid;","fromName":"Lars Kellogg-Stedman","fromEmail":"lars@oddbit.com","sentAt":"2023-04-16T17:20:20Z","receivedAt":"2023-04-16T17:26:58Z","isPatch":false,"sender":{"key":"lars@oddbit.com","avatar":"https://avatars.githubusercontent.com/u/82622?v=4"},"body":"[This behavior was originally reported in\nhttps://stackoverflow.com/q/76022720/147356.]\n\nPrior to commit 03267e8656, the following sequence would result in an\nempty commit:\n\n    git init testrepo\n    date > testrepo/testfile\n    git -C testrepo add testfile\n    git -C testrepo commit -m test --allow-empty --only\n\nAfter commit 03267e8656, the same sequence creates a commit that\ncontains \"testfile\". I believe the original behavior was correct,\nbased on the documentation for the `--only` option:\n\n> If used together with --allow-empty paths are also not required, and\n> an empty commit will be created.\n\nA simple change that corrects this behavior would be to prevent git\nfrom refreshing the cache when --only is active:\n\n    diff --git a/builtin/commit.c b/builtin/commit.c\n    index 9d8e1ea91a..8c441548f8 100644\n    --- a/builtin/commit.c\n    +++ b/builtin/commit.c\n    @@ -995,7 +995,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n        struct object_id oid;\n        const char *parent = \"HEAD\";\n     \n    -\t\tif (!the_index.cache_nr) {\n    +\t\tif (!the_index.cache_nr && !only) {\n          discard_index(&the_index);\n          if (repo_read_index(the_repository) < 0)\n            die(_(\"Cannot read index\"));\n\nAnd while that passes all the tests, I'm not sure if its correct; the\nchange in 03267e8656 was correcting a memory leak and I'm not sure I\ncompletely understand the details.\n\n-- \nLars Kellogg-Stedman <lars@oddbit.com> | larsks @ {irc,twitter,github}\nhttp://blog.oddbit.com/                | N1LKS\n"},{"id":"475493","messageId":"5vey46onc6xwy5ifqieuut6m4ni3gpy5mweucmc2lroemtau3n@d5x4rgauq5zt","threadId":"59604","inReplyTo":"bt4342bdip3nzlikjsv6wozszmcbsc2av6cyo3z2lra4jhx3ii@ut2sl5h4f5xn","subject":"Re: Regression introduced in 03267e8656","fromName":"Lars Kellogg-Stedman","fromEmail":"lars@oddbit.com","sentAt":"2023-04-16T17:30:03Z","receivedAt":"2023-04-16T17:36:52Z","isPatch":false,"sender":{"key":"lars@oddbit.com","avatar":"https://avatars.githubusercontent.com/u/82622?v=4"},"body":"...with apologies for that munged subject: line.\n\n-- \nLars Kellogg-Stedman <lars@oddbit.com> | larsks @ {irc,twitter,github}\nhttp://blog.oddbit.com/                | N1LKS\n"},{"id":"475535","messageId":"xmqqttxemotc.fsf@gitster.g","threadId":"59604","inReplyTo":"bt4342bdip3nzlikjsv6wozszmcbsc2av6cyo3z2lra4jhx3ii@ut2sl5h4f5xn","subject":"Re: Regression introduced in 03267e86","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-17T16:54:55Z","receivedAt":"2023-04-17T16:55:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Lars Kellogg-Stedman <lars@oddbit.com> writes:\n\n> [This behavior was originally reported in\n> https://stackoverflow.com/q/76022720/147356.]\n>\n> Prior to commit 03267e8656, the following sequence would result in an\n> empty commit:\n>\n>     git init testrepo\n>     date > testrepo/testfile\n>     git -C testrepo add testfile\n>     git -C testrepo commit -m test --allow-empty --only\n>\n> After commit 03267e8656, the same sequence creates a commit that\n> contains \"testfile\". I believe the original behavior was correct,\n> based on the documentation for the `--only` option:\n\nIt looks like a convoluted way (aka use of an obscure option) to\ncreate something useless (aka an empty root commit), but it should\nbe allowed and the last step should do what you expected.\n\n> And while that passes all the tests, I'm not sure if its correct; the\n> change in 03267e8656 was correcting a memory leak and I'm not sure I\n> completely understand the details.\n\nYeah, figuring out how 03267e86 (commit: discard partial cache\nbefore (re-)reading it, 2022-11-08) broke the behaviour is a good\nfirst step.\n\nThanks for reporting.\n"}]}