Skip to content

Commit 92b3564

Browse files
committed
refactor: refactor variable names and function arguments for code readability
- Change the variable name `newFileLists` to `excludedFiles` - Refactor to return `excludedFiles` instead of `newFileLists` - Use a separate variable `excludedFiles` to store the excluded files list - Pass `excludedFiles` as an argument to `args` in `diffNames` and `diffFiles` functions - Add comments to improve code readability Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
1 parent b114586 commit 92b3564

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

git/git.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ type Command struct {
2929
}
3030

3131
func (c *Command) excludeFiles() []string {
32-
newFileLists := []string{}
32+
var excludedFiles []string
3333
for _, f := range c.excludeList {
34-
newFileLists = append(newFileLists, ":(exclude)"+f)
34+
excludedFiles = append(excludedFiles, ":(exclude)"+f)
3535
}
36-
37-
return newFileLists
36+
return excludedFiles
3837
}
3938

4039
func (c *Command) diffNames() *exec.Cmd {
@@ -49,7 +48,8 @@ func (c *Command) diffNames() *exec.Cmd {
4948
args = append(args, "--staged")
5049
}
5150

52-
args = append(args, c.excludeFiles()...)
51+
excludedFiles := c.excludeFiles()
52+
args = append(args, excludedFiles...)
5353

5454
return exec.Command(
5555
"git",
@@ -71,7 +71,8 @@ func (c *Command) diffFiles() *exec.Cmd {
7171
args = append(args, "--staged")
7272
}
7373

74-
args = append(args, c.excludeFiles()...)
74+
excludedFiles := c.excludeFiles()
75+
args = append(args, excludedFiles...)
7576

7677
return exec.Command(
7778
"git",
@@ -195,17 +196,21 @@ func (c *Command) UninstallHook() error {
195196
}
196197

197198
func New(opts ...Option) *Command {
199+
// Instantiate a new config object with default values
198200
cfg := &config{}
199201

200-
// Loop through each option
202+
// Loop through each option passed as argument and apply it to the config object
201203
for _, o := range opts {
202-
// Call the option giving the instantiated
203204
o.apply(cfg)
204205
}
205206

206-
return &Command{
207+
// Instantiate a new Command object with the configurations from the config object
208+
cmd := &Command{
207209
diffUnified: cfg.diffUnified,
210+
// Append the user-defined excludeList to the default excludeFromDiff
208211
excludeList: append(excludeFromDiff, cfg.excludeList...),
209212
isAmend: cfg.isAmend,
210213
}
214+
215+
return cmd
211216
}

0 commit comments

Comments
 (0)