Comments (6)
I see, thanks. For me an inline view is essential so I guess difft
won't be a good fit for me. Still, I'm happy to have tried it out. Thanks for writing it!
from difftastic.
Why would you expect line 2 to show as green? As far as I can see there are only removals on that line.
from difftastic.
Hi Wilfred, thanks for your reply. Perhaps this is an XY problem so let me put it another way.
The standard diff tool on my system has the following property: from the content of test1.hs
and the output of diff test1.hs test2.hs
I can deduce the content of test2.hs
. This seems to me to be the most essential property of a diff tool. Specifically, if test1.hs
contains
example cond =
print (if cond then 0 else 1,
if cond then 2 else 3
)
and the output of diff /tmp/test1.hs /tmp/test2.hs
is
2,3c2,4
< print (if cond then 0 else 1,
< if cond then 2 else 3
---
> print (if cond
> then (0, 2)
> else (1, 3)
then I can deduce the content of test2.hs
by replacing test1.hs
's lines 2 and 3 with the three lines in the second section of the diff
output. However, I don't understand how the same deduction is possible using the output of difft
. Perhaps I'm just unaware of the correct interpretation of the output format (or perhaps it's not supposed to be possible). Let's consider (for simplicity) the case without color, that is
difft --display=inline --color=never /tmp/test1.hs /tmp/test2.hs
The output is
/tmp/test2.hs --- Haskell
1 example cond =
2 print (if cond then 0 else 1,
3 if cond then 2 else 3
3 then (0, 2)
4 else (1, 3)
5 )
How can I deduce the content of test2.hs
knowing just the content of test1.hs
and the output of difft
? Put another way, if I were going to write the equivalent of patch
for difft
, what algorithm would I use to determine the effect of difft
's output on the original file? The difficulty here is that I don't know how I could determine that line 2 of test2.hs
is
print (if cond
from difftastic.
Difftastic does not aim to provide a valid patch. There's a brief discussion in non-goals here: https://github.com/Wilfred/difftastic#non-goals
Difftastic works out the the relationship between the two files, and highlights the parts of the AST that don't match. That's why it considers the following JSON files the same:
[100, 200, 300]
[100,
200,
300]
It might be interesting to add a mode that shows a traditional patch with the AST diff elements highlighted. This would be tricky because some line-based patches are not syntactic changes (like the example above).
from difftastic.
Sure, I don't actually want to apply the output of difft
as a patch. I'm clearly explaining myself poorly. The fact that equivalent ASTs compare as equal is important information for me to take into account, thanks. I'll try again.
I'm asking whether, in principle, knowing the content of test1.hs
and the output of difft test1.hs test2.hs
, I should be able to deduce the content of test2.hs
, modulo AST equivalence? That seems to me to be an essential property of a diffing tool, but it seems to me that difft
doesn't have that property (example given above).
If it is a goal, does difft
actually satisfy it? If not, then presumably it's a bug. If so, then can you explain how? I don't understand how to deduce the contents of test2.hs
in the example above.
from difftastic.
Yep, you should be able deduce the content of the second file modulo AST equivalence.
The inline display is harder to read, and I rarely use it. This is one of the inline display failure cases: when the line-based diff and AST diffs consider the first change to be in different lines, it's hard to render in a comprehensible way.
Here's the default display:
From this, I can deduce that I can transform the first file into the second by opening a parenthesis before the 0, removing the else 1
to get me up to the comma, and so on.
from difftastic.
Related Issues (20)
- Provide automatic display options that consider terminal width, etc.
- Error: "index out of bounds: the len is 20 but the index is 20" HOT 4
- Unchanged HTML reported as changed HOT 1
- No option to diff hidden files in directories HOT 1
- Word differ returns out-of-bounds column numbers HOT 1
- tree-sitter-lua is out-dated
- index out of bounds: the len is X but the index is X', src/display/inline.rs:115:21
- Bad error recovery from (incorrect) C preprocessor error
- Inline diff is ignoring unchanged lines between hunks
- "index out of bounds" error, panic in side_by_side.rs HOT 2
- Crash inside eshell with memory allocation error HOT 5
- Output file paths as relative to current working directory
- Feature Request: Compare Subdirectories, ignore directory name difference
- Elm diff shows no syntactic changes for changes to doc comments
- `--language` command line argument is not supported
- difft does shows single/double quote as a diff for python HOT 3
- Include line number in patch diff header
- difftastic do not show color in fzf preview
- Dynamic sublanguages (injections)
- [Question] Want to know the changes in the AST nodes of the old and new files? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from difftastic.