diffparser

package module
v0.0.0-...-ccf7661 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2016 License: MIT Imports: 6 Imported by: 0

README

DiffParser

DiffParser is a Golang package which parse's a git diff.

Install

go get http://github.com/waigani/diffparser

Usage Example

package main

import (
	"fmt"
	"github.com/waigani/diffparser"
)

// error handling left out for brevity
func main() {
	byt, _ := ioutil.ReadFile("example.diff")
	diff, _ := diffparser.Parse(string(byt))

	// You now have a slice of files from the diff,
	file := diff.Files[0]

	// diff hunks in the file,
	hunk := file.Hunks[0]

	// new and old ranges in the hunk
	newRange := hunk.NewRange

	// and lines in the ranges.
	line := newRange.Lines[0]
}

More Examples

See diffparser_test.go for further examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Files []*DiffFile
	Raw   string `sql:"type:text"`

	PullID uint `sql:"index"`
}

func Parse

func Parse(diffString string) (*Diff, error)

Parse takes a diff, such as produced by "git diff", and parses it into a Diff struct.

func (*Diff) Changed

func (d *Diff) Changed() map[string][]int

Changed returns a map of filename to lines changed in that file. Deleted files are ignored.

type DiffFile

type DiffFile struct {
	Mode      FileMode
	Hash      string
	OrigName  string
	NewName   string
	Additions int
	Deletions int
	Hunks     []*diffHunk
}

type DiffLine

type DiffLine struct {
	Mode     DiffLineMode
	Number   int
	Content  string
	Position int // the line in the diff
}

type DiffLineMode

type DiffLineMode int
const (
	ADDED DiffLineMode = iota
	REMOVED
	UNCHANGED
)

type FileMode

type FileMode int
const (
	DELETED FileMode = iota
	MODIFIED
	NEW
)

Jump to

Keyboard shortcuts

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