{"thread":{"id":"62342","subject":"Feature Request: Document the log format string equivalent of built-in formats","startedAt":"2024-10-15T17:32:24Z","lastAt":"2024-10-15T18:43:37Z","messageCount":3,"participants":["Henry Qin","Kristoffer Haugsbakk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"505181","messageId":"CAO8bsPCWkqDFSqWwJ3gQt7O2g1okodb_Q-NbbkTq9bc7M=zU1A@mail.gmail.com","threadId":"62342","inReplyTo":null,"subject":"Feature Request: Document the log format string equivalent of built-in formats","fromName":"Henry Qin","fromEmail":"root@hq6.me","sentAt":"2024-10-15T17:31:56Z","receivedAt":"2024-10-15T17:32:24Z","isPatch":false,"sender":{"key":"root@hq6.me","avatar":null},"body":"Hi folks,\n\nI think it is useful to be able to take any of the pre-existing\nformats offered by `git log --format=<format>` and tweak it a little\nbit.\n\nIn order to do this efficiently, it's helpful to have the format\nstring equivalent of each pretty format documented explicitly,\ntogether with any limitations in being able to replicate them using a\nformat string..\n\nThe documentation in `man git-log` under PRETTY FORMATS is helpful but\ninsufficient.\n\nFor example, I tried to reproduce the format `medium` and have the following:\n\ngit log --format='%C(auto)commit %H%d%nAuthor: %an <%ae>%nDate:\n%ad%n%n%w(0,4,4)%s%n%n%-b%-C()%n'\n\nThere are two differences I have observed, and I have not yet been\nable to determine whether it's even possible to correct them.\n\n1. In my output, the ref names output by %d are added unconditionally,\nwhile git log will suppress them when the output is a file, and shows\nthem when the output is a terminal.\n2. In my output, I sometimes see a raw ^M symbol in commit messages,\nbut git log output does not show raw CR characters in its output even\nwhen CRLF is in the commit message.\n\nThanks,\n~Henry\n"},{"id":"505183","messageId":"22391e5d-c6fa-4b33-a12a-b63bbb979d81@app.fastmail.com","threadId":"62342","inReplyTo":"CAO8bsPCWkqDFSqWwJ3gQt7O2g1okodb_Q-NbbkTq9bc7M=zU1A@mail.gmail.com","subject":"Re: Feature Request: Document the log format string equivalent of built-in formats","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-10-15T18:04:58Z","receivedAt":"2024-10-15T18:05:50Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"Backlink:\n\nhttps://stackoverflow.com/questions/79089206/is-it-possible-to-fully-replicate-the-default-behavior-of-git-log-with-a-format\n\nI took a look at the code before today with search terms like\n\n    CMIT_FMT_DEFAULT\n    CMIT_FMT_MEDIUM,\n\nAnd it looked to me that at least parts of it were implemented using\nregular code branching.  I was thinking that maybe the built-in formats\nwere defined just using the formatting primitives.  But it didn’t look\nlike that to me.\n"},{"id":"505185","messageId":"CAO8bsPDiVLei4uc96jv2BnhQapo2NaFLu-MbdBMmdCKVtFuyZA@mail.gmail.com","threadId":"62342","inReplyTo":"22391e5d-c6fa-4b33-a12a-b63bbb979d81@app.fastmail.com","subject":"Re: Feature Request: Document the log format string equivalent of built-in formats","fromName":"Henry Qin","fromEmail":"root@hq6.me","sentAt":"2024-10-15T18:43:10Z","receivedAt":"2024-10-15T18:43:37Z","isPatch":false,"sender":{"key":"root@hq6.me","avatar":null},"body":"Thanks for backlinking!\nI had intended to link my SO question and then forgot.\n\nThat matches what I saw from reading the code as well.\nAs far as I could tell, the `pretty_print_commit` function only calls\n`repo_format_commit_message` when `pp->fmt == CMIT_FMT_USERFORMAT`,\nand not at all the built-in formats.\n\nThus, we cannot infer the correct format string equivalent by simply\nreading the code, which is another reason why I think it's worth\ndocumenting the closest format string equivalent and its limitations.\nIdeally, the format string is powerful enough to replicate the\nbuilt-in formats, but if it is not, then that is also worth\ndocumenting explicitly.\n\nReferences:\nhttps://github.com/git/git/blob/ef8ce8f3d4344fd3af049c17eeba5cd20d98b69f/pretty.c#L2282\nhttps://github.com/git/git/blob/ef8ce8f3d4344fd3af049c17eeba5cd20d98b69f/pretty.c#L2294\n\nOn Tue, Oct 15, 2024 at 11:06 AM Kristoffer Haugsbakk\n<kristofferhaugsbakk@fastmail.com> wrote:\n>\n> Backlink:\n>\n> https://stackoverflow.com/questions/79089206/is-it-possible-to-fully-replicate-the-default-behavior-of-git-log-with-a-format\n>\n> I took a look at the code before today with search terms like\n>\n>     CMIT_FMT_DEFAULT\n>     CMIT_FMT_MEDIUM,\n>\n> And it looked to me that at least parts of it were implemented using\n> regular code branching.  I was thinking that maybe the built-in formats\n> were defined just using the formatting primitives.  But it didn’t look\n> like that to me.\n"}]}