MCPcopy
hub / github.com/sinclairtarget/git-who / ParseArgs

Function ParseArgs

internal/git/args.go:15–61  ·  view source on GitHub ↗

Handles splitting the Git revisions from the pathspecs given a list of args. We call git rev-parse to disambiguate.

(args []string)

Source from the content-addressed store, hash-verified

13//
14// We call git rev-parse to disambiguate.
15func ParseArgs(args []string) (revs []string, pathspecs []string, err error) {
16 ctx, cancel := context.WithCancel(context.Background())
17 defer cancel()
18
19 subprocess, err := cmd.RunRevParse(ctx, args)
20 if err != nil {
21 return nil, nil, fmt.Errorf("could not parse args: %w", err)
22 }
23
24 lines, finish := subprocess.StdoutLines()
25
26 revs = []string{}
27 pathspecs = []string{}
28
29 pastRevs := false
30 for line := range lines {
31 if !pastRevs && rev.IsFullHash(line) {
32 revs = append(revs, line)
33 } else {
34 pastRevs = true
35
36 if line != "--" {
37 // If user used backslashes as path separator on windows,
38 // we want to turn into forward slashes
39 pathspecs = append(pathspecs, filepath.ToSlash(line))
40 }
41 }
42 }
43
44 err = finish()
45 if err != nil {
46 err = fmt.Errorf("failed reading output of rev-parse: %w", err)
47 return nil, nil, err
48 }
49
50 err = subprocess.Wait()
51 if err != nil {
52 return nil, nil, err
53 }
54
55 if len(revs) == 0 {
56 // Default rev
57 revs = append(revs, "HEAD")
58 }
59
60 return revs, pathspecs, nil
61}

Callers 8

tableCmdFunction · 0.92
treeCmdFunction · 0.92
histCmdFunction · 0.92
dumpCmdFunction · 0.92
parseCmdFunction · 0.92
TestParseArgsFunction · 0.92
TestParseArgsErrorFunction · 0.92
TestParseArgsRangeFunction · 0.92

Calls 3

RunRevParseFunction · 0.92
StdoutLinesMethod · 0.80
WaitMethod · 0.80

Tested by 3

TestParseArgsFunction · 0.74
TestParseArgsErrorFunction · 0.74
TestParseArgsRangeFunction · 0.74