curran / curran/google-diff-match-patch

diff_cleanupSemantic sometimes produces much worse results (visually)

Aperta
#67 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
auto-migrated Priority-Medium Type-Defect
Lingua principale
Python
Stelle
17
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

```
What steps will reproduce the problem?
Call diff_cleanupSemantic with the results of diff_main.

What is the expected output? What do you see instead?
I expect the output to be at least as visually ‘clean’ as with no
diff_cleanupSemantic call.
Sometimes the output is much worse after the diff_cleanupSemantic call.

What version of the product are you using? On what operating system?
JavaScript version, r103.

Please provide any additional information below.

I’ve been using DMP for a few years now to display diffs to text files before
svn commits. (Thank you.)
I sometimes see results that don’t look as I would expect (or like).
I’ve finally tracked it down to a simple example.
I always call diff_cleanupSemantic after diff_main as the final output is for
user display.
The outputs that result from this appear to vary
unexpectedly/uncontrollably/randomly.

The following small example produces a poor display after diff_cleanupSemantic,
but a slightly better display if each tab is replaced with 2 spaces, better
still with 6 spaces. However, if you replace all occurrences of 'comment' with
'ABC' then the output is barely changed after the diff_cleanupSemantic calls in
each case.

T1='BEGIN\n\tUInt16\tflaps;\n\taabb\tfat_mood:1;\n\txxyy\tisthing:1;\n\tccdd\ttr
ee_climb:1;\n\tUInt8\tflick:5;\nEND';
T2='BEGIN\n\tUInt16\tflaps;\t\t// first comment\n\taabb\tfat_mood:1;\t\t//
second comment\n\txxyy\tisthing:1;'+
'\t// third comment\n\tccdd\ttree_climb:1;\t// forth comment\n\tUInt8\tflick:3;\t// fifth comment\nEND';
diffs=DMP.diff_main(T1, T2)

diffs =>
BEGIN¬
UInt16 flaps; // first comment¬
aabb fat_mood:1; // second comment¬
xxyy isthing:1; // thrid comment¬
ccdd tree_climb:1; // forth comment¬
UInt8 flick:53; // fifth comment¬
END

diff_cleanupSemantic(diffs) =>
BEGIN¬
UInt16 flaps;¬
aabb fat_mood:1;¬
xxyy isthing:1;¬
ccdd tree_climb:1;¬
UInt8 flick:5;
// first comment¬
aabb fat_mood:1; // second comment¬
xxyy isthing:1; // thrid comment¬
ccdd tree_climb:1; // forth comment¬
UInt8 flick:3; // fifth comment
¬
END

While the second has less elements than the first it cannot be said to meet the
intent to “Increase human readability by factoring out commonalities which
are likely to be coincidental”.

The attached HTML file, when dropped in the diff_match_patch/javascript folder
& opened in a browser, fully illustrates the problem.
```

Original issue reported on code.google.com by `chris...@gmail.com` on 30 Mar 2012 at 2:46

Attachments:
- [DMP-cleanupSemantic-problem.html](https://storage.googleapis.com/google-code-attachments/google-diff-match-patch/issue-67/comment-0/DMP-cleanupSemantic-problem.html)

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Apri il file allegato DMP-cleanupSemantic-problem.html in un browser e riproduci l’esempio usando diff_main seguito da diff_cleanupSemantic nell’implementazione JavaScript. Confronta l’output visualizzato prima e dopo la pulizia, quindi determina se il risultato preserva le somiglianze visive segnalate senza peggiorare il diff.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.