git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import "context"
 4
 5// CatFileBlobOptions contains optional arguments for verifying the objects.
 6//
 7// Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt
 8type CatFileBlobOptions struct {
 9	CommandOptions
10}
11
12// CatFileBlob returns the blob corresponding to the given revision of the repository.
13func (r *Repository) CatFileBlob(ctx context.Context, rev string, opts ...CatFileBlobOptions) (*Blob, error) {
14	var opt CatFileBlobOptions
15	if len(opts) > 0 {
16		opt = opts[0]
17	}
18
19	// Type conversions work because all three option types share the same
20	// underlying structure (CommandOptions only).
21	rev, err := r.RevParse(ctx, rev, RevParseOptions(opt)) //nolint
22	if err != nil {
23		return nil, err
24	}
25
26	typ, err := r.CatFileType(ctx, rev, CatFileTypeOptions(opt))
27	if err != nil {
28		return nil, err
29	}
30
31	if typ != ObjectBlob {
32		return nil, ErrNotBlob
33	}
34
35	return &Blob{
36		TreeEntry: &TreeEntry{
37			mode: EntryBlob,
38			typ:  ObjectBlob,
39			id:   MustIDFromString(rev),
40			parent: &Tree{
41				repo: r,
42			},
43		},
44	}, nil
45}