Permalink
Browse files

WIP distinguishing between rename and copy.

  • Loading branch information...
acaudwell committed Nov 10, 2011
1 parent 00539f7 commit c564c1683fec1ccb8512e79b1a7caf666349a228
Showing with 79 additions and 42 deletions.
  1. +14 −10 src/commitlog.cpp
  2. +5 −4 src/commitlog.h
  3. +2 −2 src/file.cpp
  4. +5 −3 src/gource.cpp
  5. +53 −23 src/svn.cpp
View
@@ -253,19 +253,19 @@ RCommitFile::RCommitFile(const std::string& filename, const std::string& action,
}
}
-RCommitFile::RCommitFile(const std::string& rename_from, const std::string& rename_to, const std::string& action, const vec3f& colour)
+RCommitFile::RCommitFile(const std::string& filename, const std::string& destination, const std::string& action, const vec3f& colour)
: action(action), colour(colour) {
- this->filename = munge_utf8(rename_from);
- this->rename_to = munge_utf8(rename_to);
+ this->filename = munge_utf8(filename);
+ this->destination = munge_utf8(destination);
//prepend a root slash
if(this->filename[0] != '/') {
this->filename.insert(0, 1, '/');
}
- if(this->rename_to[0] != '/') {
- this->rename_to.insert(0, 1, '/');
+ if(this->destination[0] != '/') {
+ this->destination.insert(0, 1, '/');
}
}
@@ -297,12 +297,12 @@ void RCommit::addFile(const std::string& filename, const std::string& action, c
files.push_back(RCommitFile(filename, action, colour));
}
-void RCommit::addFile(const std::string& rename_from, const std::string& renamed_to, const std::string& action) {
- files.push_back(RCommitFile(rename_from, renamed_to, action, fileColour(renamed_to)));
+void RCommit::addFile(const std::string& filename, const std::string& destination, const std::string& action) {
+ files.push_back(RCommitFile(filename, destination, action, fileColour(destination)));
}
-void RCommit::addFile(const std::string& rename_from, const std::string& renamed_to, const std::string& action, const vec3f& colour) {
- files.push_back(RCommitFile(rename_from, renamed_to, action, colour));
+void RCommit::addFile(const std::string& filename, const std::string& destination, const std::string& action, const vec3f& colour) {
+ files.push_back(RCommitFile(filename, destination, action, colour));
}
bool RCommit::isValid() {
@@ -317,6 +317,10 @@ void RCommit::debug() {
for(std::list<RCommitFile>::iterator it = files.begin(); it != files.end(); it++) {
RCommitFile f = *it;
- debugLog("%s %s\n", f.action.c_str(), f.filename.c_str());
+ if(f.action == "C" || f.action == "R") {
+ debugLog("%s %s => %s\n", f.action.c_str(), f.filename.c_str(), f.destination.c_str());
+ } else {
+ debugLog("%s %s\n", f.action.c_str(), f.filename.c_str());
+ }
}
}
View
@@ -34,12 +34,13 @@
class RCommitFile {
public:
std::string filename;
- std::string rename_to;
+ std::string destination;
std::string action;
+
vec3f colour;
RCommitFile(const std::string& filename, const std::string& action, const vec3f& colour);
- RCommitFile(const std::string& rename_from, const std::string& rename_to, const std::string& action, const vec3f& colour);
+ RCommitFile(const std::string& filename, const std::string& destination, const std::string& action, const vec3f& colour);
};
class RCommit {
@@ -55,8 +56,8 @@ class RCommit {
void addFile(const std::string& filename, const std::string& action);
void addFile(const std::string& filename, const std::string& action, const vec3f& colour);
- void addFile(const std::string& rename_from, const std::string& renamed_to, const std::string& action);
- void addFile(const std::string& rename_from, const std::string& renamed_to, const std::string& action, const vec3f& colour);
+ void addFile(const std::string& filename, const std::string& destination, const std::string& action);
+ void addFile(const std::string& filename, const std::string& destination, const std::string& action, const vec3f& colour);
RCommit();
void debug();
View
@@ -248,11 +248,11 @@ void RFile::rename(const std::string& rename_to, const vec3f& rename_colour) {
if(parent_dir != 0) {
parent_dir->removeChildIfEmpty(dir);
}
-
+
setFilename(rename_to);
file_colour = rename_colour;
-
+
vec2f old_dir_pos = dir->getPos();
root->addFile(this);
View
@@ -1234,9 +1234,11 @@ void Gource::addFileAction(const std::string& username, const RCommitFile& cf, R
userAction = new ModifyAction(user, file, t);
} else if(cf.action == "D") {
userAction = new RemoveAction(user, file, t);
- } else if(cf.action == "R" && !cf.rename_to.empty()) {
- debugLog("Rename %s\n", file->getName().c_str() );
- userAction = new RenameAction(user, file, cf.rename_to, cf.colour, t);
+ } else if(cf.action == "R" && !cf.destination.empty()) {
+ userAction = new RenameAction(user, file, cf.destination, cf.colour, t);
+ } else if(cf.action == "C" && !cf.destination.empty()) {
+ // TODO: implement copy
+ userAction = new RenameAction(user, file, cf.destination, cf.colour, t);
} else {
userAction = new ModifyAction(user, file, t);
}
View
@@ -235,7 +235,9 @@ bool SVNCommitLog::parseCommit(RCommit& commit) {
//parse changes
- std::set<std::string> renames;
+ bool has_copy = false;
+
+ std::set<std::string> deletes;
for(TiXmlElement* pathE = pathsE->FirstChildElement("path"); pathE != 0; pathE = pathE->NextSiblingElement()) {
//parse path
@@ -254,7 +256,7 @@ bool SVNCommitLog::parseCommit(RCommit& commit) {
//accept only deletes for directories or directory renames
if(!(strcmp(action, "D") == 0 || strcmp(action, "A") == 0 && copy_from != 0 && strlen(copy_from) != 0)) continue;
-
+
is_dir = true;
}
@@ -275,40 +277,68 @@ bool SVNCommitLog::parseCommit(RCommit& commit) {
//NOTE: this is actually a copy. to identify an actual rename, we need to find a delete in the same commit
// with the name found in the copy_from
-
- if(status == "A" && copy_from != 0 && strlen(copy_from) != 0) {
-
- std::string rename_from(copy_from);
- status = "R";
-
- if(is_dir && rename_from[rename_from.size()-1] != '/') {
- rename_from = rename_from + std::string("/");
- }
- //fprintf(stderr, "found rename of %s to %s\n", rename_from.c_str(), file.c_str());
+ if(status == "A" && copy_from != 0 && strlen(copy_from) > 0) {
- renames.insert(rename_from);
+ has_copy = true;
- commit.addFile(rename_from, file, status);
+ std::string from(copy_from);
- } else if(status == "D") {
+ status = "C";
- //if we've seen this filename as a rename, don't add the delete
- //TODO: this assumes they are in a particular order. need to do this as a post process
- //(ie add as a copy, change to rename if there is a delete, remove the delete
-
- if(renames.find(file) == renames.end()) {
- commit.addFile(file, status);
+ if(is_dir && from[from.size()-1] != '/') {
+ from.append("/");
}
+ commit.addFile(from, file, status);
+
+ } else if(status == "D") {
+
+ deletes.insert(file);
+
} else {
+
commit.addFile(file, status);
}
}
- //fprintf(stderr,"parsed logentry\n");
+ if(has_copy) {
+
+ std::set<std::string>::iterator del_it;
+
+ // go through copies, convert to rename if there is a delete
+ for(std::list<RCommitFile>::iterator it = commit.files.begin(); it != commit.files.end(); it++) {
+
+ RCommitFile* cf = &(*it);
+
+ if(cf->action != "C") continue;
+
+ del_it = deletes.find(cf->filename);
+
+ //change to a rename, remove the delete
+ if(del_it != deletes.end()) {
+ cf->action = "R";
+ deletes.erase(del_it);
+
+ //TODO: what if you copy over the top of another file
+
+ continue;
+ }
+ }
+ }
+
+ //add remaining deletes
- //read files
+ for(std::set<std::string>::iterator it = deletes.begin(); it != deletes.end(); it++) {
+ commit.addFile(*it, "D");
+ }
+
+ /*
+ if(has_copy) {
+ commit.debug();
+ //exit(1);
+ }
+ */
return true;
}

0 comments on commit c564c16

Please sign in to comment.