2

I need a license block:

//          Copyright Billy O'Neal 2010
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file 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)

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552

1 Answers1

4

Basically, you need to combine:

  • hg log --keyword, which "do case-insensitive search for a given text" (see "hg log"): actually that would search the commit message, not all files content.
    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.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think `--keyword` checks the commit messages not the files. – Ry4an Brase Jan 27 '11 at 06:48
  • @Ry4an: which is why I was editing my answer precisely when you made that comment ;) http://stackoverflow.com/questions/746684/how-to-search-through-all-commits-in-the-repository/890923#890923 (and its comments) details the '`hg log -k` command. – VonC Jan 27 '11 at 06:48
  • YOu could probably do this answer swapping in a check like this: `find $(hg root) -type f -name '*.cpp' | xargs grep --files-without-match LICENSE_1_0.txt` if you're on unix – Ry4an Brase Jan 27 '11 at 06:50
  • @Ry4an: good point on the '`hg root`' part: I have included your suggestion included in the answer. – VonC Jan 27 '11 at 06:53
  • @Ry4an: thank you ;) Judging by the wild success of this answer... you're the only one :) – VonC Jan 27 '11 at 17:48
  • 1
    heh, it's beating all the others by a fair margin. – Ry4an Brase Jan 27 '11 at 21:43