Revision: 78349 http://sourceforge.net/p/brlcad/code/78349 Author: starseeker Date: 2021-02-28 00:03:27 +0000 (Sun, 28 Feb 2021) Log Message: ----------- Add the ability to supply a fi file to rewrite an existing commit. If we need this more need to check its ability to change a tree, but does what's needed for the immediate purpose.
Modified Paths: -------------- brlcad/trunk/misc/repowork/commit.cpp brlcad/trunk/misc/repowork/repowork.cpp brlcad/trunk/misc/repowork/repowork.h Modified: brlcad/trunk/misc/repowork/commit.cpp =================================================================== --- brlcad/trunk/misc/repowork/commit.cpp 2021-02-27 22:09:38 UTC (rev 78348) +++ brlcad/trunk/misc/repowork/commit.cpp 2021-02-28 00:03:27 UTC (rev 78349) @@ -456,9 +456,65 @@ return 0; } +int +parse_replace_commit(git_fi_data *fi_data, std::ifstream &infile) +{ + // First, find the existing commit for this sha1. If we don't + // have that, we're out of business. + if (fi_data->sha1_to_mark.find(fi_data->replace_sha1) == fi_data->sha1_to_mark.end()) { + std::cerr << "Trying to process unknown replacement sha1 " << fi_data->replace_sha1 << "\n"; + return -1; + } + int index = fi_data->mark_to_index[fi_data->sha1_to_mark[fi_data->replace_sha1]]; + git_commit_data &gcd = fi_data->commits[index]; + std::map<std::string, commitcmd_t> cmdmap; + // Commit info modification commands + cmdmap[std::string("author")] = commit_parse_author; + cmdmap[std::string("commit ")] = commit_parse_commit; // Note - need space after commit to avoid matching committer! + cmdmap[std::string("committer")] = commit_parse_committer; + cmdmap[std::string("data")] = commit_parse_data; + cmdmap[std::string("encoding")] = commit_parse_encoding; + cmdmap[std::string("from")] = commit_parse_from; + cmdmap[std::string("mark")] = commit_parse_mark; + cmdmap[std::string("merge")] = commit_parse_merge; + cmdmap[std::string("original-oid")] = commit_parse_original_oid; + // tree modification commands + cmdmap[std::string("C ")] = commit_parse_filecopy; + cmdmap[std::string("D ")] = commit_parse_filedelete; + cmdmap[std::string("M ")] = commit_parse_filemodify; + cmdmap[std::string("N ")] = commit_parse_notemodify; + cmdmap[std::string("R ")] = commit_parse_filerename; + cmdmap[std::string("deleteall")] = commit_parse_deleteall; + std::string line; + size_t offset = infile.tellg(); + int commit_done = 0; + while (!commit_done && std::getline(infile, line)) { + + commitcmd_t cc = commit_find_cmd(line, cmdmap); + + // If we found a command, process it. Otherwise, we are done + // with the commit and need to clean up. + if (cc) { + //std::cout << "commit line: " << line << "\n"; + infile.seekg(offset); + (*cc)(&gcd, infile); + offset = infile.tellg(); + } else { + // Whatever was on that line, it's not a commit input. + // Reset input to allow the parent routine to deal with + // it, and return. + infile.seekg(offset); + commit_done = 1; + } + } + + return 0; +} + + void write_op(std::ofstream &outfile, git_op *o) { Modified: brlcad/trunk/misc/repowork/repowork.cpp =================================================================== --- brlcad/trunk/misc/repowork/repowork.cpp 2021-02-27 22:09:38 UTC (rev 78348) +++ brlcad/trunk/misc/repowork/repowork.cpp 2021-02-28 00:03:27 UTC (rev 78349) @@ -1054,12 +1054,59 @@ return 0; } +int +parse_replace_fi_file(git_fi_data *fi_data, std::ifstream &infile) +{ + std::map<std::string, gitcmd_t> cmdmap; + cmdmap[std::string("alias")] = parse_alias; + cmdmap[std::string("blob")] = parse_blob; + cmdmap[std::string("cat-blob")] = parse_cat_blob; + cmdmap[std::string("checkpoint")] = parse_checkpoint; + cmdmap[std::string("commit ")] = parse_replace_commit; + cmdmap[std::string("done")] = parse_done; + cmdmap[std::string("feature")] = parse_feature; + cmdmap[std::string("get-mark")] = parse_get_mark; + cmdmap[std::string("ls")] = parse_ls; + cmdmap[std::string("option")] = parse_option; + cmdmap[std::string("progress")] = parse_progress; + cmdmap[std::string("reset")] = parse_reset; + cmdmap[std::string("tag")] = parse_tag; + size_t offset = infile.tellg(); + std::string line; + std::map<std::string, gitcmd_t>::iterator c_it; + while (std::getline(infile, line)) { + // Skip empty lines + if (!line.length()) { + offset = infile.tellg(); + continue; + } + + gitcmd_t gc = gitit_find_cmd(line, cmdmap); + if (!gc) { + //std::cerr << "Unsupported command!\n"; + offset = infile.tellg(); + continue; + } + + // If we found a command, process it + //std::cout << "line: " << line << "\n"; + // some commands have data on the command line - reset seek so the + // callback can process it + infile.seekg(offset); + (*gc)(fi_data, infile); + offset = infile.tellg(); + } + + return 0; +} + int main(int argc, char *argv[]) { git_fi_data fi_data; bool splice_commits = false; + bool replace_commits = false; bool no_blobs = false; bool collapse_notes = false; bool wrap_commit_lines = false; @@ -1109,6 +1156,7 @@ ("list-empty", "Print out information about empty commits.", cxxopts::value<bool>(list_empty)) ("splice-commits", "Look for git fast-import files in a 'splices' directory and insert them into the history.", cxxopts::value<bool>(splice_commits)) + ("replace-commits", "Look for git fast-import files in a 'replace' directory and overwrite. File of fast import file should be sha1 of target commit to replace.", cxxopts::value<bool>(replace_commits)) ("rebuild-ids", "Specify commits (revision number or SHA1) to rebuild. Requires git-repo be set as well. Needs --show-original-ids information in fast import file", cxxopts::value<std::vector<std::string>>(), "file") ("rebuild-ids-children", "File with output of \"git rev-list --children --all\" - needed for processing rebuild-ids", cxxopts::value<std::vector<std::string>>(), "file") @@ -1235,7 +1283,7 @@ int ret = parse_fi_file(&fi_data, infile); - if (splice_commits && !fi_data.have_sha1s) { + if ((replace_commits || splice_commits) && !fi_data.have_sha1s) { std::cerr << "Fatal - sha1 SVN rev updating requested, but don't have original sha1 ids - redo fast-export with the --show-original-ids option.\n"; exit(1); } @@ -1334,6 +1382,28 @@ infile.close(); + + // If we have any replace commits, parse and overwrite. + if (replace_commits) { + + std::filesystem::path ip = std::string(argv[1]); + std::filesystem::path aip = std::filesystem::absolute(ip); + std::filesystem::path pip = aip.parent_path(); + pip /= "replace"; + if (!std::filesystem::exists(pip)) { + std::cerr << "Warning - splices enabled but " << pip << " is not present on the filesystem.\n"; + } else { + for (const auto& de : std::filesystem::recursive_directory_iterator(pip)) { + std::cout << "Processing " << de.path().string() << "\n"; + std::ifstream sfile(de.path(), std::ifstream::binary); + fi_data.replace_sha1 = de.path().filename().string(); + int ret = parse_replace_fi_file(&fi_data, sfile); + sfile.close(); + } + } + } + + // If we have any splice commits, parse and insert them. if (splice_commits) { Modified: brlcad/trunk/misc/repowork/repowork.h =================================================================== --- brlcad/trunk/misc/repowork/repowork.h 2021-02-27 22:09:38 UTC (rev 78348) +++ brlcad/trunk/misc/repowork/repowork.h 2021-02-28 00:03:27 UTC (rev 78349) @@ -203,6 +203,9 @@ std::map<std::string, std::string> key2cvsauthor; std::map<std::string, std::string> key2cvsbranch; + // If processing a replacement operation, need to know which commit + // to target + std::string replace_sha1; private: long mark = -1; }; @@ -211,6 +214,7 @@ extern int parse_blob(git_fi_data *fi_data, std::ifstream &infile); extern int parse_commit(git_fi_data *fi_data, std::ifstream &infile); extern int parse_splice_commit(git_fi_data *fi_data, std::ifstream &infile); +extern int parse_replace_commit(git_fi_data *fi_data, std::ifstream &infile); extern int parse_reset(git_fi_data *fi_data, std::ifstream &infile); extern int parse_tag(git_fi_data *fi_data, std::ifstream &infile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits