Coder Social home page Coder Social logo

gotextdiff's People

Contributors

gearcog avatar slimsag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gotextdiff's Issues

Incorrect line numbers in unified hunk headers

I believe the hunk headers (starting and ending with @@) should function similarly to those that occur when running git diff. However, this is not what occurs in the following example (Using version 1.0.3 with go 1.20).

Code

package main

import (
	"fmt"

	"github.com/hexops/gotextdiff"
	"github.com/hexops/gotextdiff/myers"
	"github.com/hexops/gotextdiff/span"
)

var old = `line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
line11
line12
line13
line14
line15
line16
`

var new = `line1
line_CHANGED
line3
line4
line_CHANGED
line_CHANGED
line7
line8
line9
line10
line11
line12
line13
line14
line_CHANGED
line16
`

func main() {
	edits := myers.ComputeEdits(span.URIFromPath("a.txt"), old, new)
	unified := gotextdiff.ToUnified("a.txt", "a.txt", old, edits)
	fmt.Println(unified)
}

Output

--- a.txt
+++ a.txt
@@ -1,9 +1,9 @@
 line1
-line2
+line_CHANGED
 line3
 line4
-line5
-line6
+line_CHANGED
+line_CHANGED
 line7
 line8
 line9
@@ -12,5 +10,5 @@
 line12
 line13
 line14
-line15
+line_CHANGED
 line16

Output when running git diff --no-index test1.txt test2.txt, where test1.txt and test2.txt have the same contents as old and new respectively

--- a/test1.txt
+++ b/test2.txt
@@ -1,9 +1,9 @@
 line1
-line2
+line_CHANGED
 line3
 line4
-line5
-line6
+line_CHANGED
+line_CHANGED
 line7
 line8
 line9
@@ -12,5 +12,5 @@ line11
 line12
 line13
 line14
-line15
+line_CHANGED
 line16

I would expect the second hunk header to be @@ -12,5 +12,5 @@ (as provided by git) instead of @@ -12,5 +10,5 @@ since the hunk below the header starts on line 12 for both the previous and modified content.

Merge algorithm is inadequate

Hello,

I'm curious if a better merge algorithm would be considered in-scope. Right now the patch always applies to the same line position regardless of context. When I found this package I was looking for something with more similar behaviour to Git, but I wasn't able to find such a thing and will need to implement it myself.

No colors

In the README, it writes that the output will be shown in colors

--- a.txt
+++ b.txt
@@ -1,13 +1,28 @@
-foo
+bar

However, there is no color if I copy-paste the code example.

--- a.txt
+++ b.txt
@@ -1,13 +1,28 @@
-foo
+bar

If that intended? If there is no support, it would be nice to add support for colors.

used extremely large amount of memory

Just comparing 2 solaris pkginfo output used about 1.5Gb of memory (attached).

	edits := myers.ComputeEdits(span.URIFromPath(""), PrevContent, Content)
	unifiedPatch := gotextdiff.ToUnified("src", "dst", PrevContent, edits)
	var DiffContent = fmt.Sprint(unifiedPatch)

	fmt.Printf("!!!! len(DiffContent):%+v\n", len(DiffContent))
/usr/bin/time -v go run scratch.go
!!!! len(DiffContent):1152378
	Command being timed: "go run scratch.go"
	User time (seconds): 2.07
	System time (seconds): 2.51
	Percent of CPU this job got: 102%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.46
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 15095320
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 5
	Minor (reclaiming a frame) page faults: 3793204
	Voluntary context switches: 3058
	Involuntary context switches: 434
	Swaps: 0
	File system inputs: 0
	File system outputs: 5640
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

solaris-sw-pkginfo.txt
prev-pkginfo.txt

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.