]> andersk Git - svn-all-fast-export.git/blobdiff - src/svn.cpp
Add support for annotated tags
[svn-all-fast-export.git] / src / svn.cpp
index 4062f31a3d7e097f28dbde523dd4bdc650f59cb0..aff719173ae4819f4d04e959b100d0dc76af6cc9 100644 (file)
@@ -220,11 +220,6 @@ static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *po
     if (propvalue)
         mode = 0100755;
 
-    // maybe it's a symlink?
-    SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:special", pool));
-    if (propvalue && strcmp(propvalue->data, "symlink") == 0)
-        mode = 0120000;
-
     return mode;
 }
 
@@ -261,16 +256,37 @@ static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
     svn_filesize_t stream_length;
 
     SVN_ERR(svn_fs_file_length(&stream_length, fs_root, pathname, dumppool));
-    QIODevice *io = txn->addFile(finalPathName, mode, stream_length);
 
 #ifndef DRY_RUN
     // open the file
     svn_stream_t *in_stream, *out_stream;
     SVN_ERR(svn_fs_file_contents(&in_stream, fs_root, pathname, dumppool));
+#endif
+
+    // maybe it's a symlink?
+    svn_string_t *propvalue;
+    SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:special", dumppool));
+    if (propvalue) {
+        apr_size_t len = strlen("link ");
+#ifndef DRY_RUN
+        QByteArray buf;
+        buf.reserve(len);
+        SVN_ERR(svn_stream_read(in_stream, buf.data(), &len));
+        if (len != strlen("link ") || strncmp(buf, "link ", len) != 0)
+            qFatal("file %s is svn:special but not a symlink", pathname);
+#endif
+        mode = 0120000;
+        stream_length -= len;
+    }
+
+    QIODevice *io = txn->addFile(finalPathName, mode, stream_length);
 
+#ifndef DRY_RUN
     // open a generic svn_stream_t for the QIODevice
     out_stream = streamForDevice(io, dumppool);
     SVN_ERR(svn_stream_copy(in_stream, out_stream, dumppool));
+    svn_stream_close(out_stream);
+    svn_stream_close(in_stream);
 
     // print an ending newline
     io->putChar('\n');
@@ -333,7 +349,7 @@ time_t get_epoch(char *svn_date)
     memset(&tm, 0, sizeof tm);
     QByteArray date(svn_date, strlen(svn_date) - 8);
     strptime(date, "%Y-%m-%dT%H:%M:%S", &tm);
-    return mktime(&tm);
+    return timegm(&tm);
 }
 
 class SvnRevision
@@ -349,6 +365,11 @@ public:
     svn_fs_root_t *fs_root;
     int revnum;
 
+    // must call fetchRevProps first:
+    QByteArray authorident;
+    QByteArray log;
+    uint epoch;
+
     SvnRevision(int revision, svn_fs_t *f, apr_pool_t *parent_pool)
         : pool(parent_pool), fs(f), fs_root(0), revnum(revision)
     {
@@ -361,6 +382,7 @@ public:
     }
 
     int prepareTransactions();
+    int fetchRevProps();
     int commit();
 
     int exportEntry(const char *path, const svn_fs_path_change_t *change, apr_hash_t *changes);
@@ -424,18 +446,17 @@ int SvnRevision::prepareTransactions()
     return EXIT_SUCCESS;
 }
 
-int SvnRevision::commit()
+int SvnRevision::fetchRevProps()
 {
-    // now create the commit
     apr_hash_t *revprops;
     SVN_ERR(svn_fs_revision_proplist(&revprops, fs, revnum, pool));
     svn_string_t *svnauthor = (svn_string_t*)apr_hash_get(revprops, "svn:author", APR_HASH_KEY_STRING);
     svn_string_t *svndate = (svn_string_t*)apr_hash_get(revprops, "svn:date", APR_HASH_KEY_STRING);
     svn_string_t *svnlog = (svn_string_t*)apr_hash_get(revprops, "svn:log", APR_HASH_KEY_STRING);
 
-    QByteArray log = (char *)svnlog->data;
-    QByteArray authorident = svnauthor ? identities.value((char *)svnauthor->data) : QByteArray();
-    time_t epoch = get_epoch((char*)svndate->data);
+    log = (char *)svnlog->data;
+    authorident = svnauthor ? identities.value((char *)svnauthor->data) : QByteArray();
+    epoch = get_epoch((char*)svndate->data);
     if (authorident.isEmpty()) {
         if (!svnauthor || svn_string_isempty(svnauthor))
             authorident = "nobody <nobody@localhost>";
@@ -443,7 +464,14 @@ int SvnRevision::commit()
             authorident = svnauthor->data + QByteArray(" <") +
                           svnauthor->data + QByteArray("@localhost>");
     }
+    return EXIT_SUCCESS;
+}
 
+int SvnRevision::commit()
+{
+    // now create the commit
+    if (fetchRevProps() != EXIT_SUCCESS)
+        return EXIT_FAILURE;
     foreach (Repository::Transaction *txn, transactions) {
         txn->setAuthor(authorident);
         txn->setDateTime(epoch);
@@ -479,7 +507,7 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change_t *change
         }
 
         current += '/';
-        qDebug() << "   " << key << "was copied from" << path_from;
+        qDebug() << "   " << key << "was copied from" << path_from << "rev" << rev_from;
     }
 
     // find the first rule that matches this pathname
@@ -512,8 +540,8 @@ int SvnRevision::exportDispatch(const char *key, const svn_fs_path_change_t *cha
     switch (rule.action) {
     case Rules::Match::Ignore:
         // ignore rule
-        qDebug() << "   " << qPrintable(current) << "rev" << revnum
-                 << "-> ignored (rule" << rule << ")";
+        //qDebug() << "   " << qPrintable(current) << "rev" << revnum
+        //         << "-> ignored (rule" << rule << ")";
         return EXIT_SUCCESS;
 
     case Rules::Match::Recurse:
@@ -580,6 +608,12 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *cha
                 }
 
                 repo->createBranch(branch, revnum, prevbranch, rev_from);
+                if (rule.annotate) {
+                    // create an annotated tag
+                    fetchRevProps();
+                    repo->createAnnotatedTag(branch, svnprefix, revnum, authorident,
+                                             epoch, log);
+                }
                 return EXIT_SUCCESS;
             }
         }
@@ -631,13 +665,18 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change_t *change,
         apr_hash_this(i, &vkey, NULL, &value);
 
         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
+        if (dirent->kind != svn_node_dir)
+            continue;           // not a directory, so can't recurse; skip
+
         QByteArray entry = path + QByteArray("/") + dirent->name;
         QByteArray entryFrom;
         if (path_from)
             entryFrom = path_from + QByteArray("/") + dirent->name;
 
         // check if this entry is in the changelist for this revision already
-        if (apr_hash_get(changes, entry.constData(), APR_HASH_KEY_STRING)) {
+        svn_fs_path_change_t *otherchange =
+            (svn_fs_path_change_t*)apr_hash_get(changes, entry.constData(), APR_HASH_KEY_STRING);
+        if (otherchange && otherchange->change_kind == svn_fs_path_change_add) {
             qDebug() << entry << "rev" << revnum
                      << "is in the change-list, deferring to that one";
             continue;
This page took 0.084219 seconds and 4 git commands to generate.