diffparser

package module
v0.0.0-...-361c238 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2017 License: MIT Imports: 4 Imported by: 0

README

CLA assistant

WebsiteSlackForumTwitter

DiffParser

DiffParser is a Golang package for parsing git diffs. This supports diffs containing binary files. This library is forked from http://github.com/waigani/diffparser

Install

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

Usage Example

package main

import (
	"fmt"
	"github.com/appscode/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.

Credits

This repository started as a fork of https://github.com/waigani/diffparser .

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
	OrigName string
	NewName  string
	OldMode  string
	NewMode  string
	Binary   bool
	Hunks    []*diffHunk
	Away     []string
}

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 (
	NEW FileMode = iota + 1
	MODIFIED
	DELETED
	MOVE_AWAY
	COPY_AWAY
	MOVE_HERE
	COPY_HERE
	MULTI_COPY
	MESSAGE
	CHILD
)

Jump to

Keyboard shortcuts

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