func AddedLines(patch string) (map[int]int, error) {
	result := make(map[int]int)
	if patch == "" {
		return result, nil
	}
	lines := strings.Split(patch, "\n")
	for i := 0; i < len(lines); i++ {
		// dodge the "\ No newline at end of file" line
		if lines[i] == "\\ No newline at end of file" {
			continue
		}
		_, oldLen, newLine, newLen, err := parseHunkLine(lines[i])
		if err != nil {
			return nil, fmt.Errorf("couldn't parse hunk on line %d in patch %s: %v", i, patch, err)
		}
		oldAdd := 0
		newAdd := 0
		for oldAdd < oldLen || newAdd < newLen {
			i++
			if i >= len(lines) {
				return nil, fmt.Errorf("invalid patch: %s", patch)
			}
			switch lines[i][0] {
			case ' ':
				oldAdd++
				newAdd++
			case '-':
				oldAdd++
			case '+':
				result[newLine+newAdd] = i
				newAdd++
			default:
				return nil, fmt.Errorf("bad prefix on line %d in patch %s", i, patch)
			}
		}
	}
	return result, nil
}
func AddedLines(patch string) (map[int]int, error) {
	result := make(map[int]int)
	if patch == "" {
		return result, nil
	}
	lines := strings.Split(patch, "\n")
	for i := 0; i < len(lines); i++ {
		
		if lines[i] == "\\ No newline at end of file" {
			continue
		}
		_, oldLen, newLine, newLen, err := parseHunkLine(lines[i])
		if err != nil {
			return nil, fmt.Errorf("couldn't parse hunk on line %d in patch %s: %v", i, patch, err)
		}
		oldAdd := 0
		newAdd := 0
		for oldAdd < oldLen || newAdd < newLen {
			i++
			if i >= len(lines) {
				return nil, fmt.Errorf("invalid patch: %s", patch)
			}
			switch lines[i][0] {
			case ' ':
				oldAdd++
				newAdd++
			case '-':
				oldAdd++
			case '+':
				result[newLine+newAdd] = i
				newAdd++
			default:
				return nil, fmt.Errorf("bad prefix on line %d in patch %s", i, patch)
			}
		}
	}
	return result, nil
}
func AddedLines ( patch string ) ( map [ int ] int , error ) { result := make ( map [ int ] int ) if patch == " " { return result , nil } lines := strings . Split ( patch , " \n " ) for i := 0 ; i < len ( lines ) ; i ++ { // dodge the "\ No newline at end of file" line if lines [ i ] == " \\ " { continue } _ , oldLen , newLine , newLen , err := parseHunkLine ( lines [ i ] ) if err != nil { return nil , fmt . Errorf ( " " , i , patch , err ) } oldAdd := 0 newAdd := 0 for oldAdd < oldLen || newAdd < newLen { i ++ if i >= len ( lines ) { return nil , fmt . Errorf ( " " , patch ) } switch lines [ i ] [ 0 ] { case ' ' : oldAdd ++ newAdd ++ case '-' : oldAdd ++ case '+' : result [ newLine + newAdd ] = i newAdd ++ default : return nil , fmt . Errorf ( " " , i , patch ) } } } return result , nil }
// AddedLines returns line numbers that were added in the patch, along with
// their line in the patch itself as a map from line to patch line.
// https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Unified
// GitHub omits the ---/+++ lines since that information is in the
// PullRequestChange object.
AddedLines returns line numbers that were added in the patch along with their line in the patch itself as a map from line to patch line . https : // www . gnu . org / software / diffutils / manual / diffutils . html#Detailed - Unified GitHub omits the --- / +++ lines since that information is in the PullRequestChange object .