diff --git a/README b/README index 52bb4674..06383ac3 100644 --- a/README +++ b/README @@ -140,6 +140,9 @@ options: --key Show file extension key. + --lines + Show the number of file lines by extension. + --date-format FORMAT Specify display date string (strftime format). @@ -402,17 +405,26 @@ Interactive keyboard commands: (M) Toggle mouse visibility (N) Jump forward in time to next log entry (S) Randomize colours + (P) Toggle bloom effect + (Z) Toggle gravity (D) Toggle directory name display mode (F) Toggle file name display mode (U) Toggle user name display mode (G) Toggle display of users (T) Toggle display of directory tree edges (R) Toggle display of root directory edges - (+-) Adjust simulation speed - (<>) Adjust time scale + (Q) Toggle debug info + (W) Toggle trace debug info + (Y) Toggle quad tree debug info + (+-) Adjust the simulation speed + (Keypad +-) Adjust viewport zoom + (.,) Adjust time scale + (/) Reset time scale + ([]) Adjust gravity (TAB) Cycle through visible users (F12) Screenshot (Alt+Enter) Fullscreen toggle + (Space) Toggle pause (ESC) Quit 4. Copyright diff --git a/src/formats/commitlog.cpp b/src/formats/commitlog.cpp index 800e59cd..1dc9862d 100644 --- a/src/formats/commitlog.cpp +++ b/src/formats/commitlog.cpp @@ -291,6 +291,7 @@ RCommitFile::RCommitFile(const std::string& filename, const std::string& action, this->action = action; this->colour = colour; + this->lines = 0; } RCommit::RCommit() { @@ -343,6 +344,17 @@ void RCommit::addFile(const std::string& filename, const std::string& action, c files.push_back(RCommitFile(filename, action, colour)); } +void RCommit::addLines(const std::string &filename, long delta) { + for(std::list::iterator it = files.begin(); it != files.end(); it++) { + RCommitFile& cf = *it; + if (cf.filename == filename) { + //std::cout << filename << ": delta " << delta << std::endl; + cf.lines = delta; + return; + } + } +} + void RCommit::postprocess() { username = RCommitLog::filter_utf8(username); } diff --git a/src/formats/commitlog.h b/src/formats/commitlog.h index b7b19513..8da34c69 100644 --- a/src/formats/commitlog.h +++ b/src/formats/commitlog.h @@ -35,6 +35,7 @@ class RCommitFile { std::string filename; std::string action; vec3 colour; + long lines; RCommitFile(const std::string& filename, const std::string& action, vec3 colour); }; @@ -53,6 +54,8 @@ class RCommit { void addFile(const std::string& filename, const std::string& action); void addFile(const std::string& filename, const std::string& action, const vec3& colour); + void addLines(const std::string& filename, long delta); + RCommit(); void debug(); virtual bool parse(BaseLog* logf) { return false; }; diff --git a/src/formats/git.cpp b/src/formats/git.cpp index 9927f8e9..0f760d57 100644 --- a/src/formats/git.cpp +++ b/src/formats/git.cpp @@ -47,6 +47,10 @@ std::string GitCommitLog::logCommand() { log_command += gGourceSettings.git_branch; } + if(gGourceSettings.show_lines) { + log_command += " --numstat "; + } + return log_command; } @@ -167,19 +171,34 @@ bool GitCommitLog::parseCommit(RCommit& commit) { //incorrect log format if(tab == std::string::npos || tab == 0 || tab == line.size()-1) continue; - std::string status = line.substr(tab - 1, 1); - std::string file = line.substr(tab + 1); - - if(file.empty()) continue; - - //check for and remove double quotes - if(file.find('"') == 0 && file.rfind('"') == file.size()-1) { - if(file.size()<=2) continue; - - file = file.substr(1,file.size()-2); + if(line[0] == ':') { + std::string file = line.substr(tab + 1); + std::string status = line.substr(tab - 1, 1); + + if(file.empty()) continue; + + //check for and remove double quotes + if(file.find('"') == 0 && file.rfind('"') == file.size()-1) { + if(file.size()<=2) continue; + + file = file.substr(1,file.size()-2); + } + + commit.addFile(file, status); + } else if(gGourceSettings.show_lines) { + long added = 0, removed = 0; + std::string file; + std::istringstream line_stream(line); + line_stream >> added >> removed >> file; + //std::cout << file << ": added " << added << ", removed " << removed << std::endl; + if(!file.empty()) { + if(file[0] != '/') { + file.insert(0, 1, '/'); + } + commit.addLines(file, added - removed); + } } - commit.addFile(file, status); } //check we at least got a username diff --git a/src/gource.cpp b/src/gource.cpp index ae1cd8b8..1ea90d49 100644 --- a/src/gource.cpp +++ b/src/gource.cpp @@ -1211,6 +1211,8 @@ void Gource::addFileAction(const std::string& username, const RCommitFile& cf, R //create user if havent yet. do it here to ensure at least one of there files //was added (incase we hit gGourceSettings.max_files) + file_key.changeLines(file, cf.lines); + //find user of this commit or create them RUser* user = 0; diff --git a/src/gource_settings.cpp b/src/gource_settings.cpp index 1b5132b4..c9121c5a 100644 --- a/src/gource_settings.cpp +++ b/src/gource_settings.cpp @@ -73,7 +73,9 @@ void GourceSettings::help(bool extended_help) { printf(" -c, --time-scale SCALE Change simulation time scale (default: 1.0)\n"); printf(" -e, --elasticity FLOAT Elasticity of nodes (default: 0.0)\n\n"); - printf(" --key Show file extension key\n\n"); + printf(" --key Show summary of file extensions\n"); + printf(" --key-threshold NUMBER Show a file extension when it reaches NUMBER (0 show always)\n"); + printf(" --lines Show the lines of code by file extension (git only)\n\n"); printf(" --user-image-dir DIRECTORY Dir containing images to use as avatars\n"); printf(" --default-user-image IMAGE Default user image file\n"); @@ -246,6 +248,8 @@ GourceSettings::GourceSettings() { arg_types["highlight-dirs"] = "bool"; arg_types["file-extensions"] = "bool"; arg_types["key"] = "bool"; + arg_types["key-threshold"] = "int"; + arg_types["lines"] = "bool"; arg_types["ffp"] = "bool"; arg_types["disable-auto-rotate"] = "bool"; @@ -357,6 +361,8 @@ void GourceSettings::setGourceDefaults() { dont_stop = false; show_key = false; + show_lines = false; + key_threshold = 0; disable_auto_rotate = false; @@ -1182,6 +1188,17 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc show_key = true; } + if((entry = gource_settings->getEntry("key-threshold")) != 0) { + + if(!entry->hasValue()) conffile.entryException(entry, "specify key-threshold (number)"); + + key_threshold = entry->getInt(); + } + + if(gource_settings->getBool("lines")) { + show_lines = true; + } + if(gource_settings->getBool("ffp")) { ffp = true; } diff --git a/src/gource_settings.h b/src/gource_settings.h index 3abed071..ec2d6484 100644 --- a/src/gource_settings.h +++ b/src/gource_settings.h @@ -45,6 +45,8 @@ class GourceSettings : public SDLAppSettings { bool disable_auto_rotate; bool show_key; + bool show_lines; + int key_threshold; std::string load_config; std::string save_config; diff --git a/src/key.cpp b/src/key.cpp index 05214434..ab3c4a1d 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -18,6 +18,7 @@ FileKeyEntry::FileKeyEntry(const FXFont& font, const std::string& ext, const vec height = 18.0f; left_margin = 20.0f; count = 0; + lines = 0; brightness = 1.0f; alpha = 0.0f; @@ -69,6 +70,10 @@ void FileKeyEntry::dec() { count--; } +void FileKeyEntry::changeLines(long delta) { + lines += delta; +} + int FileKeyEntry::getCount() const { return count; } @@ -148,7 +153,11 @@ void FileKeyEntry::draw() { font.draw((int)pos.x+2, (int)pos.y+3, display_ext.c_str()); font.dropShadow(true); - font.print((int)pos.x+width+4, (int)pos.y+3, "%d", count); + if(gGourceSettings.show_lines) { + font.print((int)pos.x+width+4, (int)pos.y+3, "%d / %ld", count, lines); + } else { + font.print((int)pos.x+width+4, (int)pos.y+3, "%d", count); + } } // Key @@ -238,6 +247,15 @@ void FileKey::dec(RFile* file) { entry->dec(); } +void FileKey::changeLines(RFile *file, long lines) { + std::map::iterator result = keymap.find(file->ext); + + if(result == keymap.end()) return; + + FileKeyEntry* entry = result->second; + entry->changeLines(lines); +} + bool file_key_entry_sort (const FileKeyEntry* a, const FileKeyEntry* b) { //sort by count @@ -263,7 +281,8 @@ void FileKey::logic(float dt) { FileKeyEntry* entry = it->second; if(!entry->isFinished()) { - active_keys.push_back(entry); + if(gGourceSettings.key_threshold == 0 || entry->getCount() >= gGourceSettings.key_threshold) + active_keys.push_back(entry); } else { finished_keys.push_back(entry); } diff --git a/src/key.h b/src/key.h index add29b7a..2e10f631 100644 --- a/src/key.h +++ b/src/key.h @@ -35,6 +35,7 @@ class FileKeyEntry { float alpha; float brightness; int count; + unsigned long lines; float pos_y; float src_y; float dest_y; @@ -57,6 +58,8 @@ class FileKeyEntry { void inc(); void dec(); + + void changeLines(long delta); void setShow(bool show); @@ -93,6 +96,8 @@ class FileKey { void inc(RFile* file); void dec(RFile* file); + void changeLines(RFile* file, long lines); + void logic(float dt); void draw();