ydiff
ydiff copied to clipboard
Implement option to ignore deleted files
99% of the time when I'm doing a diff I am not interested in files that have been deleted. So it would be nice if cdiff had an option to suppress the inclusion of such files in its output. The obvious way to do this is to utilize git diff --irreversible-delete
(which is what I normally run when I'm not using cdiff
). The other solution is to use git diff --diff-filter=d
which is similar but also omits the diff headers for the deleted files.
FWIW, I just forked this project and made the obvious change (diff below) and it does exactly what I want. How best to make that optional behavior is TBD. The official web docs for git shows that this flag goes back to at least v1.9.0. And a stackoverflow question shows it was present as far back as 2013 (and likely further back). So it should be safe to just unilaterally use the flag without verifying whether or not the user's git command supports it.
diff --git a/cdiff.py b/cdiff.py
index acab5aa..954129f 100755
--- a/cdiff.py
+++ b/cdiff.py
@@ -63,7 +63,7 @@ COLORS = {
VCS_INFO = {
'Git': {
'probe': ['git', 'rev-parse'],
- 'diff': ['git', 'diff', '--no-ext-diff'],
+ 'diff': ['git', 'diff', '--no-ext-diff', '--irreversible-delete'],
'log': ['git', 'log', '--patch'],
},
'Mercurial': {
Question: Should not showing lines from deleted files be optional behavior rather than the default? I wonder how often people doing a side-by-side diff really want to see all the original lines. Obviously I don't since I opened this issue. If you do want to view the original file there are other ways to do so. I've been tempted to open this issue several times since I started using cdiff
. What prompted me to open an issue now was that I'm working on updating the Korn shell source and had a change that deleted several thousand lines related to the AST Vmalloc subsystem and which also updated a few hundred lines to use the system malloc. It was rather annoying that most of the cdiff
output was showing me lines from files I had deleted.
I for one really would not like this to be the default in cdiff in any mode, side-by-side or otherwise. I think your --irreversible-delete should probably be in a git configuration file if it is possible.
Hi @krader1961, thanks for the feedback. I second the opinion from @mat813 - at least it should not be default as it will surprise people (IMHO the option/behavior is not well known). I quickly glanced git supported environment variables and git-config man page, unfortunately I did not see a way to make the behavior default. But I could be wrong.
Workarounds:
- Pipe the desired diff to cdiff with
git diff -D | cdiff -s
- Just use
cdiff -s -D
, cdiff will ignore unknown option-D
and pass togit diff
Good luck with the hacking on ksh :P.
I suppose I can live with passing -D
as part of the CLI flags; specifically CDIFF_OPTIONS=-s -w0 --wrap -D
. That's fine for the moment since I'm currently using cdiff only with Git repositories. The problem is that it doesn't work if I use cdiff with other SCMs. So even if this isn't the default behavior it does seem like it should be a native cdiff flag that gets translated to whatever is appropriate for the underlying SCM.
@mat813 and @ymattw, I'm wondering if you're away that the --irreversible-delete
(or -D
) flag leaves a marker in the cdiff output. So it's still quite clear that the diff includes a deleted file. Here's an example:
31 #define dtnew(v, d, m) _dtnew(v, d, m, CDT_VERSION) 30 #define dtnew(d, m) _dtnew(d, m, CDT_VERSION)
32 31
33 #endif 32 #endif
diff --git a/src/lib/libast/include/vmalloc.h b/src/lib/libast/include/vmalloc.h
deleted file mode 100644
index 04094de2..00000000
diff --git a/src/lib/libast/meson.build b/src/lib/libast/meson.build
index c2bb72f0..236c4c9d 100644
--- a/src/lib/libast/meson.build
+++ b/src/lib/libast/meson.build
@@ -3,7 +3,7 @@
3 libast_files = [meson.build_root() + '/src/lib/libast/comp/conftab.c'] 3 libast_files = [meson.build_root() + '/src/lib/libast/comp/conftab.c']
4 libast_incdir = include_directories('include', 'features', 'aso', 'cdt', 'comp', 4 libast_incdir = include_directories('include', 'features', 'aso', 'cdt', 'comp',
5 'sfio', 'path', 'port', 'string', 'misc', 5 'sfio', 'path', 'port', 'string', 'misc',
6 'vmalloc', 'tm') 6 'tm')
Maybe cdiff needs to grow more env variables, like CDIFF_<scm>_OPTIONS
, you could then simply set CDIFF_GIT_OPTIONS=-D
.
Thanks for the ideas. If this has to be done, I tend to parse the diff hunks to recognize deleted files (@@ -1,45 +0,0 @@
) and ignore the content with a new option.
FYI I renamed the script (and this project) to ydiff
to avoid conflict with some other program, CDIFF_OPTIONS
will be deprecated soon (replaced by YDIFF_OPTIONS
).