Is there an easy way to ensure a license block exists on all files in my project?
I need a license block:
// Copyright Billy O'Neal 2010 // Distributed under the Boost Software License, Version 1.0. // (See accompanying fil开发者_开发百科e LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt)
to be embedded in all of my source files. I'm worried that I might have missed one or more of these files, and I don't want to release the source to my library without these. Is there an easy way to look at a project and dump all files which don't have such a block?
Bonus points for a way to hook this into Mercurial so that a commit cannot succeed if there are files with missing licenses.
(I've got lots of tools which will find the blocks, but no tools which will find the missing ones)
Basically, you need to combine:
: actually that would search the commit message, not all files content.hg log --keyword
, which "do case-insensitive search for a given text" (see "hg log")
Searching the files is better achieved through any script (like this ant one)
For instance, Ry4an suggests in the comments (for a Unix environement):
find $(hg root) -type f -name '*.cpp' | xargs grep --files-without-match LICENSE_1_0.txt
- with a pre-commit hook (note a "precommit hook would run after automatic addition/removal of files from the repo has been performed, which is not what you want here: see "Mercurial Precommit Isn't Entirely "Pre"").
Note: if you need only to block the commit if the license message isn't there, but don't mind adding/removing file to the changeset about to be committed, then a precommit is fine.
精彩评论