Skip to content

Commit

Permalink
Convert all line endings to UNIX style for git SHA1.
Browse files Browse the repository at this point in the history
Refs #8924
  • Loading branch information
martyngigg committed Nov 14, 2014
1 parent 1ee638c commit b5d2884
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Code/Mantid/Framework/Kernel/src/ChecksumHelper.cpp
Expand Up @@ -23,8 +23,9 @@ namespace ChecksumHelper
/**
* Load contents of file into a string. The line endings are preserved
* @param filepath Full path to the file to be opened
* @param unixEOL If true convert all lineendings to Unix-style \n
*/
std::string loadFile(const std::string & filepath)
std::string loadFile(const std::string & filepath, const bool unixEOL = false)
{
std::ifstream filein(filepath, std::ios::in | std::ios::binary);
if(!filein) return "";
Expand All @@ -36,6 +37,11 @@ namespace ChecksumHelper
filein.read(&contents[0], contents.size());
filein.close();

if(unixEOL)
{
static boost::regex eol("\\R"); // \R is Perl syntax for matching any EOL sequence
contents = boost::regex_replace(contents, eol, "\n"); // converts all to LF
}
return contents;
}

Expand Down Expand Up @@ -88,7 +94,8 @@ namespace ChecksumHelper
std::string gitSha1FromFile(const std::string& filepath)
{
if(filepath.empty()) return "";
std::string contents = loadFile(filepath);
const bool unixEOL(true);
std::string contents = loadFile(filepath, unixEOL);
std::stringstream header;
header << "blob " << contents.size() << '\0';
return ChecksumHelper::createSHA1(contents, header.str());
Expand Down

0 comments on commit b5d2884

Please sign in to comment.