{"thread":{"id":"63005","subject":"'git rev-list' commit ordering issue","startedAt":"2025-02-26T01:44:19Z","lastAt":"2025-02-28T16:05:57Z","messageCount":5,"participants":["Clement Moyroud","D. Ben Knoble","Phillip Wood"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"513047","messageId":"CABXAcUxHp3LnyqR=NM0coh6wG-1uy4GB3FdeZEg8mPHu-vt0bQ@mail.gmail.com","threadId":"63005","inReplyTo":null,"subject":"'git rev-list' commit ordering issue","fromName":"Clement Moyroud","fromEmail":"clement.moyroud@gmail.com","sentAt":"2025-02-26T01:43:41Z","receivedAt":"2025-02-26T01:44:19Z","isPatch":false,"sender":{"key":"clement.moyroud@gmail.com","avatar":null},"body":"Hello,\n\nI've come across an issue with `git rev-list --no-walk=sorted` commit\nordering when\ntwo commits have the exact same commit date. In that case, `git rev-list` will\nleave the two commits in the original order, preventing automated\ncherry-picking.\n\nTo reproduce starting from the attached repo archive created with `git\nbugreport`:\ngit rev-list --reverse HEAD | git rev-list --no-walk=sorted --stdin\n\nYou'll see that the order of the two middle commits is incorrect and\ndoes not match\nthe order returned by `git rev-list HEAD`\n\nSince both commits have the same commit date, `git rev-list` should use another\ncriterion to do the sorting - namely, use the parent/child topology.\n\nIf there are better ways to sort such a list, let me know. This is a much\nsimplified test case. In our real-world application, we start from a subset\nof commits that we want to cherry-pick from a branch, for the purpose\nof creating\na customer-specific patch build. For the automated cherry-pick to work, we need\nto have these commits sorted in topological order. I do not see an option to\n`git rev-list` that only sorts the commits in stdin topologically - the\n`--no-walk` option only does date-based sorting.\n\nBelow is the system info gathered by `git bugreport`.\n\nTake care,\n\nClement\n\n\n[System Info]\ngit version:\ngit version 2.48.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibcurl: 7.87.0\nOpenSSL: OpenSSL 1.0.1e-fips 11 Feb 2013\nzlib: 1.2.3\nuname: Linux 4.18.0-553.33.1.el8_10.x86_64 #1 SMP Thu Dec 19 14:28:01\nUTC 2024 x86_64\ncompiler info: gnuc: 6.2\nlibc info: glibc: 2.28\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Enabled Hooks]\n"},{"id":"513118","messageId":"CALnO6CA2j60gpPhUjxOY6_q5WdU7MHoL1GLDN_AVwWVNx_JddQ@mail.gmail.com","threadId":"63005","inReplyTo":"CABXAcUxHp3LnyqR=NM0coh6wG-1uy4GB3FdeZEg8mPHu-vt0bQ@mail.gmail.com","subject":"Re: 'git rev-list' commit ordering issue","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-02-26T18:57:56Z","receivedAt":"2025-02-26T18:58:08Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Tue, Feb 25, 2025 at 8:44 PM Clement Moyroud\n<clement.moyroud@gmail.com> wrote:\n>\n> Hello,\n>\n> I've come across an issue with `git rev-list --no-walk=sorted` commit\n> ordering when\n> two commits have the exact same commit date. In that case, `git rev-list` will\n> leave the two commits in the original order, preventing automated\n> cherry-picking.\n>\n> To reproduce starting from the attached repo archive created with `git\n> bugreport`:\n> git rev-list --reverse HEAD | git rev-list --no-walk=sorted --stdin\n>\n> You'll see that the order of the two middle commits is incorrect and\n> does not match\n> the order returned by `git rev-list HEAD`\n>\n> Since both commits have the same commit date, `git rev-list` should use another\n> criterion to do the sorting - namely, use the parent/child topology.\n>\n> If there are better ways to sort such a list, let me know. This is a much\n> simplified test case. In our real-world application, we start from a subset\n> of commits that we want to cherry-pick from a branch, for the purpose\n> of creating\n> a customer-specific patch build. For the automated cherry-pick to work, we need\n> to have these commits sorted in topological order. I do not see an option to\n> `git rev-list` that only sorts the commits in stdin topologically - the\n> `--no-walk` option only does date-based sorting.\n\nIs `--topo-order` of no help here?\n\n>\n> Below is the system info gathered by `git bugreport`.\n>\n> Take care,\n>\n> Clement\n>\n>\n> [System Info]\n> git version:\n> git version 2.48.1\n> cpu: x86_64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> libcurl: 7.87.0\n> OpenSSL: OpenSSL 1.0.1e-fips 11 Feb 2013\n> zlib: 1.2.3\n> uname: Linux 4.18.0-553.33.1.el8_10.x86_64 #1 SMP Thu Dec 19 14:28:01\n> UTC 2024 x86_64\n> compiler info: gnuc: 6.2\n> libc info: glibc: 2.28\n> $SHELL (typically, interactive shell): /bin/zsh\n>\n>\n> [Enabled Hooks]\n\n\n\n-- \nD. Ben Knoble\n"},{"id":"513124","messageId":"CABXAcUwHd2Rr8iOZ7F2k5DGiBNH87pwG3oyRWLrP40=MgD91-w@mail.gmail.com","threadId":"63005","inReplyTo":"CALnO6CA2j60gpPhUjxOY6_q5WdU7MHoL1GLDN_AVwWVNx_JddQ@mail.gmail.com","subject":"Re: 'git rev-list' commit ordering issue","fromName":"Clement Moyroud","fromEmail":"clement.moyroud@gmail.com","sentAt":"2025-02-26T22:30:41Z","receivedAt":"2025-02-26T22:31:18Z","isPatch":false,"sender":{"key":"clement.moyroud@gmail.com","avatar":null},"body":"On Wed, Feb 26, 2025 at 10:58 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:\n>\n> On Tue, Feb 25, 2025 at 8:44 PM Clement Moyroud\n> <clement.moyroud@gmail.com> wrote:\n> >\n> > Hello,\n> >\n> > I've come across an issue with `git rev-list --no-walk=sorted` commit\n> > ordering when\n> > two commits have the exact same commit date. In that case, `git rev-list` will\n> > leave the two commits in the original order, preventing automated\n> > cherry-picking.\n> >\n> > To reproduce starting from the attached repo archive created with `git\n> > bugreport`:\n> > git rev-list --reverse HEAD | git rev-list --no-walk=sorted --stdin\n> >\n> > You'll see that the order of the two middle commits is incorrect and\n> > does not match\n> > the order returned by `git rev-list HEAD`\n> >\n> > Since both commits have the same commit date, `git rev-list` should use another\n> > criterion to do the sorting - namely, use the parent/child topology.\n> >\n> > If there are better ways to sort such a list, let me know. This is a much\n> > simplified test case. In our real-world application, we start from a subset\n> > of commits that we want to cherry-pick from a branch, for the purpose\n> > of creating\n> > a customer-specific patch build. For the automated cherry-pick to work, we need\n> > to have these commits sorted in topological order. I do not see an option to\n> > `git rev-list` that only sorts the commits in stdin topologically - the\n> > `--no-walk` option only does date-based sorting.\n>\n> Is `--topo-order` of no help here?\n\nUnfortunately no, because it'll look at the ancestors. I get more\ncommits (400k+ extra\ncommits in my real world case) than I have on stdin:\n$ git log -1 --pretty=%H 2025.2 | git rev-list --stdin --topo-order --count\n417776\n\n--\nClement\n\n>\n> >\n> > Below is the system info gathered by `git bugreport`.\n> >\n> > Take care,\n> >\n> > Clement\n> >\n> >\n> > [System Info]\n> > git version:\n> > git version 2.48.1\n> > cpu: x86_64\n> > no commit associated with this build\n> > sizeof-long: 8\n> > sizeof-size_t: 8\n> > shell-path: /bin/sh\n> > libcurl: 7.87.0\n> > OpenSSL: OpenSSL 1.0.1e-fips 11 Feb 2013\n> > zlib: 1.2.3\n> > uname: Linux 4.18.0-553.33.1.el8_10.x86_64 #1 SMP Thu Dec 19 14:28:01\n> > UTC 2024 x86_64\n> > compiler info: gnuc: 6.2\n> > libc info: glibc: 2.28\n> > $SHELL (typically, interactive shell): /bin/zsh\n> >\n> >\n> > [Enabled Hooks]\n>\n>\n>\n> --\n> D. Ben Knoble\n"},{"id":"513275","messageId":"d7b1416d-d201-400e-a0eb-b9e526f740ab@gmail.com","threadId":"63005","inReplyTo":"CABXAcUwHd2Rr8iOZ7F2k5DGiBNH87pwG3oyRWLrP40=MgD91-w@mail.gmail.com","subject":"Re: 'git rev-list' commit ordering issue","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-02-28T10:59:44Z","receivedAt":"2025-02-28T10:59:48Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Clement\n\nOn 26/02/2025 22:30, Clement Moyroud wrote:\n> On Wed, Feb 26, 2025 at 10:58 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:\n >\n>> Is `--topo-order` of no help here?\n> \n> Unfortunately no, because it'll look at the ancestors. I get more\n> commits (400k+ extra\n> commits in my real world case) than I have on stdin:\n> $ git log -1 --pretty=%H 2025.2 | git rev-list --stdin --topo-order --count\n> 417776\n\nThis seems to have lost \"--no-walk\".\n\n     ... | git rev-list --stdin --topo-order --no-walk\n\nshould list only the commits passed on stdin in topographic order I think.\n\nBest Wishes\n\nPhillip\n\n> --\n> Clement\n> \n>>\n>>>\n>>> Below is the system info gathered by `git bugreport`.\n>>>\n>>> Take care,\n>>>\n>>> Clement\n>>>\n>>>\n>>> [System Info]\n>>> git version:\n>>> git version 2.48.1\n>>> cpu: x86_64\n>>> no commit associated with this build\n>>> sizeof-long: 8\n>>> sizeof-size_t: 8\n>>> shell-path: /bin/sh\n>>> libcurl: 7.87.0\n>>> OpenSSL: OpenSSL 1.0.1e-fips 11 Feb 2013\n>>> zlib: 1.2.3\n>>> uname: Linux 4.18.0-553.33.1.el8_10.x86_64 #1 SMP Thu Dec 19 14:28:01\n>>> UTC 2024 x86_64\n>>> compiler info: gnuc: 6.2\n>>> libc info: glibc: 2.28\n>>> $SHELL (typically, interactive shell): /bin/zsh\n>>>\n>>>\n>>> [Enabled Hooks]\n>>\n>>\n>>\n>> --\n>> D. Ben Knoble\n> \n\n"},{"id":"513285","messageId":"CABXAcUyWu3zi_iXrSoc1ymZCYtE5u4+JybJp2TiCCJA18T-4CQ@mail.gmail.com","threadId":"63005","inReplyTo":"d7b1416d-d201-400e-a0eb-b9e526f740ab@gmail.com","subject":"Re: 'git rev-list' commit ordering issue","fromName":"Clement Moyroud","fromEmail":"clement.moyroud@gmail.com","sentAt":"2025-02-28T16:05:20Z","receivedAt":"2025-02-28T16:05:57Z","isPatch":false,"sender":{"key":"clement.moyroud@gmail.com","avatar":null},"body":"On Fri, Feb 28, 2025 at 2:59 AM Phillip Wood <phillip.wood123@gmail.com> wrote:\n>\n> Hi Clement\n>\n> On 26/02/2025 22:30, Clement Moyroud wrote:\n> > On Wed, Feb 26, 2025 at 10:58 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:\n>  >\n> >> Is `--topo-order` of no help here?\n> >\n> > Unfortunately no, because it'll look at the ancestors. I get more\n> > commits (400k+ extra\n> > commits in my real world case) than I have on stdin:\n> > $ git log -1 --pretty=%H 2025.2 | git rev-list --stdin --topo-order --count\n> > 417776\n>\n> This seems to have lost \"--no-walk\".\n>\n>      ... | git rev-list --stdin --topo-order --no-walk\n>\n> should list only the commits passed on stdin in topographic order I think.\n>\n> Best Wishes\n>\n> Phillip\n>\n\nHi Philip,\n\nI wish that were the case :) Per the docs:\n| If the argument unsorted is given, the commits are shown in the order they\n| were given on the command line. Otherwise (if sorted or no argument was\n| given), the commits are shown in reverse chronological order by commit time.\n\nAs soon as you specify --no-walk, topological ordering is disabled. I\n_think_ it's\nbecause it will instruct `rev-list` not to look at the ancestors. It\nlooks like a new\nin-between option is needed, where topological ordering is used when the dates\nmatch.\n\nCheers,\n\nClement\n\n> > --\n> > Clement\n> >\n> >>\n> >>>\n> >>> Below is the system info gathered by `git bugreport`.\n> >>>\n> >>> Take care,\n> >>>\n> >>> Clement\n> >>>\n> >>>\n> >>> [System Info]\n> >>> git version:\n> >>> git version 2.48.1\n> >>> cpu: x86_64\n> >>> no commit associated with this build\n> >>> sizeof-long: 8\n> >>> sizeof-size_t: 8\n> >>> shell-path: /bin/sh\n> >>> libcurl: 7.87.0\n> >>> OpenSSL: OpenSSL 1.0.1e-fips 11 Feb 2013\n> >>> zlib: 1.2.3\n> >>> uname: Linux 4.18.0-553.33.1.el8_10.x86_64 #1 SMP Thu Dec 19 14:28:01\n> >>> UTC 2024 x86_64\n> >>> compiler info: gnuc: 6.2\n> >>> libc info: glibc: 2.28\n> >>> $SHELL (typically, interactive shell): /bin/zsh\n> >>>\n> >>>\n> >>> [Enabled Hooks]\n> >>\n> >>\n> >>\n> >> --\n> >> D. Ben Knoble\n> >\n>\n"}]}