Skip to contentSkip to conversation

Diff format documentation for git-format-patch

PATCH In review Bagas Sanjaya 2 participants 7 messages Mar 24, 2021 – Mar 25, 2021 Documentation

lore
Share & tools
lore
#0 lore raw

cover Diff format documentation for git-format-patch

git-format-patch generates diff, but the documentation for its format is missing, so add it.

Bagas Sanjaya (2):
git-format-patch: Include diff-generate-patch documentation
git-format-patch: Document format for binary patch

 Documentation/git-format-patch.txt | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 git-format-patch: Include diff-generate-patch documentation

diff-generate-patch explains format of generated patch for text files.

---
 Documentation/git-format-patch.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/git-format-patch.txt +7 -0
index 3e49bf2210..247033f8fc 100644
@@ -718,6 +718,13 @@ use it only when you know the recipient uses Git to apply your patch.
 $ git format-patch -3
 ------------
 
+GENERATED DIFF FORMAT
+---------------------
+git-format-patch emits diff in generated patches. For text files, the
+diff format is described as below:
+
+include::diff-generate-patch.txt[]
+
 SEE ALSO
 --------
 linkgit:git-am[1], linkgit:git-send-email[1]
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] git-format-patch: Include diff-generate-patch documentation

Quoted 1 line · Bagas Sanjaya

diff-generate-patch explains format of generated patch for text files.

That is true, but that does not justify this change. In other words, the sentence does not explain why is it a good idea to describe the itty bitty details of what is in the format-patch output (which is more for the consumption of somebody other than the user who is running the format-patch command).

Quoted 10 lines
---
 Documentation/git-format-patch.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/git-format-patch.txt +0 -0
index 3e49bf2210..247033f8fc 100644

Documentation/git-format-patch.txt use it only when you know the recipient uses Git to apply your patch. · line 727

Quoted 10 lines
Documentation/git-format-patch.txt +7 -0
@@ -718,6 +718,13 @@ use it only when you know the recipient uses Git to apply your patch.
 $ git format-patch -3
 ------------
 
+GENERATED DIFF FORMAT
+---------------------
+git-format-patch emits diff in generated patches. For text files, the
+diff format is described as below:
+
+include::diff-generate-patch.txt[]
+

I suspect that, rather than adding a new section, it would be a better change to extend what the first parapgraph of the Description says.

The current text says something called "patch" is prepared one for each commit, it is suitable for e-mail submission, and "am" is the command to use it, but does not say what that "patch" really is. The description in the page also refers to "three-dash" line, but that is totally unclear unless the reader is given a more detailed overview of what the "patch" the first paragraph refers to (and diff-generate-patch.txt will not be the place to talk about it).

In other words, something like this one.

----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 -----
From: Junio C Hamano <[email protected]>
Date: Wed, 24 Mar 2021 10:35:40 -0700
Subject: [PATCH] format-patch: give an overview of what a "patch" message is

The text says something called a "patch" is prepared one for each commit, it is suitable for e-mail submission, and "am" is the command to use it, but does not say what the "patch" really is. The description in the page also refers to "three-dash" line, but that is totally unclear unless the reader is given a more detailed overview of what the "patch" the first paragraph refers to.

---
 Documentation/git-format-patch.txt | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Documentation/git-format-patch.txt +19 -2
index 3e49bf2210..3db0e036d8 100644
@@ -36,11 +36,28 @@ SYNOPSIS
 DESCRIPTION
 -----------
 
-Prepare each commit with its patch in
-one file per commit, formatted to resemble UNIX mailbox format.
+Prepare each commit with its "patch" in
+one "message" per commit, formatted to resemble a UNIX mailbox.
 The output of this command is convenient for e-mail submission or
 for use with 'git am'.
 
+A "message" generated by the command consists of three parts:
+
+* A brief metadata header that begins with `From <commit>`
+  with a fixed `Mon Sep 17 00:00:00 2001` datestamp to help programs
+  like "file(1)" to recognize that the file is an output from this
+  command, fields that record the author identity, the author date,
+  and the title of the change (taken from the first paragraph of the
+  commit log message).
+
+* The second and subsequent paragraphs of the commit log message.
+
+* The "patch", which is the "diff -p --stat" output (see
+  linkgit:git-diff[1]) between the commit and its parent.
+
+The log message and the patch is separated by a line with a
+three-dash line.
+
 There are two ways to specify which commits to operate on.
 
 1. A single commit, <since>, specifies that the commits leading
Signature · 1 line
2.31.0-464-gadc53f61d7
#3 lore raw

PATCH 2/2 git-format-patch: Document format for binary patch

In reply to Bagas Sanjaya

Document binary file patch formats that are different from text file patch.

---
 Documentation/git-format-patch.txt | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
Documentation/git-format-patch.txt +22 -0
index 247033f8fc..8de172b1f4 100644
@@ -725,6 +725,28 @@ diff format is described as below:
 
 include::diff-generate-patch.txt[]
 
+Binary Files
+~~~~~~~~~~~~
+For binary files, the diff format have some differences compared to text
+files:
+
+1. Object hashes in index header line (`index <hash>..<hash> <mode>`)
+   are always given in full form, as binary patch is designed to be
+   applied only to an exact copy of original file. This is to ensure
+   that such patch don't apply to file with similar name but different
+   hash.
+
+2. There are additional extended header lines specific to binary files:
+
+        GIT binary patch
+        delta <bytes>
+        literal <bytes>
+
+3. The diff body can be either delta or full (literal) content,
+   whichever is the smallest size. It is encoded with base85 algorithm,
+   and emitted in 64 characters each line. All but the last line in
+   the body are prefixed with `z`.
+
 SEE ALSO
 --------
 linkgit:git-am[1], linkgit:git-send-email[1]
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/2] git-format-patch: Document format for binary patch

Quoted 13 lines · Bagas Sanjaya

Document binary file patch formats that are different from text file patch.

---
 Documentation/git-format-patch.txt | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
Documentation/git-format-patch.txt +0 -0
index 247033f8fc..8de172b1f4 100644

Documentation/git-format-patch.txt diff format is described as below: · line 731

Quoted 7 lines
Documentation/git-format-patch.txt +4 -0
@@ -725,6 +725,28 @@ diff format is described as below:
 
 include::diff-generate-patch.txt[]
 
+Binary Files
+~~~~~~~~~~~~
+For binary files, the diff format have some differences compared to text
+files:

I do not think this is specific to 'format-patch'. If we need to describe 'git diff --binary', it should be done there, so that readers of "git diff --help" would also be able to learn the format.

Documentation/git-format-patch.txt diff format is described as below: · line 733

Quoted 1 line
Documentation/git-format-patch.txt +1 -0
+1. Object hashes in index header line (`index <hash>..<hash> <mode>`)

s/Object hash/Object name/;

Documentation/git-format-patch.txt diff format is described as below: · line 737

Quoted 4 lines
Documentation/git-format-patch.txt +4 -0
+   are always given in full form, as binary patch is designed to be
+   applied only to an exact copy of original file. This is to ensure
+   that such patch don't apply to file with similar name but different
+   hash.

... with similar but different object name.

cf. Documentation/glossary-contents.txt tells you what "object name" is.

Documentation/git-format-patch.txt diff format is described as below: · line 748

Quoted 10 lines
Documentation/git-format-patch.txt +10 -0
+2. There are additional extended header lines specific to binary files:
+
+        GIT binary patch
+        delta <bytes>
+        literal <bytes>
+
+3. The diff body can be either delta or full (literal) content,
+   whichever is the smallest size. It is encoded with base85 algorithm,
+   and emitted in 64 characters each line. All but the last line in
+   the body are prefixed with `z`.

I do not think this is all that useful; it clutters the description for a reader who is not interested in reimplementing an encoder or a decoder from the document.

And it is way too insufficient for a reader who wants to reimplement an encoder or a decoder. For example,

- It does not say anything about what the delta is and how it is computed.

- The 'z' is redundant; the more important is to say that the first byte signals how many bytes are on that line and it is a mere artifact that we cram up to 52 bytes on a line.

- It does not say anything about how the binary patch ensures that it is reversible (i.e. can be given to "git apply -R").

Thanks.

#5 lore raw

Re: [PATCH 2/2] git-format-patch: Document format for binary patch

Quoted 10 lines · Junio C Hamano

I do not think this is all that useful; it clutters the description for a reader who is not interested in reimplementing an encoder or a decoder from the document.

And it is way too insufficient for a reader who wants to reimplement an encoder or a decoder. For example,

- It does not say anything about what the delta is and how it is computed.

Quoted 9 lines

- The 'z' is redundant; the more important is to say that the first byte signals how many bytes are on that line and it is a mere artifact that we cram up to 52 bytes on a line.

- It does not say anything about how the binary patch ensures that it is reversible (i.e. can be given to "git apply -R").

Thanks.

Hmmm...

I write this patch from "naive" observation of git format-patch's behavior when given binary files in the commit.

Perhaps someone which is more familiar in base85 {en,de}coder and binary patch in general can write better documentation than what I send here.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#6 lore raw

Re: [PATCH 2/2] git-format-patch: Document format for binary patch

Quoted 16 lines · Bagas Sanjaya
Quoted 6 lines · Junio C Hamano

I do not think this is all that useful; it clutters the description for a reader who is not interested in reimplementing an encoder or a decoder from the document.
And it is way too insufficient for a reader who wants to reimplement an encoder or a decoder. For example,
- It does not say anything about what the delta is and how it is

Quoted 9 lines

computed.
- The 'z' is redundant; the more important is to say that the
first
byte signals how many bytes are on that line and it is a mere artifact that we cram up to 52 bytes on a line.
- It does not say anything about how the binary patch ensures that it is reversible (i.e. can be given to "git apply -R").
Thanks.

Quoted 7 lines

Hmmm...

I write this patch from "naive" observation of git format-patch's behavior when given binary files in the commit.

Perhaps someone which is more familiar in base85 {en,de}coder and binary patch in general can write better documentation than what I send here.

I do not mind reviewing an update to an existing document or a new document in Documentation/technical/ somewhere, if somebody is motivated enough to write the details to a degree that would allow reimplementation of the encoder and the decoder. I just do not think it belongs to the end-user-facing document of "format-patch", whose target is users of the "format-patch" command, not reimplementors of the command.