2
Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version
7
3 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
Regex hg_regex("^([0-9]+) -?[0-9]+\\|([^|]+)\\|([ADM]?)\\|(.+)$");
22
// parse Mercurial log entries (using the gource.style template)
24
std::string gGourceMercurialCommand() {
26
std::string gource_style_path = gSDLAppResourceDir + std::string("gource.style");
28
return std::string("hg log -r 0:tip --style \"") + gource_style_path + std::string("\"");
31
MercurialLog::MercurialLog(const std::string& logfile) : RCommitLog(logfile) {
33
log_command = gGourceMercurialCommand();
35
//can generate log from directory
37
logf = generateLog(logfile);
46
BaseLog* MercurialLog::generateLog(const std::string& dir) {
48
//does directory have a .hg ?
49
std::string hgdir = dir + std::string("/.hg");
51
int stat_rc = stat(hgdir.c_str(), &dirinfo);
52
if(stat_rc!=0 || !(dirinfo.st_mode & S_IFDIR)) {
56
// do we have this client installed
57
requireExecutable("hg");
59
std::string command = getLogCommand();
63
if(temp_file.size()==0) return 0;
66
sprintf(cmd_buff, "%s -R \"%s\" > %s", command.c_str(), dir.c_str(), temp_file.c_str());
68
int command_rc = systemCommand(cmd_buff);
74
BaseLog* seeklog = new SeekLog(temp_file);
80
bool MercurialLog::parseCommit(RCommit& commit) {
82
while(parseCommitEntry(commit));
84
return !commit.files.empty();
87
bool MercurialLog::parseCommitEntry(RCommit& commit) {
90
std::vector<std::string> entries;
92
if(!logf->getNextLine(line)) return false;
95
if(!hg_regex.match(line, &entries)) return false;
97
time_t timestamp = atol(entries[0].c_str());
98
std::string username = entries[1];
100
//if this file is for the same person and timestamp
101
//we add to the commit, else we save the lastline
103
if(commit.files.empty()) {
104
commit.timestamp = timestamp;
105
commit.username = username;
107
if(commit.timestamp != timestamp || commit.username != username) {
113
std::string action = "A";
115
if(!entries[2].empty()) {
119
commit.addFile(entries[3], action);