Skip to content

Commit c16247b

Browse files
authored
chore: tidy up function names and code comments (#69)
1 parent 9a01961 commit c16247b

23 files changed

+497
-317
lines changed

blame.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ type Blame struct {
99
lines []*Commit
1010
}
1111

12-
// Line returns the commit by given line number (1-based).
13-
// It returns nil when no such line.
12+
// Line returns the commit by given line number (1-based). It returns nil when
13+
// no such line.
1414
func (b *Blame) Line(i int) *Commit {
1515
if i <= 0 || len(b.lines) < i {
1616
return nil

blob.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type Blob struct {
1414
*TreeEntry
1515
}
1616

17-
// Bytes reads and returns the content of the blob all at once in bytes.
18-
// This can be very slow and memory consuming for huge content.
17+
// Bytes reads and returns the content of the blob all at once in bytes. This
18+
// can be very slow and memory consuming for huge content.
1919
func (b *Blob) Bytes() ([]byte, error) {
2020
stdout := new(bytes.Buffer)
2121
stderr := new(bytes.Buffer)
@@ -29,7 +29,8 @@ func (b *Blob) Bytes() ([]byte, error) {
2929
return stdout.Bytes(), nil
3030
}
3131

32-
// Pipeline reads the content of the blob and pipes stdout and stderr to supplied io.Writer.
32+
// Pipeline reads the content of the blob and pipes stdout and stderr to
33+
// supplied io.Writer.
3334
func (b *Blob) Pipeline(stdout, stderr io.Writer) error {
3435
return NewCommand("show", b.id.String()).RunInDirPipeline(stdout, stderr, b.parent.repo.path)
3536
}

command.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func (c *Command) AddEnvs(envs ...string) *Command {
5353
// DefaultTimeout is the default timeout duration for all commands.
5454
const DefaultTimeout = time.Minute
5555

56-
// A limitDualWriter writes to W but limits the amount of data written to just N bytes.
57-
// On the other hand, it passes everything to w.
56+
// A limitDualWriter writes to W but limits the amount of data written to just N
57+
// bytes. On the other hand, it passes everything to w.
5858
type limitDualWriter struct {
5959
W io.Writer // underlying writer
6060
N int64 // max bytes remaining
@@ -81,10 +81,11 @@ func (w *limitDualWriter) Write(p []byte) (int, error) {
8181
return w.w.Write(p)
8282
}
8383

84-
// RunInDirPipelineWithTimeout executes the command in given directory and timeout duration.
85-
// It pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout
86-
// duration is less than time.Nanosecond (i.e. less than or equal to 0).
87-
// It returns an ErrExecTimeout if the execution was timed out.
84+
// RunInDirPipelineWithTimeout executes the command in given directory and
85+
// timeout duration. It pipes stdout and stderr to supplied io.Writer.
86+
// DefaultTimeout will be used if the timeout duration is less than
87+
// time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout
88+
// if the execution was timed out.
8889
func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error) {
8990
if timeout < time.Nanosecond {
9091
timeout = DefaultTimeout
@@ -148,14 +149,14 @@ func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, std
148149
}
149150
}
150151

151-
// RunInDirPipeline executes the command in given directory and default timeout duration.
152-
// It pipes stdout and stderr to supplied io.Writer.
152+
// RunInDirPipeline executes the command in given directory and default timeout
153+
// duration. It pipes stdout and stderr to supplied io.Writer.
153154
func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error {
154155
return c.RunInDirPipelineWithTimeout(DefaultTimeout, stdout, stderr, dir)
155156
}
156157

157-
// RunInDirWithTimeout executes the command in given directory and timeout duration.
158-
// It returns stdout in []byte and error (combined with stderr).
158+
// RunInDirWithTimeout executes the command in given directory and timeout
159+
// duration. It returns stdout in []byte and error (combined with stderr).
159160
func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error) {
160161
stdout := new(bytes.Buffer)
161162
stderr := new(bytes.Buffer)
@@ -165,14 +166,14 @@ func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte
165166
return stdout.Bytes(), nil
166167
}
167168

168-
// RunInDir executes the command in given directory and default timeout duration.
169-
// It returns stdout and error (combined with stderr).
169+
// RunInDir executes the command in given directory and default timeout
170+
// duration. It returns stdout and error (combined with stderr).
170171
func (c *Command) RunInDir(dir string) ([]byte, error) {
171172
return c.RunInDirWithTimeout(DefaultTimeout, dir)
172173
}
173174

174-
// RunWithTimeout executes the command in working directory and given timeout duration.
175-
// It returns stdout in string and error (combined with stderr).
175+
// RunWithTimeout executes the command in working directory and given timeout
176+
// duration. It returns stdout in string and error (combined with stderr).
176177
func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error) {
177178
stdout, err := c.RunInDirWithTimeout(timeout, "")
178179
if err != nil {

commit.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func (c *Commit) Summary() string {
3737
return strings.Split(c.Message, "\n")[0]
3838
}
3939

40-
// ParentsCount returns number of parents of the commit.
41-
// It returns 0 if this is the root commit, otherwise returns 1, 2, etc.
40+
// ParentsCount returns number of parents of the commit. It returns 0 if this is
41+
// the root commit, otherwise returns 1, 2, etc.
4242
func (c *Commit) ParentsCount() int {
4343
return len(c.parents)
4444
}
@@ -52,8 +52,8 @@ func (c *Commit) ParentID(n int) (*SHA1, error) {
5252
return c.parents[n], nil
5353
}
5454

55-
// Parent returns the n-th parent commit (0-based) of this commit.
56-
// It returns ErrRevisionNotExist if no such parent exists.
55+
// Parent returns the n-th parent commit (0-based) of this commit. It returns
56+
// ErrRevisionNotExist if no such parent exists.
5757
func (c *Commit) Parent(n int, opts ...CatFileCommitOptions) (*Commit, error) {
5858
id, err := c.ParentID(n)
5959
if err != nil {
@@ -68,14 +68,14 @@ func (c *Commit) CommitByPath(opts ...CommitByRevisionOptions) (*Commit, error)
6868
return c.repo.CommitByRevision(c.ID.String(), opts...)
6969
}
7070

71-
// CommitsByPage returns a paginated list of commits in the state of this commit.
72-
// The returned list is in reverse chronological order.
71+
// CommitsByPage returns a paginated list of commits in the state of this
72+
// commit. The returned list is in reverse chronological order.
7373
func (c *Commit) CommitsByPage(page, size int, opts ...CommitsByPageOptions) ([]*Commit, error) {
7474
return c.repo.CommitsByPage(c.ID.String(), page, size, opts...)
7575
}
7676

77-
// SearchCommits searches commit message with given pattern. The returned list is in reverse
78-
// chronological order.
77+
// SearchCommits searches commit message with given pattern. The returned list
78+
// is in reverse chronological order.
7979
func (c *Commit) SearchCommits(pattern string, opts ...SearchCommitsOptions) ([]*Commit, error) {
8080
return c.repo.SearchCommits(c.ID.String(), pattern, opts...)
8181
}
@@ -90,18 +90,19 @@ func (c *Commit) CommitsCount(opts ...RevListCountOptions) (int64, error) {
9090
return c.repo.RevListCount([]string{c.ID.String()}, opts...)
9191
}
9292

93-
// FilesChangedSince returns a list of files changed after given commit ID.
93+
// FilesChangedAfter returns a list of files changed after given commit ID.
9494
func (c *Commit) FilesChangedAfter(after string, opts ...DiffNameOnlyOptions) ([]string, error) {
9595
return c.repo.DiffNameOnly(after, c.ID.String(), opts...)
9696
}
9797

98-
// CommitsAfter returns a list of commits after given commit ID up to this commit. The returned
99-
// list is in reverse chronological order.
98+
// CommitsAfter returns a list of commits after given commit ID up to this
99+
// commit. The returned list is in reverse chronological order.
100100
func (c *Commit) CommitsAfter(after string, opts ...RevListOptions) ([]*Commit, error) {
101101
return c.repo.RevList([]string{after + "..." + c.ID.String()}, opts...)
102102
}
103103

104-
// Ancestors returns a list of ancestors of this commit in reverse chronological order.
104+
// Ancestors returns a list of ancestors of this commit in reverse chronological
105+
// order.
105106
func (c *Commit) Ancestors(opts ...LogOptions) ([]*Commit, error) {
106107
if c.ParentsCount() == 0 {
107108
return []*Commit{}, nil
@@ -166,7 +167,8 @@ func (c *Commit) IsImageFile(subpath string) (bool, error) {
166167
return c.isImageFile(c.Blob(subpath))
167168
}
168169

169-
// IsImageFileByIndex returns true if the blob of the commit is an image by index.
170+
// IsImageFileByIndex returns true if the blob of the commit is an image by
171+
// index.
170172
func (c *Commit) IsImageFileByIndex(index string) (bool, error) {
171173
return c.isImageFile(c.BlobByIndex(index))
172174
}

diff.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ type diffParser struct {
215215
maxFileLines int
216216
maxLineChars int
217217

218-
// The next line that hasn't been processed. It is used to determine what kind of process should go in.
218+
// The next line that hasn't been processed. It is used to determine what kind
219+
// of process should go in.
219220
buffer []byte
220221
isEOF bool
221222
}
@@ -248,8 +249,8 @@ func (p *diffParser) parseFileHeader() (*DiffFile, error) {
248249
line := string(p.buffer)
249250
p.buffer = nil
250251

251-
// Note: In case file name is surrounded by double quotes (it happens only in git-shell).
252-
// e.g. diff --git "a/xxx" "b/xxx"
252+
// NOTE: In case file name is surrounded by double quotes (it happens only in
253+
// git-shell). e.g. diff --git "a/xxx" "b/xxx"
253254
var middle int
254255
hasQuote := line[len(diffHead)] == '"'
255256
if hasQuote {
@@ -494,9 +495,10 @@ func (p *diffParser) parse() (*Diff, error) {
494495
return diff, nil
495496
}
496497

497-
// StreamParseDiff parses the diff read from the given io.Reader. It does parse-on-read to minimize
498-
// the time spent on huge diffs. It accepts a channel to notify and send error (if any) to the caller
499-
// when the process is done. Therefore, this method should be called in a goroutine asynchronously.
498+
// StreamParseDiff parses the diff read from the given io.Reader. It does
499+
// parse-on-read to minimize the time spent on huge diffs. It accepts a channel
500+
// to notify and send error (if any) to the caller when the process is done.
501+
// Therefore, this method should be called in a goroutine asynchronously.
500502
func StreamParseDiff(r io.Reader, done chan<- SteamParseDiffResult, maxFiles, maxFileLines, maxLineChars int) {
501503
p := &diffParser{
502504
Reader: bufio.NewReader(r),

git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func log(format string, args ...interface{}) {
3333
return
3434
}
3535

36-
fmt.Fprint(logOutput, logPrefix)
37-
fmt.Fprintf(logOutput, format, args...)
38-
fmt.Fprintln(logOutput)
36+
_, _ = fmt.Fprint(logOutput, logPrefix)
37+
_, _ = fmt.Fprintf(logOutput, format, args...)
38+
_, _ = fmt.Fprintln(logOutput)
3939
}
4040

4141
var (

hook.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ const (
2222
)
2323

2424
var (
25-
// ServerSideHooks contains a list of Git hooks that are supported on the server side.
25+
// ServerSideHooks contains a list of Git hooks that are supported on the server
26+
// side.
2627
ServerSideHooks = []HookName{HookPreReceive, HookUpdate, HookPostReceive}
27-
// ServerSideHookSamples contains samples of Git hooks that are supported on the server side.
28+
// ServerSideHookSamples contains samples of Git hooks that are supported on the
29+
// server side.
2830
ServerSideHookSamples = map[HookName]string{
2931
HookPreReceive: `#!/bin/sh
3032
#
@@ -214,7 +216,7 @@ func (h *Hook) Name() HookName {
214216
return h.name
215217
}
216218

217-
// path returns the path of the Git hook.
219+
// Path returns the path of the Git hook.
218220
func (h *Hook) Path() string {
219221
return h.path
220222
}
@@ -229,8 +231,8 @@ func (h *Hook) Content() string {
229231
return h.content
230232
}
231233

232-
// Update writes the content of the Git hook on filesystem. It updates the memory copy of
233-
// the content as well.
234+
// Update writes the content of the Git hook on filesystem. It updates the
235+
// memory copy of the content as well.
234236
func (h *Hook) Update(content string) error {
235237
h.content = strings.TrimSpace(content)
236238
h.content = strings.Replace(h.content, "\r", "", -1)

0 commit comments

Comments
 (0)