Revision: 72322
          http://sourceforge.net/p/brlcad/code/72322
Author:   starseeker
Date:     2019-02-03 16:20:42 +0000 (Sun, 03 Feb 2019)
Log Message:
-----------
Bah - enough fiddling.  Just extract and use the APR logic for date parsing.

Modified Paths:
--------------
    brlcad/trunk/misc/CMakeLists.txt
    brlcad/trunk/misc/repoconv/svnfexport/svnfexport.cxx

Added Paths:
-----------
    brlcad/trunk/misc/repoconv/svnfexport/svn_date.h

Modified: brlcad/trunk/misc/CMakeLists.txt
===================================================================
--- brlcad/trunk/misc/CMakeLists.txt    2019-02-03 03:11:44 UTC (rev 72321)
+++ brlcad/trunk/misc/CMakeLists.txt    2019-02-03 16:20:42 UTC (rev 72322)
@@ -145,6 +145,7 @@
   repoconv/svn2git/svn-fast-export/svn.cpp
   repoconv/svn2git/svn-fast-export/svn.h
   repoconv/svnfexport/sha1.hpp
+  repoconv/svnfexport/svn_date.h
   repoconv/svnfexport/svnfexport.cxx
   uncpowerplant2g.sh
   win32-msvc/CMakeLists.txt

Added: brlcad/trunk/misc/repoconv/svnfexport/svn_date.h
===================================================================
--- brlcad/trunk/misc/repoconv/svnfexport/svn_date.h                            
(rev 0)
+++ brlcad/trunk/misc/repoconv/svnfexport/svn_date.h    2019-02-03 16:20:42 UTC 
(rev 72322)
@@ -0,0 +1,104 @@
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <stdint.h>
+
+/* This is an extraction in stand-alone form of a small set of the Apache
+ * Portable Runtime logic for date parsing.  It's sole purpose is to convert
+ * internal SVN timestamps into proper Git timestamp strings.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define TIMESTAMP_FORMAT "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ"
+#define APR_USEC_PER_SEC 1000000LL
+
+struct svn_time {
+    int tm_year;
+    int tm_mon;
+    int tm_mday;
+    int tm_hour;
+    int tm_min;
+    int tm_sec;
+    int tm_usec;
+};
+
+uint64_t
+svn_time_from_cstring(struct svn_time *xt, const char *tstamp)
+{
+    uint64_t tfinal;
+    uint64_t year;
+    uint64_t days;
+    static const int dayoffset[12] = {306, 337, 0, 31, 61, 92, 122, 153, 184, 
214, 245, 275};
+
+    sscanf(tstamp, TIMESTAMP_FORMAT,  &xt->tm_year, &xt->tm_mon,
+           &xt->tm_mday, &xt->tm_hour, &xt->tm_min,
+           &xt->tm_sec, &xt->tm_usec);
+
+    xt->tm_year  -= 1900;
+    xt->tm_mon   -= 1;
+    year = xt->tm_year;
+
+    if (xt->tm_mon < 0 || xt->tm_mon >= 12)
+       return 0;
+
+    /* shift new year to 1st March in order to make leap year calc easy */
+    if (xt->tm_mon < 2)
+       year--;
+
+    /* Find number of days since 1st March 1900 (in the Gregorian calendar). */
+    days = year * 365 + year / 4 - year / 100 + (year / 100 + 3) / 4;
+    days += dayoffset[xt->tm_mon] + xt->tm_mday - 1;
+    days -= 25508;              /* 1 jan 1970 is 25508 days since 1 mar 1900 */
+    days = ((days * 24 + xt->tm_hour) * 60 + xt->tm_min) * 60 + xt->tm_sec;
+
+    if (days < 0) {
+       return 0;
+    }
+
+    tfinal = days * APR_USEC_PER_SEC + xt->tm_usec;
+
+    return tfinal;
+}
+
+std::string
+svn_time_to_git_time(const char *tstamp)
+{
+    struct svn_time svntime;
+    uint64_t stime = svn_time_from_cstring(&svntime, tstamp);
+    uint64_t ssec = (stime) / APR_USEC_PER_SEC;
+    return std::to_string(ssec) + std::string(" +0000");
+}
+
+#if 0
+int
+main()
+{
+    const std::string tstamp("2008-01-11T18:54:07.016469Z");
+    std::cout << tstamp << "\n";
+    std::cout << "converted time: " << svn_time_to_git_time(tstamp.c_str()) << 
"\n";
+}
+#endif
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8
+


Property changes on: brlcad/trunk/misc/repoconv/svnfexport/svn_date.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/trunk/misc/repoconv/svnfexport/svnfexport.cxx
===================================================================
--- brlcad/trunk/misc/repoconv/svnfexport/svnfexport.cxx        2019-02-03 
03:11:44 UTC (rev 72321)
+++ brlcad/trunk/misc/repoconv/svnfexport/svnfexport.cxx        2019-02-03 
16:20:42 UTC (rev 72322)
@@ -5,7 +5,10 @@
 #include <sstream>
 #include <string>
 #include <vector>
+#include <locale>
+#include <iomanip>
 #include "sha1.hpp"
+#include "svn_date.h"
 
 enum svn_node_kind_t { nkerr, nfile, ndir };
 enum svn_node_action_t { naerr, nchange, nadd, ndelete, nreplace };
@@ -64,6 +67,7 @@
 std::map<std::string,std::string> svn_sha1_to_git_sha1;
 
 std::set<std::string> blob_sha1;
+std::map<std::string,std::string> author_map;
 
 /* Branches */
 std::set<std::string> branches;
@@ -162,8 +166,9 @@
        long int v = std::stol(value);
 
        // Value associated with V line
-       char vbuff[v+1] = {'\0'};
+       char vbuff[v+1];
        infile.read(vbuff, v);
+       vbuff[v] = '\0';
        value = std::string(vbuff);
 
        // Have key value
@@ -220,8 +225,9 @@
        long int v = std::stol(value);
 
        // Value associated with V line
-       char vbuff[v+1] = {'\0'};
+       char vbuff[v+1];
        infile.read(vbuff, v);
+       vbuff[v] = '\0';
        value = std::string(vbuff);
 
        // Have key value
@@ -335,7 +341,7 @@
        go_buff.append(cbuffer, n.text_content_length);
        std::string git_sha1 = sha1_hash_hex(go_buff.c_str(), go_buff.length());
        svn_sha1_to_git_sha1[n.text_content_sha1] = git_sha1;
-       delete cbuffer;
+       delete[] cbuffer;
        /* Stash information on how to read the blob */
        sha1_blobs.insert(std::pair<std::string,std::pair<size_t, long 
int>>(n.text_content_sha1, std::pair<size_t, long int>(n.content_start, 
n.text_content_length)));
        /* Jump over the content and continue */
@@ -647,7 +653,7 @@
 
            outfile << "commit " << rev.nodes[0].branch << "\n";
            outfile << "mark :" << rev.revision_number << "\n";
-           outfile << "committer " << "unknown <brlcad@unknown> 1200077647 
-0500" << "\n";
+           outfile << "committer " << author_map[rev.author] << " " << 
svn_time_to_git_time(rev.timestamp.c_str()) << "\n";
            outfile << "data " << rev.commit_msg.length() << "\n";
            outfile << rev.commit_msg << "\n";
            outfile << "from " << branch_head_ids[rev.nodes[0].branch] << "\n";
@@ -730,9 +736,9 @@
 load_blob_sha1s(const char *f)
 {
 
-    std::ifstream hfile(f);
+    std::ifstream bfile(f);
     std::string line;
-    while (std::getline(hfile, line)) {
+    while (std::getline(bfile, line)) {
        size_t spos = line.find_first_of(" ");
        std::string hsha1 = line.substr(0, spos);
        blob_sha1.insert(hsha1);
@@ -739,10 +745,26 @@
     }
 }
 
+
+void
+load_author_map(const char *f)
+{
+
+    std::ifstream afile(f);
+    std::string line;
+    while (std::getline(afile, line)) {
+       size_t spos = line.find_first_of(" ");
+       std::string svnauthor = line.substr(0, spos);
+       std::string gitauthor = line.substr(spos+1, std::string::npos);
+       std::cout << svnauthor << " -> " << gitauthor << "\n";
+       author_map[svnauthor] = gitauthor;
+    }
+}
+
 int main(int argc, const char **argv)
 {
     if (argc < 4) {
-       std::cerr << "svnfexport dumpfile head_sha1s blob_sha1s\n";
+       std::cerr << "svnfexport dumpfile author_map head_sha1s blob_sha1s\n";
        return 1;
     }
 
@@ -764,10 +786,13 @@
     branch_mappings[std::string("framebuffer-experiment")] = 
std::string("framebuffer-experiment");
 
     /* Read in pre-existing branch sha1 heads from git */
-    load_branch_head_sha1s(argv[2]);
+    load_author_map(argv[2]);
 
+    /* Read in pre-existing branch sha1 heads from git */
+    load_branch_head_sha1s(argv[3]);
+
     /* Read in pre-existing blob sha1s from git */
-    load_blob_sha1s(argv[3]);
+    load_blob_sha1s(argv[4]);
 
     int rev_cnt = load_dump_file(argv[1]);
     if (rev_cnt > 0) {

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