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

add dotfiles support #498

Merged
merged 8 commits into from Dec 13, 2014

Conversation

Projects
None yet
4 participants
@mpapis
Copy link
Member

mpapis commented Nov 23, 2014

#492 with whitelist support

@mpapis mpapis force-pushed the feature/dotfiles_gh_492 branch from 4f0595b to 96628bf Nov 23, 2014

#
# @raise [MaxSymlinkDepthExceededError] if too many indirections are
# encountered while resolving symlinks
#
# @raise [UnsupportedFileTypeError] if a file of an unsupported type is
# detected (something other than file, directory or link)
def all_files_in(dir_name, recursion_limit = 10)

This comment has been minimized.

@ddfreyne

ddfreyne Nov 29, 2014

Member

The addition of the new extra_files param makes it not backwards compatible. Could this be converted into a params = {} defaulting to []?

This comment has been minimized.

@mpapis

mpapis Nov 29, 2014

Author Member

https://github.com/nanoc/nanoc/blob/feature/dotfiles_gh_492/lib/nanoc/extra/filesystem_tools.rb#L7 :

# @api private

wouldn't that mean we do not have to care about backwards compatibility? ... not that I can't do that change, just curious.

This comment has been minimized.

@ddfreyne

ddfreyne Nov 29, 2014

Member

You’re right. I didn’t spot the @api private. So, never mind :)

@ddfreyne ddfreyne added the to review label Nov 29, 2014

@ddfreyne

This comment has been minimized.

Copy link
Member

ddfreyne commented Nov 29, 2014

More in-depth review coming soon!

@ddfreyne ddfreyne modified the milestone: 3.7.5 Nov 29, 2014

when String
patterns << "#{dir_name}/#{extra_files}"
when Array
patterns += extra_files.map { |extra_file| "#{dir_name}/#{extra_file}" }

This comment has been minimized.

@ddfreyne

ddfreyne Nov 30, 2014

Member

For consistency, I’d rather have this be

extra_files.each { |extra_file| patterns << "#{dir_name}/#{extra_file}" }

This comment has been minimized.

@mpapis

mpapis Nov 30, 2014

Author Member

taking into account removing the default maybe it would be better to change previous line:

patterns << "#{dir_name}/#{extra_files}"

to

patterns += [ "#{dir_name}/#{extra_files}" ]

?
the each << pattern feels java like (in the monkeys typing form), there are good things in java, this is not one of them.

This comment has been minimized.

@ddfreyne

ddfreyne Nov 30, 2014

Member

I prefer #<< in this case, since it modifies the array rather than creating a modified duplicate. Since #all_files_and_dirs_in is the method in which the array is constructed, modifying the array in-place is good.

It’s also more compact, and arguably easier to read.

This comment has been minimized.

@mpapis

mpapis Nov 30, 2014

Author Member

I think it might be slower ... but I will do the fix in the evening

This comment has been minimized.

@ddfreyne

ddfreyne Nov 30, 2014

Member

Modifying the array in-place is definitely faster:

require 'benchmark'

Benchmark.bmbm do |x|
  x.report('#<<') do
    a = []
    50_000.times { a << 1 }
  end

  x.report('#+=') do
    a = []
    50_000.times { a += [1] }
  end
end
          user     system      total        real
#<<   0.010000   0.000000   0.010000 (  0.008376)
#+=   2.310000   3.880000   6.190000 (  6.208789)

Not that it matters much in this case, but there’s no reason to use += over << here.

This comment has been minimized.

@mpapis

mpapis Nov 30, 2014

Author Member

that's surprising, will have to report a bug for ruby

This comment has been minimized.

@ddfreyne

ddfreyne Nov 30, 2014

Member

It’s not a bug. The + form creates a new array by copying the original array and adding the new element. Copying is slow and creates lots of temporary objects that stress the GC.

This comment has been minimized.

@mpapis

mpapis Dec 1, 2014

Author Member

well I was expecting += to behave as concat => jruby/jruby#2256

This comment has been minimized.

@ddfreyne

ddfreyne Dec 6, 2014

Member

I prefer #concat:

patterns.concat(extra_files.map { |extra_file| "#{dir_name}/#{extra_file}" })
patterns = [ "#{dir_name}/**/*" ]
case extra_files
when nil
patterns << "#{dir_name}/**/.{htaccess,htpasswd}"

This comment has been minimized.

@ddfreyne

ddfreyne Nov 30, 2014

Member

I don’t think we should default to .{htaccess,htpasswd} here. I believe the default should be empty.

Having an empty default is both more predictable and more explicit.

This comment has been minimized.

@bobthecow

bobthecow Nov 30, 2014

Member

Agreed. Also, back when Apache was the only web server worth using, this would have been an acceptable default. Now, I'd be surprised if it would even be useful for a majority of users.

This comment has been minimized.

@mpapis

mpapis Dec 1, 2014

Author Member

removed the default

@ddfreyne

This comment has been minimized.

Copy link
Member

ddfreyne commented Nov 30, 2014

You’ll probably have to rebase against release-3.7.x because of the style changes, sorry!

@mpapis mpapis force-pushed the feature/dotfiles_gh_492 branch from 96628bf to 0859e20 Dec 1, 2014

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 1, 2014

Coverage Status

Coverage increased (+0.02%) when pulling 7e8d183 on feature/dotfiles_gh_492 into 07af041 on release-3.7.x.

@mpapis

This comment has been minimized.

Copy link
Member Author

mpapis commented Dec 1, 2014

I think the remaining bug will be fixed with #502

@mpapis

This comment has been minimized.

Copy link
Member Author

mpapis commented Dec 1, 2014

by bug I meant test failures

mpapis and others added some commits Nov 23, 2014

Test support for dotfiles in data-sources
    .htaccess and .htpasswd were not handled by any data-source

@mpapis mpapis force-pushed the feature/dotfiles_gh_492 branch from 7e8d183 to 1782d70 Dec 6, 2014

when String
patterns << "#{dir_name}/#{extra_files}"
when Array
patterns.concat(extra_files.map { |extra_file| "#{dir_name}/#{extra_file}" })

This comment has been minimized.

@mpapis

mpapis Dec 6, 2014

Author Member

now, is << and concat ok, or should I change << to concat([...])?

This comment has been minimized.

@ddfreyne

ddfreyne Dec 13, 2014

Member

Yup, that’s OK. It doesn’t make sense to use #concat when appending only a single element.

@mpapis

This comment has been minimized.

Copy link
Member Author

mpapis commented Dec 6, 2014

and the tests pass after rebasing on top of merged #502

@ddfreyne

This comment has been minimized.

Copy link
Member

ddfreyne commented Dec 13, 2014

👍

ddfreyne added a commit that referenced this pull request Dec 13, 2014

@ddfreyne ddfreyne merged commit 82f9a88 into release-3.7.x Dec 13, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@ddfreyne ddfreyne deleted the feature/dotfiles_gh_492 branch Dec 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.