Handle Edit hunks
Dependencies
- [2]
TLR47XSAParse AddRoot hunk - [3]
EYPCPIP7Apply changes and build a graph - [*]
EVHNGDT7parse FileAdd hunk
Change contents
- replacement in pristine.go at line 45
// blockContaining returns the block containing the specified location,// blockStarting returns the block starting at the specified location, - replacement in pristine.go at line 47
func (g *Graph) blockContaining(change Hash, pos ChangePosition) *Block {func (g *Graph) blockStarting(change Hash, pos ChangePosition) *Block {blocks := g.Index[change]if len(blocks) == 0 {return nil}i := sort.Search(len(blocks), func(i int) bool {return blocks[i].Start >= pos})if i == len(blocks) {return nil}if blocks[i].Start == pos {return blocks[i]}// TODO: split blocksreturn nil}// blockEnding returns the block ending at the specified location, or nil if// it is not found.func (g *Graph) blockEnding(change Hash, pos ChangePosition) *Block { - replacement in pristine.go at line 80
if blocks[i].Start <= pos {if blocks[i].End == pos { - replacement in pristine.go at line 83
return nilif blocks[i].Start >= pos {return nil}// Split the block.oldBlock := blocks[i]newBlock := &Block{Change: change,Start: pos,End: oldBlock.End,Content: oldBlock.Content[pos-oldBlock.Start:],Edges: oldBlock.Edges,}oldBlock.End = posoldBlock.Content = oldBlock.Content[:pos-oldBlock.Start]oldBlock.Edges = nilmakeEdge(change, EdgeFlagsBlock, oldBlock, newBlock)blocks = append(blocks, newBlock)sort.Sort(blockList(blocks))g.Index[change] = blocksreturn oldBlock - replacement in pristine.go at line 139
parent := g.blockContaining(coalesceHash(pos.Change, h), pos.Pos)if parent == nil || parent.End != pos.Pos {// TODO split blocks.parent := g.blockEnding(coalesceHash(pos.Change, h), pos.Pos)if parent == nil { - replacement in pristine.go at line 146
child := g.blockContaining(coalesceHash(pos.Change, h), pos.Pos)if child == nil || child.Start != pos.Pos {// TODO split blocks.child := g.blockStarting(coalesceHash(pos.Change, h), pos.Pos)if child == nil { - edit in hunk.go at line 191[5.3441][2.0]
case 6:return edit(data) - edit in hunk.go at line 253[2.287][5.4158]
}type Edit struct {Change AtomLocal LocalEncoding string - edit in hunk.go at line 260[5.4160]
func (e Edit) atoms() []Atom {return []Atom{e.Change}}func edit(data []byte) ([]byte, Edit, error) {var e Editdata, _, err := tuple(assign(&e.Change, atom),assign(&e.Local, local),assign(&e.Encoding, mapValue(option(toString(lengthData(uint64LE))), func(p *string) string {if p == nil {return ""}return *p})),)(data)return data, e, err}