Split into two rows.
[svn2git:cuboxs-uqs-svn2git.git] / src / svn.cpp
1 /*
2  *  Copyright (C) 2007  Thiago Macieira <thiago@kde.org>
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*
19  * Based on svn-fast-export by Chris Lee <clee@kde.org>
20  * License: MIT <http://www.opensource.org/licenses/mit-license.php>
21  * URL: git://repo.or.cz/fast-import.git http://repo.or.cz/w/fast-export.git
22  */
23
24 #define _XOPEN_SOURCE
25 #define _LARGEFILE_SUPPORT
26 #define _LARGEFILE64_SUPPORT
27
28 #include "svn.h"
29 #include "CommandLineParser.h"
30
31 #include <unistd.h>
32 #include <string.h>
33 #include <stdio.h>
34 #include <time.h>
35 #include <unistd.h>
36
37 #include <apr_lib.h>
38 #include <apr_getopt.h>
39 #include <apr_general.h>
40
41 #include <svn_fs.h>
42 #include <svn_pools.h>
43 #include <svn_repos.h>
44 #include <svn_types.h>
45
46 #include <QFile>
47 #include <QDebug>
48
49 #include "repository.h"
50
51 #undef SVN_ERR
52 #define SVN_ERR(expr) SVN_INT_ERR(expr)
53
54 typedef QList<Rules::Match> MatchRuleList;
55 typedef QHash<QString, Repository *> RepositoryHash;
56 typedef QHash<QByteArray, QByteArray> IdentityHash;
57
58 class AprAutoPool
59 {
60     apr_pool_t *pool;
61     AprAutoPool(const AprAutoPool &);
62     AprAutoPool &operator=(const AprAutoPool &);
63 public:
64     inline AprAutoPool(apr_pool_t *parent = NULL)
65         { pool = svn_pool_create(parent); }
66     inline ~AprAutoPool()
67         { svn_pool_destroy(pool); }
68
69     inline void clear() { svn_pool_clear(pool); }
70     inline apr_pool_t *data() const { return pool; }
71     inline operator apr_pool_t *() const { return pool; }
72 };
73
74 class SvnPrivate
75 {
76 public:
77     MatchRuleList matchRules;
78     RepositoryHash repositories;
79     IdentityHash identities;
80
81     SvnPrivate(const QString &pathToRepository);
82     ~SvnPrivate();
83     int youngestRevision();
84     int exportRevision(int revnum);
85
86     int openRepository(const QString &pathToRepository);
87
88 private:
89     AprAutoPool global_pool;
90     svn_fs_t *fs;
91     svn_revnum_t youngest_rev;
92 };
93
94 void Svn::initialize()
95 {
96     // initialize APR or exit
97     if (apr_initialize() != APR_SUCCESS) {
98         fprintf(stderr, "You lose at apr_initialize().\n");
99         exit(1);
100     }
101
102     // static destructor
103     static struct Destructor { ~Destructor() { apr_terminate(); } } destructor;
104 }
105
106 Svn::Svn(const QString &pathToRepository)
107     : d(new SvnPrivate(pathToRepository))
108 {
109 }
110
111 Svn::~Svn()
112 {
113     delete d;
114 }
115
116 void Svn::setMatchRules(const MatchRuleList &matchRules)
117 {
118     d->matchRules = matchRules;
119 }
120
121 void Svn::setRepositories(const RepositoryHash &repositories)
122 {
123     d->repositories = repositories;
124 }
125
126 void Svn::setIdentityMap(const IdentityHash &identityMap)
127 {
128     d->identities = identityMap;
129 }
130
131 int Svn::youngestRevision()
132 {
133     return d->youngestRevision();
134 }
135
136 bool Svn::exportRevision(int revnum)
137 {
138     return d->exportRevision(revnum) == EXIT_SUCCESS;
139 }
140
141 SvnPrivate::SvnPrivate(const QString &pathToRepository)
142     : global_pool(NULL)
143 {
144     openRepository(pathToRepository);
145
146     // get the youngest revision
147     svn_fs_youngest_rev(&youngest_rev, fs, global_pool);
148 }
149
150 SvnPrivate::~SvnPrivate()
151 {
152     svn_pool_destroy(global_pool);
153 }
154
155 int SvnPrivate::youngestRevision()
156 {
157     return youngest_rev;
158 }
159
160 int SvnPrivate::openRepository(const QString &pathToRepository)
161 {
162     svn_repos_t *repos;
163     QString path = pathToRepository;
164     while (path.endsWith('/')) // no trailing slash allowed
165         path = path.mid(0, path.length()-1);
166     SVN_ERR(svn_repos_open(&repos, QFile::encodeName(path), global_pool));
167     fs = svn_repos_fs(repos);
168
169     return EXIT_SUCCESS;
170 }
171
172 enum RuleType { AnyRule = 0, NoIgnoreRule = 0x01, NoRecurseRule = 0x02 };
173
174 static MatchRuleList::ConstIterator
175 findMatchRule(const MatchRuleList &matchRules, int revnum, const QString &current,
176               int ruleMask = AnyRule)
177 {
178     MatchRuleList::ConstIterator it = matchRules.constBegin(),
179                                 end = matchRules.constEnd();
180     for ( ; it != end; ++it) {
181         if (it->minRevision > revnum)
182             continue;
183         if (it->maxRevision != -1 && it->maxRevision < revnum)
184             continue;
185         if (it->action == Rules::Match::Ignore && ruleMask & NoIgnoreRule)
186             continue;
187         if (it->action == Rules::Match::Recurse && ruleMask & NoRecurseRule)
188             continue;
189         if (it->rx.indexIn(current) == 0) {
190             return it;
191         }
192     }
193
194     // no match
195     return end;
196 }
197
198 static void splitPathName(const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
199                           QString *repository_p, QString *branch_p, QString *path_p)
200 {
201     QString svnprefix = pathName;
202     svnprefix.truncate(rule.rx.matchedLength());
203
204     if (svnprefix_p) {
205         *svnprefix_p = svnprefix;
206     }
207
208     if (repository_p) {
209         *repository_p = svnprefix;
210         repository_p->replace(rule.rx, rule.repository);
211     }
212
213     if (branch_p) {
214         *branch_p = svnprefix;
215         branch_p->replace(rule.rx, rule.branch);
216     }
217
218     if (path_p) {
219         QString prefix = svnprefix;
220         prefix.replace(rule.rx, rule.prefix);
221         *path_p = prefix + pathName.mid(svnprefix.length());
222     }
223 }
224
225 static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *pool)
226 {
227     svn_string_t *propvalue;
228     SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:executable", pool));
229     int mode = 0100644;
230     if (propvalue)
231         mode = 0100755;
232
233     return mode;
234 }
235
236 svn_error_t *QIODevice_write(void *baton, const char *data, apr_size_t *len)
237 {
238     QIODevice *device = reinterpret_cast<QIODevice *>(baton);
239     device->write(data, *len);
240
241     while (device->bytesToWrite() > 32*1024) {
242         if (!device->waitForBytesWritten(-1)) {
243             qFatal("Failed to write to process: %s", qPrintable(device->errorString()));
244             return svn_error_createf(APR_EOF, SVN_NO_ERROR, "Failed to write to process: %s",
245                                      qPrintable(device->errorString()));
246         }
247     }
248     return SVN_NO_ERROR;
249 }
250
251 static svn_stream_t *streamForDevice(QIODevice *device, apr_pool_t *pool)
252 {
253     svn_stream_t *stream = svn_stream_create(device, pool);
254     svn_stream_set_write(stream, QIODevice_write);
255
256     return stream;
257 }
258
259 static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
260                     const char *pathname, const QString &finalPathName, apr_pool_t *pool)
261 {
262     AprAutoPool dumppool(pool);
263     // what type is it?
264     int mode = pathMode(fs_root, pathname, dumppool);
265
266     svn_filesize_t stream_length;
267
268     SVN_ERR(svn_fs_file_length(&stream_length, fs_root, pathname, dumppool));
269
270     svn_stream_t *in_stream, *out_stream;
271     if (!CommandLineParser::instance()->contains("dry-run")) {
272         // open the file
273         SVN_ERR(svn_fs_file_contents(&in_stream, fs_root, pathname, dumppool));
274     }
275
276     // maybe it's a symlink?
277     svn_string_t *propvalue;
278     SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:special", dumppool));
279     if (propvalue) {
280         apr_size_t len = strlen("link ");
281         if (!CommandLineParser::instance()->contains("dry-run")) {
282             QByteArray buf;
283             buf.reserve(len);
284             SVN_ERR(svn_stream_read(in_stream, buf.data(), &len));
285             if (len != strlen("link ") || strncmp(buf, "link ", len) != 0)
286                 qFatal("file %s is svn:special but not a symlink", pathname);
287         }
288         mode = 0120000;
289         stream_length -= len;
290     }
291
292     QIODevice *io = txn->addFile(finalPathName, mode, stream_length);
293
294     if (!CommandLineParser::instance()->contains("dry-run")) {
295         // open a generic svn_stream_t for the QIODevice
296         out_stream = streamForDevice(io, dumppool);
297         SVN_ERR(svn_stream_copy(in_stream, out_stream, dumppool));
298         svn_stream_close(out_stream);
299         svn_stream_close(in_stream);
300
301         // print an ending newline
302         io->putChar('\n');
303     }
304
305     return EXIT_SUCCESS;
306 }
307
308 static int recursiveDumpDir(Repository::Transaction *txn, svn_fs_root_t *fs_root,
309                             const QByteArray &pathname, const QString &finalPathName,
310                             apr_pool_t *pool)
311 {
312     // get the dir listing
313     apr_hash_t *entries;
314     SVN_ERR(svn_fs_dir_entries(&entries, fs_root, pathname, pool));
315     AprAutoPool dirpool(pool);
316
317     for (apr_hash_index_t *i = apr_hash_first(pool, entries); i; i = apr_hash_next(i)) {
318         dirpool.clear();
319         const void *vkey;
320         void *value;
321         apr_hash_this(i, &vkey, NULL, &value);
322
323         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
324         QByteArray entryName = pathname + '/' + dirent->name;
325         QString entryFinalName = finalPathName + dirent->name;
326
327         if (dirent->kind == svn_node_dir) {
328             entryFinalName += '/';
329             if (recursiveDumpDir(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
330                 return EXIT_FAILURE;
331         } else if (dirent->kind == svn_node_file) {
332             printf("+");
333             fflush(stdout);
334             if (dumpBlob(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
335                 return EXIT_FAILURE;
336         }
337     }
338
339     return EXIT_SUCCESS;
340 }
341
342 static bool wasDir(svn_fs_t *fs, int revnum, const char *pathname, apr_pool_t *pool)
343 {
344     AprAutoPool subpool(pool);
345     svn_fs_root_t *fs_root;
346     if (svn_fs_revision_root(&fs_root, fs, revnum, subpool) != SVN_NO_ERROR)
347         return false;
348
349     svn_boolean_t is_dir;
350     if (svn_fs_is_dir(&is_dir, fs_root, pathname, subpool) != SVN_NO_ERROR)
351         return false;
352
353     return is_dir;
354 }
355
356 time_t get_epoch(char *svn_date)
357 {
358     struct tm tm;
359     memset(&tm, 0, sizeof tm);
360     QByteArray date(svn_date, strlen(svn_date) - 8);
361     strptime(date, "%Y-%m-%dT%H:%M:%S", &tm);
362     return timegm(&tm);
363 }
364
365 class SvnRevision
366 {
367 public:
368     AprAutoPool pool;
369     QHash<QString, Repository::Transaction *> transactions;
370     MatchRuleList matchRules;
371     RepositoryHash repositories;
372     IdentityHash identities;
373
374     svn_fs_t *fs;
375     svn_fs_root_t *fs_root;
376     int revnum;
377
378     // must call fetchRevProps first:
379     QByteArray authorident;
380     QByteArray log;
381     uint epoch;
382
383     SvnRevision(int revision, svn_fs_t *f, apr_pool_t *parent_pool)
384         : pool(parent_pool), fs(f), fs_root(0), revnum(revision)
385     {
386     }
387
388     int open()
389     {
390         SVN_ERR(svn_fs_revision_root(&fs_root, fs, revnum, pool));
391         return EXIT_SUCCESS;
392     }
393
394     int prepareTransactions();
395     int fetchRevProps();
396     int commit();
397
398     int exportEntry(const char *path, const svn_fs_path_change_t *change, apr_hash_t *changes);
399     int exportDispatch(const char *path, const svn_fs_path_change_t *change,
400                        const char *path_from, svn_revnum_t rev_from,
401                        apr_hash_t *changes, const QString &current, const Rules::Match &rule,
402                        apr_pool_t *pool);
403     int exportInternal(const char *path, const svn_fs_path_change_t *change,
404                        const char *path_from, svn_revnum_t rev_from,
405                        const QString &current, const Rules::Match &rule);
406     int recurse(const char *path, const svn_fs_path_change_t *change,
407                 const char *path_from, svn_revnum_t rev_from,
408                 apr_hash_t *changes, apr_pool_t *pool);
409 };
410
411 int SvnPrivate::exportRevision(int revnum)
412 {
413     SvnRevision rev(revnum, fs, global_pool);
414     rev.matchRules = matchRules;
415     rev.repositories = repositories;
416     rev.identities = identities;
417
418     // open this revision:
419     printf("Exporting revision %d ", revnum);
420     fflush(stdout);
421
422     if (rev.open() == EXIT_FAILURE)
423         return EXIT_FAILURE;
424
425     if (rev.prepareTransactions() == EXIT_FAILURE)
426         return EXIT_FAILURE;
427
428     if (rev.transactions.isEmpty()) {
429         printf(" nothing to do\n");
430         return EXIT_SUCCESS;    // no changes?
431     }
432
433     if (rev.commit() == EXIT_FAILURE)
434         return EXIT_FAILURE;
435
436     printf(" done\n");
437     return EXIT_SUCCESS;
438 }
439
440 int SvnRevision::prepareTransactions()
441 {
442     // find out what was changed in this revision:
443     apr_hash_t *changes;
444     SVN_ERR(svn_fs_paths_changed(&changes, fs_root, pool));
445     for (apr_hash_index_t *i = apr_hash_first(pool, changes); i; i = apr_hash_next(i)) {
446         const void *vkey;
447         void *value;
448         apr_hash_this(i, &vkey, NULL, &value);
449         const char *key = reinterpret_cast<const char *>(vkey);
450         svn_fs_path_change_t *change = reinterpret_cast<svn_fs_path_change_t *>(value);
451
452         if (exportEntry(key, change, changes) == EXIT_FAILURE)
453             return EXIT_FAILURE;
454     }
455
456     return EXIT_SUCCESS;
457 }
458
459 int SvnRevision::fetchRevProps()
460 {
461     apr_hash_t *revprops;
462     SVN_ERR(svn_fs_revision_proplist(&revprops, fs, revnum, pool));
463     svn_string_t *svnauthor = (svn_string_t*)apr_hash_get(revprops, "svn:author", APR_HASH_KEY_STRING);
464     svn_string_t *svndate = (svn_string_t*)apr_hash_get(revprops, "svn:date", APR_HASH_KEY_STRING);
465     svn_string_t *svnlog = (svn_string_t*)apr_hash_get(revprops, "svn:log", APR_HASH_KEY_STRING);
466
467     log = (char *)svnlog->data;
468     authorident = svnauthor ? identities.value((char *)svnauthor->data) : QByteArray();
469     epoch = get_epoch((char*)svndate->data);
470     if (authorident.isEmpty()) {
471         if (!svnauthor || svn_string_isempty(svnauthor))
472             authorident = "nobody <nobody@localhost>";
473         else
474             authorident = svnauthor->data + QByteArray(" <") +
475                           svnauthor->data + QByteArray("@localhost>");
476     }
477     return EXIT_SUCCESS;
478 }
479
480 int SvnRevision::commit()
481 {
482     // now create the commit
483     if (fetchRevProps() != EXIT_SUCCESS)
484         return EXIT_FAILURE;
485     foreach (Repository::Transaction *txn, transactions) {
486         txn->setAuthor(authorident);
487         txn->setDateTime(epoch);
488         txn->setLog(log);
489
490         txn->commit();
491         delete txn;
492     }
493
494     return EXIT_SUCCESS;
495 }
496
497 int SvnRevision::exportEntry(const char *key, const svn_fs_path_change_t *change,
498                              apr_hash_t *changes)
499 {
500     AprAutoPool revpool(pool.data());
501     QString current = QString::fromUtf8(key);
502
503     // was this copied from somewhere?
504     svn_revnum_t rev_from;
505     const char *path_from;
506     SVN_ERR(svn_fs_copied_from(&rev_from, &path_from, fs_root, key, revpool));
507
508     // is this a directory?
509     svn_boolean_t is_dir;
510     SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool));
511     if (is_dir) {
512         if (path_from == NULL) {
513             // no, it's a new directory being added
514             // Git doesn't handle directories, so we don't either
515             //qDebug() << "   mkdir ignored:" << key;
516             return EXIT_SUCCESS;
517         }
518
519         current += '/';
520         qDebug() << "   " << key << "was copied from" << path_from << "rev" << rev_from;
521     }
522
523     // find the first rule that matches this pathname
524     MatchRuleList::ConstIterator match = findMatchRule(matchRules, revnum, current);
525     if (match != matchRules.constEnd()) {
526         const Rules::Match &rule = *match;
527         return exportDispatch(key, change, path_from, rev_from, changes, current, rule, revpool);
528     }
529
530     if (is_dir && path_from != NULL) {
531         qDebug() << current << "is a copy-with-history, auto-recursing";
532         return recurse(key, change, path_from, rev_from, changes, revpool);
533     } else if (wasDir(fs, revnum - 1, key, revpool)) {
534         qDebug() << current << "was a directory; ignoring";
535     } else if (change->change_kind == svn_fs_path_change_delete) {
536         qDebug() << current << "is being deleted but I don't know anything about it; ignoring";
537     } else {
538         qCritical() << current << "did not match any rules; cannot continue";
539         return EXIT_FAILURE;
540     }
541
542     return EXIT_SUCCESS;
543 }
544
545 int SvnRevision::exportDispatch(const char *key, const svn_fs_path_change_t *change,
546                                 const char *path_from, svn_revnum_t rev_from,
547                                 apr_hash_t *changes, const QString &current,
548                                 const Rules::Match &rule, apr_pool_t *pool)
549 {
550     if(CommandLineParser::instance()->contains( QLatin1String("debug-rules")))
551       qDebug() << "    " << qPrintable(current) << "matched rule:" << rule.lineNumber << "(" << rule.rx.pattern() << ")";
552     switch (rule.action) {
553     case Rules::Match::Ignore:
554         // ignore rule
555         //qDebug() << "   " << qPrintable(current) << "rev" << revnum
556         //         << "-> ignored (rule" << rule << ")";
557         return EXIT_SUCCESS;
558
559     case Rules::Match::Recurse:
560         return recurse(key, change, path_from, rev_from, changes, pool);
561
562     case Rules::Match::Export:
563         return exportInternal(key, change, path_from, rev_from, current, rule);
564     }
565
566     // never reached
567     return EXIT_FAILURE;
568 }
569
570 int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *change,
571                                 const char *path_from, svn_revnum_t rev_from,
572                                 const QString &current, const Rules::Match &rule)
573 {
574     QString svnprefix, repository, branch, path;
575     splitPathName(rule, current, &svnprefix, &repository, &branch, &path);
576
577     printf(".");
578     fflush(stdout);
579 //                qDebug() << "   " << qPrintable(current) << "rev" << revnum << "->"
580 //                         << qPrintable(repository) << qPrintable(branch) << qPrintable(path);
581
582     if (path.isEmpty() && path_from != NULL) {
583         QString previous = QString::fromUtf8(path_from) + '/';
584         MatchRuleList::ConstIterator prevmatch =
585             findMatchRule(matchRules, rev_from, previous, NoIgnoreRule);
586         if (prevmatch != matchRules.constEnd()) {
587             QString prevsvnprefix, prevrepository, prevbranch, prevpath;
588             splitPathName(*prevmatch, previous, &prevsvnprefix, &prevrepository,
589                           &prevbranch, &prevpath);
590
591             if (!prevpath.isEmpty()) {
592                 qDebug() << qPrintable(current) << "is a partial branch of repository"
593                          << qPrintable(prevrepository) << "branch"
594                          << qPrintable(prevbranch) << "subdir"
595                          << qPrintable(prevpath);
596             } else if (prevrepository != repository) {
597                 qWarning() << qPrintable(current) << "rev" << revnum
598                            << "is a cross-repository copy (from repository"
599                            << qPrintable(prevrepository) << "branch"
600                            << qPrintable(prevbranch) << "path"
601                            << qPrintable(prevpath) << "rev" << rev_from << ")";
602             } else if (prevbranch == branch) {
603                 // same branch and same repository
604                 qDebug() << qPrintable(current) << "rev" << revnum
605                          << "is an SVN rename from"
606                          << qPrintable(previous) << "rev" << rev_from;
607                 return EXIT_SUCCESS;
608             } else {
609                 // same repository but not same branch
610                 // this means this is a plain branch
611                 qDebug() << qPrintable(repository) << ": branch"
612                          << qPrintable(branch) << "is branching from"
613                          << qPrintable(prevbranch);
614
615                 Repository *repo = repositories.value(repository, 0);
616                 if (!repo) {
617                     qCritical() << "Rule" << rule
618                                 << "references unknown repository" << repository;
619                     return EXIT_FAILURE;
620                 }
621
622                 repo->createBranch(branch, revnum, prevbranch, rev_from);
623                 if (rule.annotate) {
624                     // create an annotated tag
625                     fetchRevProps();
626                     repo->createAnnotatedTag(branch, svnprefix, revnum, authorident,
627                                              epoch, log);
628                 }
629                 return EXIT_SUCCESS;
630             }
631         }
632     }
633
634     Repository::Transaction *txn = transactions.value(repository + branch, 0);
635     if (!txn) {
636         Repository *repo = repositories.value(repository, 0);
637         if (!repo) {
638             qCritical() << "Rule" << rule
639                         << "references unknown repository" << repository;
640             return EXIT_FAILURE;
641         }
642
643         txn = repo->newTransaction(branch, svnprefix, revnum);
644         if (!txn)
645             return EXIT_FAILURE;
646
647         transactions.insert(repository + branch, txn);
648     }
649
650     if (change->change_kind == svn_fs_path_change_delete) {
651         txn->deleteFile(path);
652     } else if (!current.endsWith('/')) {
653         dumpBlob(txn, fs_root, key, path, pool);
654     } else {
655         txn->deleteFile(path);
656         recursiveDumpDir(txn, fs_root, key, path, pool);
657     }
658
659     return EXIT_SUCCESS;
660 }
661
662 int SvnRevision::recurse(const char *path, const svn_fs_path_change_t *change,
663                          const char *path_from, svn_revnum_t rev_from,
664                          apr_hash_t *changes, apr_pool_t *pool)
665 {
666     // get the dir listing
667     apr_hash_t *entries;
668     SVN_ERR(svn_fs_dir_entries(&entries, fs_root, path, pool));
669
670     AprAutoPool dirpool(pool);
671     for (apr_hash_index_t *i = apr_hash_first(pool, entries); i; i = apr_hash_next(i)) {
672         dirpool.clear();
673         const void *vkey;
674         void *value;
675         apr_hash_this(i, &vkey, NULL, &value);
676
677         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
678         if (dirent->kind != svn_node_dir)
679             continue;           // not a directory, so can't recurse; skip
680
681         QByteArray entry = path + QByteArray("/") + dirent->name;
682         QByteArray entryFrom;
683         if (path_from)
684             entryFrom = path_from + QByteArray("/") + dirent->name;
685
686         // check if this entry is in the changelist for this revision already
687         svn_fs_path_change_t *otherchange =
688             (svn_fs_path_change_t*)apr_hash_get(changes, entry.constData(), APR_HASH_KEY_STRING);
689         if (otherchange && otherchange->change_kind == svn_fs_path_change_add) {
690             qDebug() << entry << "rev" << revnum
691                      << "is in the change-list, deferring to that one";
692             continue;
693         }
694
695         QString current = QString::fromUtf8(entry);
696         if (dirent->kind == svn_node_dir)
697             current += '/';
698
699         // find the first rule that matches this pathname
700         MatchRuleList::ConstIterator match = findMatchRule(matchRules, revnum, current);
701         if (match != matchRules.constEnd()) {
702             if (exportDispatch(entry, change, entryFrom.isNull() ? 0 : entryFrom.constData(),
703                                rev_from, changes, current, *match, dirpool) == EXIT_FAILURE)
704                 return EXIT_FAILURE;
705         } else {
706             qCritical() << current << "rev" << revnum
707                         << "did not match any rules; cannot continue";
708             return EXIT_FAILURE;
709         }
710     }
711
712     return EXIT_SUCCESS;
713 }