import code from gerrit

  http://review.source.kitware.com/#/c/9072/