Git development
 help / color / mirror / Atom feed
* [PATCH 0/1] Extract only the message log body from git commit.
@ 2026-07-22  8:38 hardikxk
  2026-07-22  8:38 ` [PATCH 1/1] Extract only the message " hardikxk
  2026-07-22 12:38 ` [PATCH 0/1] Extract only the message log " Pablo Sabater
  0 siblings, 2 replies; 6+ messages in thread
From: hardikxk @ 2026-07-22  8:38 UTC (permalink / raw)
  To: git; +Cc: hardikxk


The patch fixes the `extractLogMessageFromGitCommit` function to skip all the metada of the commit object and only return back the message body.

Previously the function would return the entire data of the objects
including authors tree and SHAs. This patch fixes that to skip over all
that and just return the body of the log message.

hardikxk (1):
  Extract only the message body from git commit.

 git-p4.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)


base-commit: 48bbf81c29ca9a4479ec7850fe206518682cdb2f
-- 
2.55.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] Extract only the message body from git commit.
  2026-07-22  8:38 [PATCH 0/1] Extract only the message log body from git commit hardikxk
@ 2026-07-22  8:38 ` hardikxk
  2026-07-22 12:23   ` Pablo Sabater
  2026-07-22 20:53   ` Junio C Hamano
  2026-07-22 12:38 ` [PATCH 0/1] Extract only the message log " Pablo Sabater
  1 sibling, 2 replies; 6+ messages in thread
From: hardikxk @ 2026-07-22  8:38 UTC (permalink / raw)
  To: git; +Cc: hardikxk

The patch fixes the `extractLogMessageFromGitCommit` function to skip all the metada of the commit object and only return back the message body.

Previously the function would return the entire data of the objects
including authors tree and SHAs. This patch fixes that to skip over all
that and just return the body of the log message.

Signed-off-by: hardikxk <hardikxk@gmail.com>
---
 git-p4.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index c0ca7be..589efcd 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1003,12 +1003,18 @@ def branchExists(ref):
 def extractLogMessageFromGitCommit(commit):
     logMessage = ""
 
-    # fixme: title is first line of commit, not 1st paragraph.
+    foundNewLine = False
     foundTitle = False
     for log in read_pipe_lines(["git", "cat-file", "commit", commit]):
-        if not foundTitle:
+        if not foundNewLine:
+            # skip anything that is not the commit message
             if len(log) == 1:
-                foundTitle = True
+                foundNewLine = True
+            continue
+
+        # everything from here is the commit message
+        if not foundTitle:
+            foundTitle = True
             continue
 
         logMessage += log
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Extract only the message body from git commit.
  2026-07-22  8:38 ` [PATCH 1/1] Extract only the message " hardikxk
@ 2026-07-22 12:23   ` Pablo Sabater
  2026-07-22 13:42     ` Hardik Kumar
  2026-07-22 20:53   ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Pablo Sabater @ 2026-07-22 12:23 UTC (permalink / raw)
  To: hardikxk, git

On Wed Jul 22, 2026 at 10:38 AM CEST, hardikxk wrote:
> The patch fixes the `extractLogMessageFromGitCommit` function to skip all the metada of the commit object and only return back the message body.

nit: wrap this long line to a max of ~72 columns.
nit: s/metada/metadata/

>
> Previously the function would return the entire data of the objects
> including authors tree and SHAs. This patch fixes that to skip over all
> that and just return the body of the log message.

nit: I think this can be written more clearly. Let's use present tense
and state things affirmatively:

  extractLogMessageFromGitCommit() returns the entire object data,
  including authors, tree and SHAs.
  Make it return only the log message body.

Don't take this suggestion literally, as we find below that this log
does not match reality.

You may find Documentation/CodingGuidelines and
Documentation/SubmittingPatches interesting.

>
> Signed-off-by: hardikxk <hardikxk@gmail.com>
> ---
>  git-p4.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index c0ca7be..589efcd 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1003,12 +1003,18 @@ def branchExists(ref):
>  def extractLogMessageFromGitCommit(commit):
>      logMessage = ""
>
> -    # fixme: title is first line of commit, not 1st paragraph.
> +    foundNewLine = False
>      foundTitle = False
>      for log in read_pipe_lines(["git", "cat-file", "commit", commit]):
> -        if not foundTitle:
> +        if not foundNewLine:
> +            # skip anything that is not the commit message
>              if len(log) == 1:
> -                foundTitle = True
> +                foundNewLine = True
> +            continue
> +
> +        # everything from here is the commit message
> +        if not foundTitle:
> +            foundTitle = True
>              continue
>
>          logMessage += log

Reading the code, this doesn't seem to do what the log says it does.
Testing it against what it did before this patch:

First we need to do a bit of investigation, but we end up finding
that the commit that introduced this '# fixme' was:

  b016d39756 (Robustness fixes for pipes, 2007-05-23)

I couldn't find a thread about this commit.

*Note that the output does not have line breaks; I'm adding them for
readability*.

previously:

'Extract only the message body from git commit.\n\nThe patch fixes the
`extractLogMessageFromGitCommit` function to skip all the metada of the
commit object and only return back the message body.\n\nPreviously the
function would return the entire data of the objects\nincluding authors
tree and SHAs. This patch fixes that to skip over all\nthat and just
return the body of the log message.\n\nSigned-off-by: hardikxk <hardikxk@gmail.com>\n'

after the patch:

'\nThe patch fixes the `extractLogMessageFromGitCommit` function to skip
all the metada of the commit object and only return back the message
body.\n\nPreviously the function would return the entire data of the
objects\nincluding authors tree and SHAs. This patch fixes that to skip
over all\nthat and just return the body of the log message.
\n\nSigned-off-by: hardikxk <hardikxk@gmail.com>\n'

We can see that the previous output only shows the commit log, title
+ body. There were no SHAs, tree, etc., the opposite of what this
patch's log claimed.

What this patch actually does is drop the commit subject.

Is this what the '# fixme' meant? I'm making assumptions here, since I
couldn't find a thread to be sure why it was added, but I think it is
either about the loop stopping at the blank line rather than at the title
itself, or a warning that a title is just one line and not a paragraph.

Either way, this patch does not address the '# fixme' correctly.

Before continuing, I think we should try to understand what the '# fixme'
meant in the first place.

Regards,
Pablo.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] Extract only the message log body from git commit.
  2026-07-22  8:38 [PATCH 0/1] Extract only the message log body from git commit hardikxk
  2026-07-22  8:38 ` [PATCH 1/1] Extract only the message " hardikxk
@ 2026-07-22 12:38 ` Pablo Sabater
  1 sibling, 0 replies; 6+ messages in thread
From: Pablo Sabater @ 2026-07-22 12:38 UTC (permalink / raw)
  To: hardikxk, git

On Wed Jul 22, 2026 at 10:38 AM CEST, hardikxk wrote:
>
> The patch fixes the `extractLogMessageFromGitCommit` function to skip all the metada of the commit object and only return back the message body.

nit: Let's wrap this at ~72 columns.

>
> Previously the function would return the entire data of the objects
> including authors tree and SHAs. This patch fixes that to skip over all
> that and just return the body of the log message.

This repeats what the commit message already says. For a single-patch
series a cover letter is usually not needed.

Documentation/MyFirstContribution [1] notes that the commit message
should already explain the change at a high level, and that any extra
context can go below the '---' line instead. I would drop this cover
letter unless there's something else to say.

>
> hardikxk (1):
>   Extract only the message body from git commit.
>
>  git-p4.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
>
> base-commit: 48bbf81c29ca9a4479ec7850fe206518682cdb2f

[1]: https://github.com/git/git/blob/master/Documentation/MyFirstContribution.adoc#bonus-chapter-one-patch-changes

Regards,
Pablo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Extract only the message body from git commit.
  2026-07-22 12:23   ` Pablo Sabater
@ 2026-07-22 13:42     ` Hardik Kumar
  0 siblings, 0 replies; 6+ messages in thread
From: Hardik Kumar @ 2026-07-22 13:42 UTC (permalink / raw)
  To: Pablo Sabater, hardikxk, git

> nit: I think this can be written more clearly. Let's use present tense
> and state things affirmatively:

Sure, I will update this in a later commit.

> Reading the code, this doesn't seem to do what the log says it does.
> Testing it against what it did before this patch:
> We can see that the previous output only shows the commit log, title
> + body. There were no SHAs, tree, etc., the opposite of what this
> patch's log claimed.

I see, I was comparing this to the how git stores your commits in
.git/objects. My assumption was the function would take an object
from there and (wanting to extract just the body) was taking the
entire object as is and not stripping out the subject.

> What this patch actually does is drop the commit subject.

Yes, since I suppose all the other places in the file where
this method is being used don't require the subject line.

> Either way, this patch does not address the '# fixme' correctly.
>
> Before continuing, I think we should try to understand what the '# fixme'
> meant in the first place.

My assumption was that the function that I made changes to was solely
responsible for sending back only the message stripping out subject and
metadata related to the commit object.

Moving forward I suppose the one suggestion would be changing the name
of the variable `foundTitle` to `foundSubject` instead since that might
result in less ambuiguity in what the function is doing (and the fixme).
Although I dont't think if that really makes any difference.

But yes the #fixme does seem very vague now. Not sure if this is worth
it.

Regards,
Hardik.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Extract only the message body from git commit.
  2026-07-22  8:38 ` [PATCH 1/1] Extract only the message " hardikxk
  2026-07-22 12:23   ` Pablo Sabater
@ 2026-07-22 20:53   ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2026-07-22 20:53 UTC (permalink / raw)
  To: hardikxk; +Cc: git


hardikxk <hardikxk@gmail.com> writes:

> Subject: Re: [PATCH 1/1] Extract only the message body from git commit.

Please see Documentation/SubmittingPatches[[describe-changes]].

> The patch fixes the `extractLogMessageFromGitCommit` function to skip all the metada of the commit object and only return back the message body.

Line-wrap overly long lines like this one.

> Previously the function would return the entire data of the objects
> including authors tree and SHAs. This patch fixes that to skip over all
> that and just return the body of the log message.

Please see Documentation/SubmittingPatches[[meaningful-message]].
The observation on how the current code behaves should not be
described as "Previously X did Y".  Just say "X does Y" instead.
There are other rules on how to write proposed commit log messages
explained there.

> Signed-off-by: hardikxk <hardikxk@gmail.com>

Please see Documentation/SubmittingPatches[[real-name]].

> ---
>  git-p4.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)

Thanks.

> diff --git a/git-p4.py b/git-p4.py
> index c0ca7be..589efcd 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1003,12 +1003,18 @@ def branchExists(ref):
>  def extractLogMessageFromGitCommit(commit):
>      logMessage = ""
>  
> -    # fixme: title is first line of commit, not 1st paragraph.
> +    foundNewLine = False
>      foundTitle = False
>      for log in read_pipe_lines(["git", "cat-file", "commit", commit]):
> -        if not foundTitle:
> +        if not foundNewLine:
> +            # skip anything that is not the commit message
>              if len(log) == 1:
> -                foundTitle = True
> +                foundNewLine = True
> +            continue
> +
> +        # everything from here is the commit message
> +        if not foundTitle:
> +            foundTitle = True
>              continue
>  
>          logMessage += log


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-22 20:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22  8:38 [PATCH 0/1] Extract only the message log body from git commit hardikxk
2026-07-22  8:38 ` [PATCH 1/1] Extract only the message " hardikxk
2026-07-22 12:23   ` Pablo Sabater
2026-07-22 13:42     ` Hardik Kumar
2026-07-22 20:53   ` Junio C Hamano
2026-07-22 12:38 ` [PATCH 0/1] Extract only the message log " Pablo Sabater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox