Giter Club home page Giter Club logo

diffstat-snapshots's Introduction

$Id: README,v 1.5 2001/10/11 00:23:46 tom Exp $

Readme file for DiffStat.

This program is a simple filter that reads the output of the 'diff' program,
and produces a histogram of the total number of lines that were changed.  It is
useful for scanning a patch file to see which files were changed.

diffstat-snapshots's People

Contributors

thomasdickey avatar

Stargazers

Andy Shevchenko avatar Brian Inglis avatar

Watchers

James Cloos avatar  avatar  avatar

diffstat-snapshots's Issues

Trailing slashes in diff -r can cause diffstat to identify changes incorrectly.

Hello,

I have made the following discovery and also know a simple workaround in the shell how to avoid it, without changing diffstat's source code.

However, in case you're considering fixing this issue inside the diffstat code... here are my findings:

OS Release:

cat /etc/os-release

Output:

NAME="openSUSE Tumbleweed"
# VERSION="20211228"
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
VERSION_ID="20211228"
PRETTY_NAME="openSUSE Tumbleweed"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:tumbleweed:20211228"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Tumbleweed"
LOGO="distributor-logo-Tumbleweed"

Diff version:

diff --version

Output:

diff (GNU diffutils) 3.8
Packaged by openSUSE
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.

Diffstat version:

diffstat --version

Output:

diffstat version 1.64

Setup the test playground:

mkdir -p ~/tmp/diffstat_tests
cd ~/tmp/diffstat_tests
mkdir A B
touch A/old_file.txt
touch B/new_file.txt
touch A/common_file.txt
touch B/common_file.txt
ls -lR > A/common_file.txt
ls -lR > B/common_file.txt

Regular diff run:

diff -ur A B

Output:

diff -ur A/common_file.txt B/common_file.txt
--- A/common_file.txt   2022-01-01 14:51:14.228516014 +0100
+++ B/common_file.txt   2022-01-01 14:51:19.656661982 +0100
@@ -4,10 +4,10 @@
 
 ./A:
 Permissions Size User    Date Modified    Name
-.rw-------     0 paxsali 2022-01-01 14:51 common_file.txt
+.rw-------   467 paxsali 2022-01-01 14:51 common_file.txt
 .rw-------     0 paxsali 2022-01-01 14:49 old_file.txt
 
 ./B:
 Permissions Size User    Date Modified    Name
-.rw-------     0 paxsali 2022-01-01 14:50 common_file.txt
+.rw-------   188 paxsali 2022-01-01 14:51 common_file.txt
 .rw-------     0 paxsali 2022-01-01 14:49 new_file.txt
Only in B: new_file.txt
Only in A: old_file.txt

Pipe output through diffstat:

diff -ur A B | diffstat -C -K

Output:

 A/old_file.txt    |deleted
 B/common_file.txt |    4 ++--
 B/new_file.txt    |added
 3 files changed, 2 insertions(+), 2 deletions(-), 1 file added, 1 file removed

Notice the output is correct and the added and deleted files are correctly identified.

Regular diff, but with trailing slashes:

diff -ur A/ B/

Output:

diff -ur A/common_file.txt B/common_file.txt
--- A/common_file.txt   2022-01-01 14:51:14.228516014 +0100
+++ B/common_file.txt   2022-01-01 14:51:19.656661982 +0100
@@ -4,10 +4,10 @@
 
 ./A:
 Permissions Size User    Date Modified    Name
-.rw-------     0 paxsali 2022-01-01 14:51 common_file.txt
+.rw-------   467 paxsali 2022-01-01 14:51 common_file.txt
 .rw-------     0 paxsali 2022-01-01 14:49 old_file.txt
 
 ./B:
 Permissions Size User    Date Modified    Name
-.rw-------     0 paxsali 2022-01-01 14:50 common_file.txt
+.rw-------   188 paxsali 2022-01-01 14:51 common_file.txt
 .rw-------     0 paxsali 2022-01-01 14:49 new_file.txt
Only in B/: new_file.txt
Only in A/: old_file.txt

Pipe diff with trailing slashes through diffstat:

diff -ur A/ B/ | diffstat -C -K

Output:

 A//old_file.txt   |deleted
 B//new_file.txt   |deleted
 B/common_file.txt |    4 ++--
 3 files changed, 2 insertions(+), 2 deletions(-), 2 files removed

Now the output is A) unusual, because of the double-slashes in the filenames and B) incorrect, since both files are labeled deleted.

Workaround is to remove trailing slashes on "Only in DIR/: FILE" lines.

Both of the following commands produce the same output (including any combination of A/ B, A B/):

diff -ur A/ B/ | sed '/^Only in /s/\/:/:/' | diffstat -C -K

diff -ur A B | sed '/^Only in /s/\/:/:/' | diffstat -C -K

Output:

 A/old_file.txt    |deleted
 B/common_file.txt |    4 ++--
 B/new_file.txt    |added
 3 files changed, 2 insertions(+), 2 deletions(-), 1 file added, 1 file removed

I'll consider providing a patch, but I'm not a C programmer, so I'd have to read up and test some things out first.

Please consider patching this on the diffstat side, because I can see some legitimate ambiguity on the question of where to address this issue.
It may as well have been addressed over at the guys from https://savannah.gnu.org/projects/diffutils/ to the original diff utility.
However, IMHO it may be more appropriate to fix this here rather than in diff itself.

Thanks. And happy new year, btw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.