( ctx context.Context, repoPath string, alternateObjectDirs []string, ref string, page int, limit int, filter CommitFilter, )
| 92 | } |
| 93 | |
| 94 | func (g *Git) listCommitSHAs( |
| 95 | ctx context.Context, |
| 96 | repoPath string, |
| 97 | alternateObjectDirs []string, |
| 98 | ref string, |
| 99 | page int, |
| 100 | limit int, |
| 101 | filter CommitFilter, |
| 102 | ) ([]sha.SHA, error) { |
| 103 | cmd := command.New("rev-list") |
| 104 | |
| 105 | // return commits only up to a certain reference if requested |
| 106 | if filter.AfterRef != "" { |
| 107 | // ^REF tells the rev-list command to return only commits that aren't reachable by SHA |
| 108 | cmd.Add(command.WithArg(fmt.Sprintf("^%s", filter.AfterRef))) |
| 109 | } |
| 110 | // add refCommitSHA as starting point |
| 111 | cmd.Add(command.WithArg(ref)) |
| 112 | |
| 113 | cmd.Add(command.WithAlternateObjectDirs(alternateObjectDirs...)) |
| 114 | |
| 115 | if len(filter.Path) != 0 { |
| 116 | cmd.Add(command.WithPostSepArg(filter.Path)) |
| 117 | } |
| 118 | |
| 119 | // add pagination if requested |
| 120 | // TODO: we should add absolut limits to protect git (return error) |
| 121 | if limit > 0 { |
| 122 | cmd.Add(command.WithFlag("--max-count", strconv.Itoa(limit))) |
| 123 | |
| 124 | if page > 1 { |
| 125 | cmd.Add(command.WithFlag("--skip", strconv.Itoa((page-1)*limit))) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if filter.Since > 0 || filter.Until > 0 { |
| 130 | cmd.Add(command.WithFlag("--date", "unix")) |
| 131 | } |
| 132 | if filter.Since > 0 { |
| 133 | cmd.Add(command.WithFlag("--since", strconv.FormatInt(filter.Since, 10))) |
| 134 | } |
| 135 | if filter.Until > 0 { |
| 136 | cmd.Add(command.WithFlag("--until", strconv.FormatInt(filter.Until, 10))) |
| 137 | } |
| 138 | if filter.Regex { |
| 139 | cmd.Add(command.WithFlag("-E")) |
| 140 | } |
| 141 | if filter.Committer != "" { |
| 142 | cmd.Add(command.WithFlag("--committer", filter.Committer)) |
| 143 | } |
| 144 | if filter.Author != "" { |
| 145 | cmd.Add(command.WithFlag("--author", filter.Author)) |
| 146 | } |
| 147 | output := &bytes.Buffer{} |
| 148 | err := cmd.Run(ctx, command.WithDir(repoPath), command.WithStdout(output)) |
| 149 | if cErr := command.AsError(err); cErr != nil && cErr.IsExitCode(128) { |
| 150 | if cErr.IsAmbiguousArgErr() || cErr.IsBadObject() { |
| 151 | return []sha.SHA{}, nil // return an empty list if reference doesn't exist |
no test coverage detected