Handle Edit hunks

andybalholm
Apr 2, 2023, 12:58 AM
7D7CMNN3DJ5FINFJGQVZXF5X2MYOZHXW3I4RFASPX5SKNTR44WNQC

Dependencies

Change contents

  • replacement in pristine.go at line 45
    [3.868][3.868:940]()
    // blockContaining returns the block containing the specified location,
    [3.868]
    [3.940]
    // blockStarting returns the block starting at the specified location,
  • replacement in pristine.go at line 47
    [3.970][3.970:1044]()
    func (g *Graph) blockContaining(change Hash, pos ChangePosition) *Block {
    [3.970]
    [3.1044]
    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 blocks
    return 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
    [3.1234][3.1234:1263]()
    if blocks[i].Start <= pos {
    [3.1234]
    [3.1263]
    if blocks[i].End == pos {
  • replacement in pristine.go at line 83
    [3.1285][3.1285:1297]()
    return nil
    [3.1285]
    [3.1297]
    if 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 = pos
    oldBlock.Content = oldBlock.Content[:pos-oldBlock.Start]
    oldBlock.Edges = nil
    makeEdge(change, EdgeFlagsBlock, oldBlock, newBlock)
    blocks = append(blocks, newBlock)
    sort.Sort(blockList(blocks))
    g.Index[change] = blocks
    return oldBlock
  • replacement in pristine.go at line 139
    [3.2121][3.2121:2269]()
    parent := g.blockContaining(coalesceHash(pos.Change, h), pos.Pos)
    if parent == nil || parent.End != pos.Pos {
    // TODO split blocks.
    [3.2121]
    [3.2269]
    parent := g.blockEnding(coalesceHash(pos.Change, h), pos.Pos)
    if parent == nil {
  • replacement in pristine.go at line 146
    [3.2456][3.2456:2603]()
    child := g.blockContaining(coalesceHash(pos.Change, h), pos.Pos)
    if child == nil || child.Start != pos.Pos {
    // TODO split blocks.
    [3.2456]
    [3.2603]
    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 Atom
    Local Local
    Encoding 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 Edit
    data, _, 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
    }