Show binary file size change in diff --stat
PATCH 1/1 Show binary file size change in diff --stat
Previously, a binary file in the diffstat would show as:
some-binary-file.bin | Bin
The space after the "Bin" was never used. This patch changes binary lines in the diffstat to be:
some-binary-file.bin | Bin +123456B -12345B
The "+" item is the size of the new version, the "-" item is the size of the old version. If a size is 0 it's not shown (although it would probably be better to treat no-file differently from zero-byte-file).
The "B" (for bytes) is shown to highlight the fact that these numbers are not "number of lines", but actual bytes.
The user can see what changed in the binary file, and how big the new file is. This is in keeping with the information in the rest of the diffstat.
The diffstat_t members "added" and "deleted" were unused when the file was binary, so this patch loads them with the file sizes in builtin_diffstat(). These figures are then read in show_stats() when the file is marked binary.
--- diff.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-)
diff.c +12 -3
@@ -808,7 +808,14 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)if (data->files[i]->is_binary) {show_name (prefix, name, len, reset, set); -printf (" Bin\n" ); +printf (" Bin " ); +if (added !=0 ) +printf ("%s+%iB%s" , add_c, added, reset); +if (added !=0 && deleted !=0 ) +printf (" " ); +if (deleted !=0 ) +printf ("%s-%iB%s" , del_c, deleted, reset); +printf ("\n" ); goto free_diffstat_file; }else if (data->files[i]->is_unmerged) {
@@ -1179,9 +1186,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,if (fill_mmfile (&mf1, one) <0 ||fill_mmfile (&mf2, two) <0 )die ("unable to read files to diff" ); -if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) +if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) { data->is_binary =1 ; -else { + data->added = mf2.size; + data->deleted = mf1.size; + }else {/* Crazy xdl interfaces.. */ xpparam_t xpp;xdemitconf_t xecfg;
Signature · 1 line
1.5.0.2.778.gdcb06
Quoted 16 lines · Andy Parkins
Previously, a binary file in the diffstat would show as:
some-binary-file.bin | BinThe space after the "Bin" was never used. This patch changes binary lines in the diffstat to be:
some-binary-file.bin | Bin +123456B -12345BThe "+" item is the size of the new version, the "-" item is the size of the old version. If a size is 0 it's not shown (although it would probably be better to treat no-file differently from zero-byte-file).
The "B" (for bytes) is shown to highlight the fact that these numbers are not "number of lines", but actual bytes.
Quoted 8 lines
The user can see what changed in the binary file, and how big the new file is. This is in keeping with the information in the rest of the diffstat.
The
diffstat_tmembers "added" and "deleted" were unused when the file was binary, so this patch loads them with the file sizes inbuiltin_diffstat(). These figures are then read inshow_stats()when the file is marked binary.
How about showing the size of the changes between the 2 files via the libxdiff binary patch function?
It would probably not be that difficult to generate a binary patch, and then derive some stats from it.
Rogan
Hi,
Quoted 2 lines · Rogan Dawes
How about showing the size of the changes between the 2 files via the libxdiff binary patch function?
I briefly considered this, too. But what would it tell you in the case of a jpg? I think it has more disadvantages than advantages...
Ciao,
Dscho
Quoted 10 lines · Johannes Schindelin
Hi,
Quoted 1 line · Rogan Dawes
How about showing the size of the changes between the 2 files via the libxdiff binary patch function?
I briefly considered this, too. But what would it tell you in the case of a jpg? I think it has more disadvantages than advantages...
Ciao,
Dscho
It would still tell you the extent of the changes. i.e. Did we change only 10 bytes of the file, or is it a dramatic change?
This is exactly what the text statistics show. +(new lines + modified lines) -(deleted lines + modified lines)
Instead of having a "line-based" record size, simply use individual bytes, since binary files don't have lines (most of them, anyway!).
Rogan
Hi,
Quoted 4 lines · Rogan Dawes
Quoted 2 lines · Johannes Schindelin
On Wed, 28 Feb 2007, Rogan Dawes wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How about showing the size of the changes between the 2 files via the libxdiff binary patch function?
I briefly considered this, too. But what would it tell you in the case of a jpg? I think it has more disadvantages than advantages...
It would still tell you the extent of the changes. i.e. Did we change only 10 bytes of the file, or is it a dramatic change?
I was not explicit enough, okay. I was not so worried about the case where only 10 bytes changed. If you insert a single dot in a jpg image, chances are that your binary content will change _a lot_.
So, no problem deducing from 10 bytes changed that it was a minor change. But you cannot deduce the opposite of a 1MB change!
Hth,
Dscho
Quoted 10 lines · Johannes Schindelin
Hi,
Quoted 6 lines · Rogan Dawes
Quoted 4 lines · Johannes Schindelin
Quoted 1 line · Rogan Dawes
How about showing the size of the changes between the 2 files via the libxdiff binary patch function?
I briefly considered this, too. But what would it tell you in the case of a jpg? I think it has more disadvantages than advantages...
Quoted 9 lines
Quoted 1 line
It would still tell you the extent of the changes. i.e. Did we change only 10 bytes of the file, or is it a dramatic change?
I was not explicit enough, okay. I was not so worried about the case where only 10 bytes changed. If you insert a single dot in a jpg image, chances are that your binary content will change _a
lot_.So, no problem deducing from 10 bytes changed that it was a minor change. But you cannot deduce the opposite of a 1MB change!
Hth,
Dscho
Yeah, I did understand that.
However, if we were to generalise, making a change to an XML document (wrapping the whole thing in an additional tag, with the associated indentation adjustments), we'd still see all the lines in the file change, even though the actual (semantic?) change is small. However, we would still report the full numbers of lines added and deleted regardless.
Why should a binary file be any different? It would be up to the observer to make a conclusion as to the significance of the numbers, based on their intrinsic knowledge of the file type, and its properties.
I just believe that showing bytes changed for binary files is _consistent_ with what we do for text.
Rogan
Hi,
Quoted 8 lines · Andy Parkins
Previously, a binary file in the diffstat would show as:
some-binary-file.bin | BinThe space after the "Bin" was never used. This patch changes binary lines in the diffstat to be:
some-binary-file.bin | Bin +123456B -12345B
This seemed as a good idea to me at first. But I think it is a little
misleading: Imagine for example that you have raw image data (which I track with Git, too). If only part of that changes, this representation is misleading.
How about "Bin 123456 -> 12345 bytes" instead?
Ciao,
Dscho
PATCH 1/1 Show binary file size change in diff --stat
Previously, a binary file in the diffstat would show as:
some-binary-file.bin | Bin
The space after the "Bin" was never used. This patch changes binary lines in the diffstat to be:
some-binary-file.bin | Bin 123456 -> 12345 bytes
The very nice "->" notation was suggested by Johannes Schindelin, and shows the before and after sizes more clearly than "+" and "-" would. If a size is 0 it's not shown (although it would probably be better to treat no-file differently from zero-byte-file).
The user can see what changed in the binary file, and how big the new file is. This is in keeping with the information in the rest of the diffstat.
The diffstat_t members "added" and "deleted" were unused when the file was binary, so this patch loads them with the file sizes in builtin_diffstat(). These figures are then read in show_stats() when the file is marked binary.
---
Good call.
I like it. "->" is much better than "+" and "-"; they would imply that a set of bytes had been removed and another set added to replace them - obviously nonsense.
diff.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
diff.c +14 -3
@@ -808,7 +808,16 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)if (data->files[i]->is_binary) {show_name (prefix, name, len, reset, set); -printf (" Bin\n" ); +printf (" Bin " ); +if (added !=0 ) +printf ("%s%i%s" , add_c, added, reset); +if (added !=0 && deleted !=0 ) +printf (" -> " ); +if (deleted !=0 ) +printf ("%s%i%s" , del_c, deleted, reset); +if (added !=0 || deleted !=0 ) +printf (" bytes" ); +printf ("\n" ); goto free_diffstat_file; }else if (data->files[i]->is_unmerged) {
@@ -1179,9 +1188,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,if (fill_mmfile (&mf1, one) <0 ||fill_mmfile (&mf2, two) <0 )die ("unable to read files to diff" ); -if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) +if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) { data->is_binary =1 ; -else { + data->added = mf2.size; + data->deleted = mf1.size; + }else {/* Crazy xdl interfaces.. */ xpparam_t xpp;xdemitconf_t xecfg;
Signature · 1 line
1.5.0.2.205.gea888-dirty
Hi,
diff.c static void show_stats(struct diffstat_t* data, struct diff_options *options) · line 813
Quoted 1 line · Andy Parkins
diff.c +1
-0+printf ("%s%i%s" , add_c, added, reset);
Please use "%d" instead of "%i" (I forgot why, but I remember Junio saying that we should do it...).
diff.c static void show_stats(struct diffstat_t* data, struct diff_options *options) · line 815
Quoted 2 lines
diff.c +2
-0+if (added !=0 && deleted !=0 ) +printf (" -> " );
Either you want to have
Bin +123456 bytes
or
Bin 0 -> 123456 bytes
for added files (and the obvious thing for deleted ones), but with your patch, both added and deleted get
Bin 123456 bytes
which is not so optimal.
Ciao,
Dscho
Quoted 6 lines · Johannes Schindelin
for added files (and the obvious thing for deleted ones), but with your patch, both added and deleted get
Bin 123456 byteswhich is not so optimal.
See my corrected patch. However, while you're interested: how would one tell the difference between 0 bytes and (no file). I'm thinking of these possibilities:
new -> 123456
0 -> 123456
123456 -> deleted
123456 -> 0
For example - does mmfile_t.ptr set to NULL mean anything?
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Hi,
Quoted 13 lines · Andy Parkins
Quoted 6 lines · Johannes Schindelin
for added files (and the obvious thing for deleted ones), but with your patch, both added and deleted get
Bin 123456 byteswhich is not so optimal.
See my corrected patch. However, while you're interested: how would one tell the difference between 0 bytes and (no file). I'm thinking of these possibilities:
Quoted 6 lines
new -> 123456
0 -> 123456
123456 -> deleted
123456 -> 0For example - does mmfile_t.ptr set to NULL mean anything?
In non-binary case, we have only plusses or minusses, so you cannot tell either. You have to look into the summary for that.
Ciao,
Dscho
PATCH 1/1 Show binary file size change in diff --stat
In reply to Johannes SchindelinPreviously, a binary file in the diffstat would show as:
some-binary-file.bin | Bin
The space after the "Bin" was never used. This patch changes binary lines in the diffstat to be:
some-binary-file.bin | Bin 12345 -> 123456 bytes
The very nice "->" notation was suggested by Johannes Schindelin, and shows the before and after sizes more clearly than "+" and "-" would.
The user can see what changed in the binary file, and how big the new file is. This is in keeping with the information in the rest of the diffstat.
The diffstat_t members "added" and "deleted" were unused when the file was binary, so this patch loads them with the file sizes in builtin_diffstat(). These figures are then read in show_stats() when the file is marked binary.
---
GAHHH!!!
Ignore previous; I forgot to swap the order of the added and deleted items. I've also removed the conditionals on the 0 byte sizes - they're always shown.
diff.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
diff.c +10 -3
@@ -808,7 +808,12 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)if (data->files[i]->is_binary) {show_name (prefix, name, len, reset, set); -printf (" Bin\n" ); +printf (" Bin " ); +printf ("%s%i%s" , del_c, deleted, reset); +printf (" -> " ); +printf ("%s%i%s" , add_c, added, reset); +printf (" bytes" ); +printf ("\n" ); goto free_diffstat_file; }else if (data->files[i]->is_unmerged) {
@@ -1179,9 +1184,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,if (fill_mmfile (&mf1, one) <0 ||fill_mmfile (&mf2, two) <0 )die ("unable to read files to diff" ); -if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) +if (mmfile_is_binary (&mf1) ||mmfile_is_binary (&mf2)) { data->is_binary =1 ; -else { + data->added = mf2.size; + data->deleted = mf1.size; + }else {/* Crazy xdl interfaces.. */ xpparam_t xpp;xdemitconf_t xecfg;
Signature · 1 line
1.5.0.2.205.gea888-dirty
Quoted 1 line · Johannes Schindelin
How about "Bin 123456 -> 12345 bytes" instead?
I agree.
Nicolas