Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lines count display option #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/formats/commitlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<RCommitFile>::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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/formats/commitlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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; };
Expand Down
41 changes: 30 additions & 11 deletions src/formats/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ std::string GitCommitLog::logCommand() {
log_command += gGourceSettings.git_branch;
}

if(gGourceSettings.show_lines) {
log_command += " --numstat ";
}

return log_command;
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/gource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 18 additions & 1 deletion src/gource_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -357,6 +361,8 @@ void GourceSettings::setGourceDefaults() {
dont_stop = false;

show_key = false;
show_lines = false;
key_threshold = 0;

disable_auto_rotate = false;

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gource_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 21 additions & 2 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,6 +70,10 @@ void FileKeyEntry::dec() {
count--;
}

void FileKeyEntry::changeLines(long delta) {
lines += delta;
}

int FileKeyEntry::getCount() const {
return count;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -238,6 +247,15 @@ void FileKey::dec(RFile* file) {
entry->dec();
}

void FileKey::changeLines(RFile *file, long lines) {
std::map<std::string, FileKeyEntry*>::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
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FileKeyEntry {
float alpha;
float brightness;
int count;
unsigned long lines;
float pos_y;
float src_y;
float dest_y;
Expand All @@ -57,6 +58,8 @@ class FileKeyEntry {

void inc();
void dec();

void changeLines(long delta);

void setShow(bool show);

Expand Down Expand Up @@ -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();
Expand Down