Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

git: worktree, add Grep() method for git grep #686

Merged
merged 4 commits into from
Dec 12, 2017

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented Dec 9, 2017

This change implemented grep on worktree with options to match ignoring case, invert match and specify pathspec. Also, a commit hash or reference can be used to specify the worktree to search.

options.go Outdated
// GrepOptions describes how a grep should be performed.
type GrepOptions struct {
// Pattern is the match pattern.
Pattern string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Itstead of accepting a string, I would prefer a *regexp.Regexp with this the people can speed that the process with precompilled expressions.

options.go Outdated
// Pattern is the match pattern.
Pattern string
// IgnoreCase enables case insensitive match.
IgnoreCase bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we accept the type instead of the string, this is not need it.

worktree.go Outdated
}

// Iterate through the files and look for any matches.
err = fileiter.ForEach(func(file *object.File) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put this code in a private function?

worktree_test.go Outdated
TreeName: "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the open and close brace in the same line.

Signed-off-by: Sunny <me@darkowlzz.space>
Signed-off-by: Sunny <me@darkowlzz.space>
Signed-off-by: Sunny <me@darkowlzz.space>
Signed-off-by: Sunny <me@darkowlzz.space>
@darkowlzz
Copy link
Contributor Author

  • Changed GrepOptions to accept precompiled regexp objects for Pattern and PathSpec
  • Moved the file iteration and pattern matching code to a separate private function findMatchInFiles()
  • Changed the table test struct format
  • Updated compatibility doc

@mcuadros mcuadros merged commit 757a260 into src-d:master Dec 12, 2017
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants