From a5265c690970324ef24b8d0075c086917e4eb848 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Wed, 6 Dec 2017 12:38:05 +0100 Subject: [PATCH 1/4] Preliminary implementation of lines count by file extension At the moment works only with GIT Enabled with --lines command option --- src/formats/commitlog.cpp | 12 ++++++++++++ src/formats/commitlog.h | 3 +++ src/formats/git.cpp | 41 ++++++++++++++++++++++++++++----------- src/gource.cpp | 3 +++ src/gource_settings.cpp | 9 ++++++++- src/gource_settings.h | 1 + src/key.cpp | 20 ++++++++++++++++++- src/key.h | 5 +++++ 8 files changed, 81 insertions(+), 13 deletions(-) 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..ef237e39 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..2db2f003 100644 --- a/src/gource.cpp +++ b/src/gource.cpp @@ -990,6 +990,7 @@ RFile* Gource::addFile(const RCommitFile& cf) { root->addFile(file); file_key.inc(file); + file_key.changeLines(file, cf.lines); while(root->getParent() != 0) { debugLog("parent changed to %s", root->getPath().c_str()); @@ -1201,6 +1202,8 @@ void Gource::processCommit(RCommit& commit, float t) { file = addFile(cf); if(!file) continue; + } else { + file_key.changeLines(file, cf.lines); } addFileAction(commit.username, cf, file, t); diff --git a/src/gource_settings.cpp b/src/gource_settings.cpp index 1b5132b4..9f6fedac 100644 --- a/src/gource_settings.cpp +++ b/src/gource_settings.cpp @@ -73,7 +73,8 @@ 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(" --lines Show summary of lines of code by language\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 +247,7 @@ GourceSettings::GourceSettings() { arg_types["highlight-dirs"] = "bool"; arg_types["file-extensions"] = "bool"; arg_types["key"] = "bool"; + arg_types["lines"] = "bool"; arg_types["ffp"] = "bool"; arg_types["disable-auto-rotate"] = "bool"; @@ -357,6 +359,7 @@ void GourceSettings::setGourceDefaults() { dont_stop = false; show_key = false; + show_lines = false; disable_auto_rotate = false; @@ -1182,6 +1185,10 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc show_key = true; } + 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..7bf72a62 100644 --- a/src/gource_settings.h +++ b/src/gource_settings.h @@ -45,6 +45,7 @@ class GourceSettings : public SDLAppSettings { bool disable_auto_rotate; bool show_key; + bool show_lines; std::string load_config; std::string save_config; diff --git a/src/key.cpp b/src/key.cpp index 05214434..4a6c48f6 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 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(); From c611ee0b36a77dcc02058a413fd9cdc3e8788f99 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Wed, 6 Dec 2017 12:38:40 +0100 Subject: [PATCH 2/4] Updated README with missing runtime keys meaning --- README | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 From aadecaea79f0f1c683f4e0b85044a161565967dd Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Wed, 6 Dec 2017 15:31:24 +0100 Subject: [PATCH 3/4] Fixed the obviously wrong delta lines calculation --- src/formats/git.cpp | 2 +- src/gource.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/formats/git.cpp b/src/formats/git.cpp index ef237e39..0f760d57 100644 --- a/src/formats/git.cpp +++ b/src/formats/git.cpp @@ -195,7 +195,7 @@ bool GitCommitLog::parseCommit(RCommit& commit) { if(file[0] != '/') { file.insert(0, 1, '/'); } - commit.addLines(file, added + removed); + commit.addLines(file, added - removed); } } diff --git a/src/gource.cpp b/src/gource.cpp index 2db2f003..1ea90d49 100644 --- a/src/gource.cpp +++ b/src/gource.cpp @@ -990,7 +990,6 @@ RFile* Gource::addFile(const RCommitFile& cf) { root->addFile(file); file_key.inc(file); - file_key.changeLines(file, cf.lines); while(root->getParent() != 0) { debugLog("parent changed to %s", root->getPath().c_str()); @@ -1202,8 +1201,6 @@ void Gource::processCommit(RCommit& commit, float t) { file = addFile(cf); if(!file) continue; - } else { - file_key.changeLines(file, cf.lines); } addFileAction(commit.username, cf, file, t); @@ -1214,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; From 2b705c57156d4f30e2b4da8ceeb3083be51846db Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Sun, 31 Dec 2017 12:42:12 +0100 Subject: [PATCH 4/4] Added --key-threshold option to filter keys by a minimum count --- src/gource_settings.cpp | 12 +++++++++++- src/gource_settings.h | 1 + src/key.cpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gource_settings.cpp b/src/gource_settings.cpp index 9f6fedac..c9121c5a 100644 --- a/src/gource_settings.cpp +++ b/src/gource_settings.cpp @@ -74,7 +74,8 @@ void GourceSettings::help(bool extended_help) { printf(" -e, --elasticity FLOAT Elasticity of nodes (default: 0.0)\n\n"); printf(" --key Show summary of file extensions\n"); - printf(" --lines Show summary of lines of code by language\n\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"); @@ -247,6 +248,7 @@ 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"; @@ -360,6 +362,7 @@ void GourceSettings::setGourceDefaults() { show_key = false; show_lines = false; + key_threshold = 0; disable_auto_rotate = false; @@ -1185,6 +1188,13 @@ 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; } diff --git a/src/gource_settings.h b/src/gource_settings.h index 7bf72a62..ec2d6484 100644 --- a/src/gource_settings.h +++ b/src/gource_settings.h @@ -46,6 +46,7 @@ class GourceSettings : public SDLAppSettings { 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 4a6c48f6..ab3c4a1d 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -281,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); }