]> andersk Git - svn-all-fast-export.git/blobdiff - src/svn.cpp
Fix the recursing when the sub-path was modified instead of just added
[svn-all-fast-export.git] / src / svn.cpp
index 378dc771f9f958f4674ac10671a86343f4cb387e..4bf4e9edd5a23c052c90492efbbedafa01c8e781 100644 (file)
@@ -122,6 +122,11 @@ void Svn::setRepositories(const RepositoryHash &repositories)
     d->repositories = repositories;
 }
 
+void Svn::setIdentityMap(const IdentityHash &identityMap)
+{
+    d->identities = identityMap;
+}
+
 int Svn::youngestRevision()
 {
     return d->youngestRevision();
@@ -160,7 +165,7 @@ int SvnPrivate::openRepository(const QString &pathToRepository)
     return EXIT_SUCCESS;
 }
 
-enum RuleType { AnyRule = 0, NoIgnoreRule = 0x01 };
+enum RuleType { AnyRule = 0, NoIgnoreRule = 0x01, NoRecurseRule = 0x02 };
 
 static MatchRuleList::ConstIterator
 findMatchRule(const MatchRuleList &matchRules, int revnum, const QString &current,
@@ -175,6 +180,8 @@ findMatchRule(const MatchRuleList &matchRules, int revnum, const QString &curren
             continue;
         if (it->action == Rules::Match::Ignore && ruleMask & NoIgnoreRule)
             continue;
+        if (it->action == Rules::Match::Recurse && ruleMask & NoRecurseRule)
+            continue;
         if (it->rx.indexIn(current) == 0)
             return it;
     }
@@ -213,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;
 }
 
@@ -226,8 +228,13 @@ svn_error_t *QIODevice_write(void *baton, const char *data, apr_size_t *len)
     QIODevice *device = reinterpret_cast<QIODevice *>(baton);
     device->write(data, *len);
 
-    if (device->bytesToWrite() > 16384)
-        device->waitForBytesWritten(0);
+    while (device->bytesToWrite() > 32*1024) {
+        if (!device->waitForBytesWritten(-1)) {
+            qFatal("Failed to write to process: %s", qPrintable(device->errorString()));
+            return svn_error_createf(APR_EOF, SVN_NO_ERROR, "Failed to write to process: %s",
+                                     qPrintable(device->errorString()));
+        }
+    }
     return SVN_NO_ERROR;
 }
 
@@ -249,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');
@@ -321,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
@@ -467,7 +495,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
@@ -500,8 +528,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:
@@ -510,6 +538,9 @@ int SvnRevision::exportDispatch(const char *key, const svn_fs_path_change_t *cha
     case Rules::Match::Export:
         return exportInternal(key, change, path_from, rev_from, current, rule);
     }
+
+    // never reached
+    return EXIT_FAILURE;
 }
 
 int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *change,
@@ -616,13 +647,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.095477 seconds and 4 git commands to generate.