Revision: 78363
          http://sourceforge.net/p/brlcad/code/78363
Author:   starseeker
Date:     2021-03-03 15:26:39 +0000 (Wed, 03 Mar 2021)
Log Message:
-----------
Add ability to add commit without splicing

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-03-03 14:13:28 UTC (rev 
78362)
+++ brlcad/trunk/misc/repowork/commit.cpp       2021-03-03 15:26:39 UTC (rev 
78363)
@@ -514,7 +514,74 @@
     return 0;
 }
 
+int
+parse_add_commit(git_fi_data *fi_data, std::ifstream &infile)
+{
+    //std::cout << "Found command: commit\n";
 
+    git_commit_data gcd;
+    gcd.s = fi_data;
+
+    // Tell the commit where it will be in the vector - this
+    // uniquely identifies this specific commit, regardless of
+    // its sha1.
+    gcd.id.index = fi_data->commits.size();
+
+    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;
+       }
+    }
+
+    gcd.id.mark = fi_data->next_mark(gcd.id.mark);
+    fi_data->mark_to_index[gcd.id.mark] = gcd.id.index;
+
+    //std::cout << "commit new mark: " << gcd.id.mark << "\n";
+
+    // Add the commit to the data
+    fi_data->commits.push_back(gcd);
+
+    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-03-03 14:13:28 UTC (rev 
78362)
+++ brlcad/trunk/misc/repowork/repowork.cpp     2021-03-03 15:26:39 UTC (rev 
78363)
@@ -1102,11 +1102,62 @@
 }
 
 int
+parse_add_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_add_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 add_commits = false;
     bool no_blobs = false;
     bool collapse_notes = false;
     bool wrap_commit_lines = false;
@@ -1157,6 +1208,7 @@
 
            ("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))
+           ("add-commits", "Look for git fast-import files in an 'add' 
directory and add to history.  Unlike splice commits, these are not being 
inserted into existing commit streams.", cxxopts::value<bool>(add_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")
@@ -1283,7 +1335,7 @@
 
     int ret = parse_fi_file(&fi_data, infile);
 
-    if ((replace_commits || splice_commits) && !fi_data.have_sha1s) {
+    if ((replace_commits || splice_commits || add_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);
     }
@@ -1403,8 +1455,27 @@
        }
     }
 
+    // If we have any additional commits, parse and insert them.
+    if (add_commits) {
 
-    // If we have any splice commits, parse and insert them.
+       std::filesystem::path ip = std::string(argv[1]);
+       std::filesystem::path aip = std::filesystem::absolute(ip);
+       std::filesystem::path pip = aip.parent_path();
+       pip /= "add";
+       if (!std::filesystem::exists(pip)) {
+           std::cerr << "Warning - adds 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);
+               int ret = parse_add_fi_file(&fi_data, sfile);
+               sfile.close();
+           }
+       }
+    }
+
+    // If we have any splice commits, parse and insert them.  (Note - this 
comes last, for
+    // bookkeeping reasons.)
     if (splice_commits) {
 
        std::filesystem::path ip = std::string(argv[1]);

Modified: brlcad/trunk/misc/repowork/repowork.h
===================================================================
--- brlcad/trunk/misc/repowork/repowork.h       2021-03-03 14:13:28 UTC (rev 
78362)
+++ brlcad/trunk/misc/repowork/repowork.h       2021-03-03 15:26:39 UTC (rev 
78363)
@@ -215,6 +215,7 @@
 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_add_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

Reply via email to