filecache

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElideUnifiedDiff

func ElideUnifiedDiff(diff string, contextLines int) string

ElideUnifiedDiff takes a unified diff and limits context lines around changes

func GenerateElidedUnifiedDiff

func GenerateElidedUnifiedDiff(oldContent, newContent []byte, filename string, contextLines int) string

GenerateElidedUnifiedDiff creates a unified diff with context limiting

Types

type DiffLine

type DiffLine struct {
	Type    DiffLineType // Type of line (add, remove, context)
	Content string       // Content of the line
	OldLine int          // Line number in old file (0 if not applicable)
	NewLine int          // Line number in new file (0 if not applicable)
}

DiffLine represents a single line in a diff with its type

func ParseUnifiedDiff

func ParseUnifiedDiff(diff string) []DiffLine

ParseUnifiedDiff parses a unified diff into structured diff lines with line numbers

type DiffLineType

type DiffLineType int

DiffLineType represents the type of a diff line

const (
	DiffLineContext  DiffLineType = iota // Unchanged line
	DiffLineAdd                          // Added line (+)
	DiffLineRemove                       // Removed line (-)
	DiffLineHeader                       // File header (---, +++)
	DiffLineLocation                     // Hunk header (@@)
	DiffLineElided                       // Elided content marker (...)
)

type FileCache

type FileCache struct {
	// contains filtered or unexported fields
}

FileCache caches file contents for diff generation

func New

func New() *FileCache

New creates a new file cache

func (*FileCache) Cleanup

func (fc *FileCache) Cleanup()

Cleanup removes old entries from the cache

func (*FileCache) GenerateDiff

func (fc *FileCache) GenerateDiff(pid uint32, fd int32, pathHash uint32, offset uint64, newContent []byte) (string, bool)

GenerateDiff compares cached content with new write content

func (*FileCache) GenerateUnifiedDiff

func (fc *FileCache) GenerateUnifiedDiff(pid uint32, fd int32, pathHash uint32, offset uint64, newContent []byte, filename string) (string, bool)

GenerateUnifiedDiff generates a unified diff format

func (*FileCache) GetContentForDiff

func (fc *FileCache) GetContentForDiff(pid uint32, fd int32, pathHash uint32, offset uint64) (*FileContent, bool)

GetContentForDiff retrieves cached content for diff comparison

func (*FileCache) Size

func (fc *FileCache) Size() int

Size returns the number of cached entries

func (*FileCache) StoreReadContent

func (fc *FileCache) StoreReadContent(pid uint32, fd int32, pathHash uint32, content []byte, offset uint64)

StoreReadContent stores content from a read operation

func (*FileCache) UpdateWriteContent

func (fc *FileCache) UpdateWriteContent(pid uint32, fd int32, pathHash uint32, content []byte, offset uint64)

UpdateWriteContent updates the cache with new write content

type FileContent

type FileContent struct {
	Content   []byte
	Hash      string
	Timestamp time.Time
	Offset    uint64
	Size      uint64
}

FileContent represents cached file content

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL