Skip to content

Commit

Permalink
Don't add files that match the path of a known directory.
Browse files Browse the repository at this point in the history
This issue occurs with SVN logs of old repositories that do not
indicate the 'kind' of the path is a directory.
  • Loading branch information
acaudwell committed Nov 9, 2011
1 parent f60a7f4 commit 8fb3fe7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.38:
* Use AM_CPPFLAGS in Makefile.am to allow passing custom CPPFLAGS.
* Don't add files that match the path of a known directory.

0.37:
* Made SVN log GMT timestamp conversion fix portable.
Expand Down
16 changes: 15 additions & 1 deletion src/dirnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ RDirNode* RDirNode::getParent() const{
}


bool RDirNode::isDir(const std::string& path) const {

if(prefixedBy(path)) return true;

if(path.find(abspath) != 0) return false;

for(std::list<RDirNode*>::const_iterator it = children.begin(); it != children.end(); it++) {
if((*it)->isDir(path)) return true;
}

return false;
}

//finds directories closest to the root directory prefixed by path (eg foo/ may match just foo/ or could also match foo/bar1, foo/bar2, ... if foo/ doesn't exist).
void RDirNode::findDirs(const std::string& path, std::list<RDirNode*>& dirs) {

Expand Down Expand Up @@ -402,9 +415,10 @@ bool RDirNode::addFile(RFile* f) {
//do we have a file in this directory thats fullpath is a prefix of this file, if so
//that file is actually a directory - the file should be removed, and a directory with that path added
//if this is the root node we do this regardless of if the file was added to a child node

for(std::list<RFile*>::const_iterator it = files.begin(); it != files.end(); it++) {
RFile* file = (*it);

if(f->path.find(file->fullpath) == 0) {
//fprintf(stderr, "removing %s as is actually the directory of %s\n", file->fullpath.c_str(), f->fullpath.c_str());
file->remove(true);
Expand Down
1 change: 1 addition & 0 deletions src/dirnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class RDirNode : public QuadItem {

RDirNode* getParent() const;

bool isDir(const std::string& path) const;
void findDirs(const std::string& path, std::list<RDirNode*>& dirs);

const vec2f & getPos() const;
Expand Down
17 changes: 12 additions & 5 deletions src/gource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,16 @@ void Gource::deleteFile(RFile* file) {

RFile* Gource::addFile(const RCommitFile& cf) {

//if we already have max files in circulation
//we cant add any more
if(gGourceSettings.max_files > 0 && files.size() >= gGourceSettings.max_files) return 0;

//see if this is a directory
std::string file_as_dir = cf.filename;
if(file_as_dir[file_as_dir.size()-1] != '/') file_as_dir.append("/");

if(root->isDir(file_as_dir)) return 0;

int tagid = tag_seq++;

RFile* file = new RFile(cf.filename, cf.colour, vec2f(0.0,0.0), tagid);
Expand Down Expand Up @@ -1178,12 +1188,9 @@ void Gource::processCommit(RCommit& commit, float t) {

if(file == 0) {

//if we already have max files in circulation
//we cant add any more
if(gGourceSettings.max_files > 0 && files.size() >= gGourceSettings.max_files)
continue;

file = addFile(cf);

if(!file) continue;
}

addFileAction(commit.username, cf.action, file, t);
Expand Down

0 comments on commit 8fb3fe7

Please sign in to comment.