Revision: 76516
          http://sourceforge.net/p/brlcad/code/76516
Author:   starseeker
Date:     2020-07-27 01:55:14 +0000 (Mon, 27 Jul 2020)
Log Message:
-----------
Demonstrate (for N=1) ability to replace contents of a CVS commit with contents 
generated from a checkout.

Modified Paths:
--------------
    brlcad/trunk/misc/repowork/commit.cpp
    brlcad/trunk/misc/repowork/repowork.cpp

Modified: brlcad/trunk/misc/repowork/commit.cpp
===================================================================
--- brlcad/trunk/misc/repowork/commit.cpp       2020-07-27 01:12:45 UTC (rev 
76515)
+++ brlcad/trunk/misc/repowork/commit.cpp       2020-07-27 01:55:14 UTC (rev 
76516)
@@ -559,11 +559,9 @@
 
     bool write_ops = true;
     if (c->id.sha1.length()) {
-       if (c->s->rebuild_commits.find(c->id.sha1) != 
c->s->rebuild_commits.end()) {
+       if ((c->s->rebuild_commits.find(c->id.sha1) != 
c->s->rebuild_commits.end()) ||
+               (c->s->reset_commits.find(c->id.sha1) != 
c->s->reset_commits.end())) {
            write_ops = false;
-           if (c->s->reset_commits.find(c->id.sha1) != 
c->s->rebuild_commits.end()) {
-               std::cout << "reset commit!\n";
-           }
            std::string sha1tree = c->id.sha1 + std::string("-tree.fi");
            std::ifstream s1t(sha1tree, std::ifstream::binary | std::ios::ate);
            std::streamsize size = s1t.tellg();
@@ -577,9 +575,6 @@
            }
            s1t.close();
        }
-       if (c->s->reset_commits.find(c->id.sha1) != c->s->reset_commits.end()) {
-           std::cout << "TODO - reset commit\n";
-       }
     }
     if (write_ops) {
        for (size_t i = 0; i < c->fileops.size(); i++) {

Modified: brlcad/trunk/misc/repowork/repowork.cpp
===================================================================
--- brlcad/trunk/misc/repowork/repowork.cpp     2020-07-27 01:12:45 UTC (rev 
76515)
+++ brlcad/trunk/misc/repowork/repowork.cpp     2020-07-27 01:55:14 UTC (rev 
76516)
@@ -226,8 +226,38 @@
     return 0;
 }
 
+void
+process_ls_tree(std::string &sha1)
+{
+    // read children
+    std::ifstream tfile("tree.txt", std::ifstream::binary);
+    if (!tfile.good()) {
+       std::cerr << "Could not open tree file tree.txt\n";
+       exit(-1);
+    }
+    std::string sha1tree = sha1 + std::string("-tree.fi");
+    std::ofstream ofile(sha1tree, std::ios::out | std::ios::binary);
+    ofile << "deleteall\n";
+
+    std::string tline;
+    while (std::getline(tfile, tline)) {
+       std::string ltree = tline;
+       std::regex bregex(" blob ");
+       std::string ltree2 = std::regex_replace(ltree, bregex, " ");
+       std::regex sregex("^");
+       ltree = std::regex_replace(ltree2, sregex , "M ");
+       std::regex tregex("\t");
+       ltree2 = std::regex_replace(ltree, tregex , " \"");
+       ofile << ltree2 << "\"\n";
+    }
+
+    ofile.close();
+
+    std::remove("tree.txt");
+}
+
 int
-git_id_cvs_commits(git_fi_data *s, std::string &cvs_id_file, std::string 
&child_commits_file)
+git_id_cvs_commits(git_fi_data *s, std::string &cvs_id_file, std::string 
&repo_path, std::string &child_commits_file)
 {
     {
        // read children
@@ -321,6 +351,20 @@
            }
        }
     }
+
+    // Now that we know what the reset commits are, generate the trees that 
will
+    // achieve this.
+    std::set<std::string>::iterator s_it;
+    for (s_it = s->reset_commits.begin(); s_it != s->reset_commits.end(); 
s_it++) {
+       std::string sha1 = *s_it;
+       std::string git_ls_tree_cmd = std::string("cd ") + repo_path + 
std::string(" && git ls-tree --full-tree -r ") + sha1 + std::string(" > 
../tree.txt && cd ..");
+       if (std::system(git_ls_tree_cmd.c_str())) {
+           std::cout << "git_ls_tree_cmd \"" << git_ls_tree_cmd << "\" 
failed\n";
+           exit(-1);
+       }
+       process_ls_tree(sha1);
+    }
+
     return 0;
 }
 
@@ -401,7 +445,6 @@
     std::string svn_map;
     std::string children_file;
     std::string cvs_id_file;
-    std::string cvs_repo_path;
     int cwidth = 72;
 
     // TODO - might be good do have a "validate" option that does the fast 
import and then
@@ -422,8 +465,7 @@
            ("n,collapse-notes", "Take any git-notes contents and append them 
to regular commit messages.", cxxopts::value<bool>(collapse_notes))
           
            ("children", "File with output of \"git rev-list --children 
--all\"", cxxopts::value<std::vector<std::string>>(), "file")
-           ("cvs-ids", "Specify CVS era commits (revision number or SHA1) to 
rebuild.  Requires cvs-repo be set as well.  Needs --show-original-ids 
information in fast import file", cxxopts::value<std::vector<std::string>>(), 
"file")
-           ("cvs-repo", "CVS repository path", 
cxxopts::value<std::vector<std::string>>(), "path")
+           ("cvs-ids", "Specify CVS era 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")
 
            ("h,help", "Print help")
            ;
@@ -466,12 +508,6 @@
            cvs_id_file = ff[0];
        }
 
-       if (result.count("cvs-repo"))
-       {
-           auto& ff = result["cvs-repo"].as<std::vector<std::string>>();
-           cvs_repo_path = ff[0];
-       }
-
        if (result.count("width"))
        {
            cwidth = result["width"].as<int>();
@@ -489,8 +525,8 @@
        return -1;
     }
 
-    if ((cvs_id_file.length() && !cvs_repo_path.length()) || 
(!cvs_id_file.length() && cvs_repo_path.length())) {
-       std::cerr << "Need both CVS id list and CVS repository path for 
processing!\n";
+    if (cvs_id_file.length() && !repo_path.length()) {
+       std::cerr << "Need Git repository path for CVS id list processing!\n";
        return -1;
     }
 
@@ -534,7 +570,7 @@
 
     if (cvs_id_file.length()) {
        // Handle CVS rebuild info
-       git_id_cvs_commits(&fi_data, cvs_id_file, children_file);
+       git_id_cvs_commits(&fi_data, cvs_id_file, repo_path, children_file);
     }
 
     fi_data.wrap_width = cwidth;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to