Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds .tsuruignore file support #25

Merged
merged 8 commits into from
Feb 13, 2017
Merged

Conversation

arxdsilva
Copy link
Contributor

@arxdsilva arxdsilva commented Feb 8, 2017

c.Assert(headers, check.DeepEquals, expected)
}

func (s *S) TestIgnoreRelativeFolder(c *check.C) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd replace folder with directory or dir

c.Assert(contents, check.IsNil)
}

func (s *S) TestIgnoreFolder(c *check.C) {
Copy link
Member

@andrestc andrestc Feb 8, 2017

Choose a reason for hiding this comment

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

I'd replace folder with directory or dir

@@ -1,7 +1,3 @@
// Copyright 2016 tsuru-client authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

I think this was removed by mistake, we need the header on every file.

@@ -290,13 +366,36 @@ func targz(ctx *cmd.Context, destination io.Writer, filepaths ...string) error {
if err != nil {
return err
}
wd, errWd := os.Getwd()
if errWd != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

I think you mean't return errWd. I think you can also rename errWd to err

@@ -348,11 +447,38 @@ func addDir(writer *tar.Writer, dirpath string) error {
if err != nil {
return err
}
wd, errWd := os.Getwd()
if errWd != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Same as before

@codecov-io
Copy link

codecov-io commented Feb 8, 2017

Codecov Report

Merging #25 into master will decrease coverage by -0.21%.

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
- Coverage   67.54%   67.34%   -0.21%     
==========================================
  Files          34       34              
  Lines        6335     6403      +68     
==========================================
+ Hits         4279     4312      +33     
- Misses       1441     1464      +23     
- Partials      615      627      +12
Impacted Files Coverage Δ
tsuru/client/deploy.go 69.32% <53.94%> (-4.43%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 508e4bb...064e134. Read the comment docs.

@arxdsilva arxdsilva changed the title Deploy ignore, solving tsuru/tsuru#1512 Adds .tsuruignore file support Feb 8, 2017
if err != nil {
return err
}
fiName := filepath.Join(wd, fi.Name())
if fi.IsDir() {
Copy link
Member

Choose a reason for hiding this comment

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

I think lines 375-383 can be moved to before the if statement (so you can remove the ones in 389-397).

@andrestc
Copy link
Member

andrestc commented Feb 8, 2017

I think there is some repetition that can be avoided by moving the checks to the begin of addDir and addFile.

for _, pattern := range ignorePatterns {
ignPats, errProc := processTsuruIgnore(pattern, context.Args...)
if errProc != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

return errProc

return nil, err
}
for i := range paths {
if dir == "." {
Copy link
Member

Choose a reason for hiding this comment

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

Is this if necessary? Couldn't this loop always do paths[i] = filepath.Join(dir, paths[i])?

Copy link
Contributor Author

@arxdsilva arxdsilva Feb 8, 2017

Choose a reason for hiding this comment

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

It is, we got this as a bug while uploading static into lab so without It, the path would be only paths[i] and It would never match glob on the root dir

return nil, err
}
defer os.Chdir(old)
for _, dir := range dirPath {
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to rename this vars to for _, dirPath := range dirPaths as dir is also used inside the for body.

}
paths[i] = filepath.Join(dir, paths[i])
}
dir, err := os.Open(dir)
Copy link
Member

Choose a reason for hiding this comment

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

You need to call dir.Close() after the Readdir call.

defer file.Close()
patterns := []string{}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
Copy link
Member

Choose a reason for hiding this comment

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

ScanLines is the default splitter, no need for this line.

scanner.Split(bufio.ScanLines)
for scanner.Scan() {
pattern := scanner.Text()
patterns = append(patterns, pattern)
Copy link
Member

Choose a reason for hiding this comment

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

Simply patterns = append(patterns, scanner.Text())

if fi.IsDir() {
for _, p := range ignoreList {
Copy link
Member

Choose a reason for hiding this comment

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

It would be more efficient for ignoreList to be a var ignoreSet map[string]struct{}. This way you could ignore patterns in O(1) by doing:

if _, inSet := ignoreSet[fiName]; !inSet {
    continue
}

Arthur Silva added 3 commits February 8, 2017 14:33
    return errProc
    rename vars to `for _, dirPath := range dirPaths`
    call dir.Close() after the Readdir
    simplify scanner append
    ignoreSet is a map[string]struct{} that allows better comparison
    to know If the pattern has matched or not
Copy link
Member

@andrestc andrestc left a comment

Choose a reason for hiding this comment

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

LGTM

@andrestc
Copy link
Member

This LGTM, what do you think, @cezarsa ?

@cezarsa cezarsa merged commit d7c3712 into tsuru:master Feb 13, 2017
@arxdsilva arxdsilva deleted the deploy-ignore branch February 13, 2017 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants