diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-10-14 18:09:12 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-10-15 09:08:36 +0000 |
| commit | 80c2f74093e9dad96ec26cec4ef7869762cbbb36 (patch) | |
| tree | 7a3141250840ca4e7e22ca7f1023364f0032b21f /pkg/vcs/git.go | |
| parent | 42d3a37026616a8cb3a9da11ab8e5565ca6b6074 (diff) | |
pkg/vcs: expose commit patch
Add Commit.Patch with patch body.
Diffstat (limited to 'pkg/vcs/git.go')
| -rw-r--r-- | pkg/vcs/git.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index dd1681157..7425066d2 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -242,11 +242,25 @@ func (git *git) Contains(commit string) (bool, error) { } func (git *git) Commit(com string) (*Commit, error) { - output, err := git.git("log", "--format=%H%n%s%n%ae%n%an%n%ad%n%P%n%cd%n%b", "-n", "1", com) + const patchSeparator = "---===syzkaller-patch-separator===---" + output, err := git.git("log", "--format=%H%n%s%n%ae%n%an%n%ad%n%P%n%cd%n%b"+patchSeparator, + "-n", "1", "-p", "-U0", com) if err != nil { return nil, err } - return gitParseCommit(output, nil, nil, git.ignoreCC) + pos := bytes.Index(output, []byte(patchSeparator)) + if pos == -1 { + return nil, fmt.Errorf("git log output does not contain patch separator") + } + commit, err := gitParseCommit(output[:pos], nil, nil, git.ignoreCC) + if err != nil { + return nil, err + } + commit.Patch = output[pos+len(patchSeparator):] + for len(commit.Patch) != 0 && commit.Patch[0] == '\n' { + commit.Patch = commit.Patch[1:] + } + return commit, nil } func gitParseCommit(output, user, domain []byte, ignoreCC map[string]bool) (*Commit, error) { |
