Merge remote branch 'svn2git/master'
[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.replace(rule.rx, rule.prefix);
220         *path_p = prefix + pathName.mid(svnprefix.length());
221     }
222 }
223
224 static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *pool)
225 {
226     svn_string_t *propvalue;
227     SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:executable", pool));
228     int mode = 0100644;
229     if (propvalue)
230         mode = 0100755;
231
232     return mode;
233 }
234
235 svn_error_t *QIODevice_write(void *baton, const char *data, apr_size_t *len)
236 {
237     QIODevice *device = reinterpret_cast<QIODevice *>(baton);
238     device->write(data, *len);
239
240     while (device->bytesToWrite() > 32*1024) {
241         if (!device->waitForBytesWritten(-1)) {
242             qFatal("Failed to write to process: %s", qPrintable(device->errorString()));
243             return svn_error_createf(APR_EOF, SVN_NO_ERROR, "Failed to write to process: %s",
244                                      qPrintable(device->errorString()));
245         }
246     }
247     return SVN_NO_ERROR;
248 }
249
250 static svn_stream_t *streamForDevice(QIODevice *device, apr_pool_t *pool)
251 {
252     svn_stream_t *stream = svn_stream_create(device, pool);
253     svn_stream_set_write(stream, QIODevice_write);
254
255     return stream;
256 }
257
258 static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
259                     const char *pathname, const QString &finalPathName, apr_pool_t *pool)
260 {
261     AprAutoPool dumppool(pool);
262     // what type is it?
263     int mode = pathMode(fs_root, pathname, dumppool);
264
265     svn_filesize_t stream_length;
266
267     SVN_ERR(svn_fs_file_length(&stream_length, fs_root, pathname, dumppool));
268
269     svn_stream_t *in_stream, *out_stream;
270     if (!CommandLineParser::instance()->contains("dry-run")) {
271         // open the file
272         SVN_ERR(svn_fs_file_contents(&in_stream, fs_root, pathname, dumppool));
273     }
274
275     // maybe it's a symlink?
276     svn_string_t *propvalue;
277     SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:special", dumppool));
278     if (propvalue) {
279         apr_size_t len = strlen("link ");
280         if (!CommandLineParser::instance()->contains("dry-run")) {
281             QByteArray buf;
282             buf.reserve(len);
283             SVN_ERR(svn_stream_read(in_stream, buf.data(), &len));
284             if (len != strlen("link ") || strncmp(buf, "link ", len) != 0)
285                 qFatal("file %s is svn:special but not a symlink", pathname);
286         }
287         mode = 0120000;
288         stream_length -= len;
289     }
290
291     QIODevice *io = txn->addFile(finalPathName, mode, stream_length);
292
293     if (!CommandLineParser::instance()->contains("dry-run")) {
294         // open a generic svn_stream_t for the QIODevice
295         out_stream = streamForDevice(io, dumppool);
296         SVN_ERR(svn_stream_copy(in_stream, out_stream, dumppool));
297         svn_stream_close(out_stream);
298         svn_stream_close(in_stream);
299
300         // print an ending newline
301         io->putChar('\n');
302     }
303
304     return EXIT_SUCCESS;
305 }
306
307 static int recursiveDumpDir(Repository::Transaction *txn, svn_fs_root_t *fs_root,
308                             const QByteArray &pathname, const QString &finalPathName,
309                             apr_pool_t *pool)
310 {
311     // get the dir listing
312     apr_hash_t *entries;
313     SVN_ERR(svn_fs_dir_entries(&entries, fs_root, pathname, pool));
314     AprAutoPool dirpool(pool);
315
316     for (apr_hash_index_t *i = apr_hash_first(pool, entries); i; i = apr_hash_next(i)) {
317         dirpool.clear();
318         const void *vkey;
319         void *value;
320         apr_hash_this(i, &vkey, NULL, &value);
321
322         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
323         QByteArray entryName = pathname + '/' + dirent->name;
324         QString entryFinalName = finalPathName + dirent->name;
325
326         if (dirent->kind == svn_node_dir) {
327             entryFinalName += '/';
328             if (recursiveDumpDir(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
329                 return EXIT_FAILURE;
330         } else if (dirent->kind == svn_node_file) {
331             printf("+");
332             fflush(stdout);
333             if (dumpBlob(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
334                 return EXIT_FAILURE;
335         }
336     }
337
338     return EXIT_SUCCESS;
339 }
340
341 static bool wasDir(svn_fs_t *fs, int revnum, const char *pathname, apr_pool_t *pool)
342 {
343     AprAutoPool subpool(pool);
344     svn_fs_root_t *fs_root;
345     if (svn_fs_revision_root(&fs_root, fs, revnum, subpool) != SVN_NO_ERROR)
346         return false;
347
348     svn_boolean_t is_dir;
349     if (svn_fs_is_dir(&is_dir, fs_root, pathname, subpool) != SVN_NO_ERROR)
350         return false;
351
352     return is_dir;
353 }
354
355 time_t get_epoch(char *svn_date)
356 {
357     struct tm tm;
358     memset(&tm, 0, sizeof tm);
359     QByteArray date(svn_date, strlen(svn_date) - 8);
360     strptime(date, "%Y-%m-%dT%H:%M:%S", &tm);
361     return timegm(&tm);
362 }
363
364 class SvnRevision
365 {
366 public:
367     AprAutoPool pool;
368     QHash<QString, Repository::Transaction *> transactions;
369     MatchRuleList matchRules;
370     RepositoryHash repositories;
371     IdentityHash identities;
372
373     svn_fs_t *fs;
374     svn_fs_root_t *fs_root;
375     int revnum;
376
377     // must call fetchRevProps first:
378     QByteArray authorident;
379     QByteArray log;
380     uint epoch;
381
382     SvnRevision(int revision, svn_fs_t *f, apr_pool_t *parent_pool)
383         : pool(parent_pool), fs(f), fs_root(0), revnum(revision)
384     {
385     }
386
387     int open()
388     {
389         SVN_ERR(svn_fs_revision_root(&fs_root, fs, revnum, pool));
390         return EXIT_SUCCESS;
391     }
392
393     int prepareTransactions();
394     int fetchRevProps();
395     int commit();
396
397     int exportEntry(const char *path, const svn_fs_path_change_t *change, apr_hash_t *changes);
398     int exportDispatch(const char *path, const svn_fs_path_change_t *change,
399                        const char *path_from, svn_revnum_t rev_from,
400                        apr_hash_t *changes, const QString &current, const Rules::Match &rule,
401                        apr_pool_t *pool);
402     int exportInternal(const char *path, const svn_fs_path_change_t *change,
403                        const char *path_from, svn_revnum_t rev_from,
404                        const QString &current, const Rules::Match &rule);
405     int recurse(const char *path, const svn_fs_path_change_t *change,
406                 const char *path_from, svn_revnum_t rev_from,
407                 apr_hash_t *changes, apr_pool_t *pool);
408 };
409
410 int SvnPrivate::exportRevision(int revnum)
411 {
412     SvnRevision rev(revnum, fs, global_pool);
413     rev.matchRules = matchRules;
414     rev.repositories = repositories;
415     rev.identities = identities;
416
417     // open this revision:
418     printf("Exporting revision %d ", revnum);
419     fflush(stdout);
420
421     if (rev.open() == EXIT_FAILURE)
422         return EXIT_FAILURE;
423
424     if (rev.prepareTransactions() == EXIT_FAILURE)
425         return EXIT_FAILURE;
426
427     if (rev.transactions.isEmpty()) {
428         printf(" nothing to do\n");
429         return EXIT_SUCCESS;    // no changes?
430     }
431
432     if (rev.commit() == EXIT_FAILURE)
433         return EXIT_FAILURE;
434
435     printf(" done\n");
436     return EXIT_SUCCESS;
437 }
438
439 int SvnRevision::prepareTransactions()
440 {
441     // find out what was changed in this revision:
442     apr_hash_t *changes;
443     SVN_ERR(svn_fs_paths_changed(&changes, fs_root, pool));
444     for (apr_hash_index_t *i = apr_hash_first(pool, changes); i; i = apr_hash_next(i)) {
445         const void *vkey;
446         void *value;
447         apr_hash_this(i, &vkey, NULL, &value);
448         const char *key = reinterpret_cast<const char *>(vkey);
449         svn_fs_path_change_t *change = reinterpret_cast<svn_fs_path_change_t *>(value);
450
451         if (exportEntry(key, change, changes) == EXIT_FAILURE)
452             return EXIT_FAILURE;
453     }
454
455     return EXIT_SUCCESS;
456 }
457
458 int SvnRevision::fetchRevProps()
459 {
460     apr_hash_t *revprops;
461     SVN_ERR(svn_fs_revision_proplist(&revprops, fs, revnum, pool));
462     svn_string_t *svnauthor = (svn_string_t*)apr_hash_get(revprops, "svn:author", APR_HASH_KEY_STRING);
463     svn_string_t *svndate = (svn_string_t*)apr_hash_get(revprops, "svn:date", APR_HASH_KEY_STRING);
464     svn_string_t *svnlog = (svn_string_t*)apr_hash_get(revprops, "svn:log", APR_HASH_KEY_STRING);
465
466     log = (char *)svnlog->data;
467     authorident = svnauthor ? identities.value((char *)svnauthor->data) : QByteArray();
468     epoch = get_epoch((char*)svndate->data);
469     if (authorident.isEmpty()) {
470         if (!svnauthor || svn_string_isempty(svnauthor))
471             authorident = "nobody <nobody@localhost>";
472         else
473             authorident = svnauthor->data + QByteArray(" <") +
474                           svnauthor->data + QByteArray("@localhost>");
475     }
476     return EXIT_SUCCESS;
477 }
478
479 int SvnRevision::commit()
480 {
481     // now create the commit
482     if (fetchRevProps() != EXIT_SUCCESS)
483         return EXIT_FAILURE;
484     foreach (Repository::Transaction *txn, transactions) {
485         txn->setAuthor(authorident);
486         txn->setDateTime(epoch);
487         txn->setLog(log);
488
489         txn->commit();
490         delete txn;
491     }
492
493     return EXIT_SUCCESS;
494 }
495
496 int SvnRevision::exportEntry(const char *key, const svn_fs_path_change_t *change,
497                              apr_hash_t *changes)
498 {
499     AprAutoPool revpool(pool.data());
500     QString current = QString::fromUtf8(key);
501
502     // was this copied from somewhere?
503     svn_revnum_t rev_from;
504     const char *path_from;
505     SVN_ERR(svn_fs_copied_from(&rev_from, &path_from, fs_root, key, revpool));
506
507     // is this a directory?
508     svn_boolean_t is_dir;
509     SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool));
510     if (is_dir) {
511         if (path_from == NULL) {
512             // no, it's a new directory being added
513             // Git doesn't handle directories, so we don't either
514             //qDebug() << "   mkdir ignored:" << key;
515             return EXIT_SUCCESS;
516         }
517
518         current += '/';
519         qDebug() << "   " << key << "was copied from" << path_from << "rev" << rev_from;
520     }
521
522     // find the first rule that matches this pathname
523     MatchRuleList::ConstIterator match = findMatchRule(matchRules, revnum, current);
524     if (match != matchRules.constEnd()) {
525         const Rules::Match &rule = *match;
526         return exportDispatch(key, change, path_from, rev_from, changes, current, rule, revpool);
527     }
528
529     if (is_dir && path_from != NULL) {
530         qDebug() << current << "is a copy-with-history, auto-recursing";
531         return recurse(key, change, path_from, rev_from, changes, revpool);
532     } else if (wasDir(fs, revnum - 1, key, revpool)) {
533         qDebug() << current << "was a directory; ignoring";
534     } else if (change->change_kind == svn_fs_path_change_delete) {
535         qDebug() << current << "is being deleted but I don't know anything about it; ignoring";
536     } else {
537         qCritical() << current << "did not match any rules; cannot continue";
538         return EXIT_FAILURE;
539     }
540
541     return EXIT_SUCCESS;
542 }
543
544 int SvnRevision::exportDispatch(const char *key, const svn_fs_path_change_t *change,
545                                 const char *path_from, svn_revnum_t rev_from,
546                                 apr_hash_t *changes, const QString &current,
547                                 const Rules::Match &rule, apr_pool_t *pool)
548 {
549     if(CommandLineParser::instance()->contains( QLatin1String("debug-rules")))
550       qDebug() << "    " << qPrintable(current) << "matched rule:" << rule.lineNumber << "(" << rule.rx.pattern() << ")";
551     switch (rule.action) {
552     case Rules::Match::Ignore:
553         // ignore rule
554         //qDebug() << "   " << qPrintable(current) << "rev" << revnum
555         //         << "-> ignored (rule" << rule << ")";
556         return EXIT_SUCCESS;
557
558     case Rules::Match::Recurse:
559         return recurse(key, change, path_from, rev_from, changes, pool);
560
561     case Rules::Match::Export:
562         return exportInternal(key, change, path_from, rev_from, current, rule);
563     }
564
565     // never reached
566     return EXIT_FAILURE;
567 }
568
569 int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *change,
570                                 const char *path_from, svn_revnum_t rev_from,
571                                 const QString &current, const Rules::Match &rule)
572 {
573     QString svnprefix, repository, branch, path;
574     splitPathName(rule, current, &svnprefix, &repository, &branch, &path);
575
576     printf(".");
577     fflush(stdout);
578 //                qDebug() << "   " << qPrintable(current) << "rev" << revnum << "->"
579 //                         << qPrintable(repository) << qPrintable(branch) << qPrintable(path);
580
581     if (path.isEmpty() && path_from != NULL) {
582         QString previous = QString::fromUtf8(path_from) + '/';
583         MatchRuleList::ConstIterator prevmatch =
584             findMatchRule(matchRules, rev_from, previous, NoIgnoreRule);
585         if (prevmatch != matchRules.constEnd()) {
586             QString prevsvnprefix, prevrepository, prevbranch, prevpath;
587             splitPathName(*prevmatch, previous, &prevsvnprefix, &prevrepository,
588                           &prevbranch, &prevpath);
589
590             if (!prevpath.isEmpty()) {
591                 qDebug() << qPrintable(current) << "is a partial branch of repository"
592                          << qPrintable(prevrepository) << "branch"
593                          << qPrintable(prevbranch) << "subdir"
594                          << qPrintable(prevpath);
595             } else if (prevrepository != repository) {
596                 qWarning() << qPrintable(current) << "rev" << revnum
597                            << "is a cross-repository copy (from repository"
598                            << qPrintable(prevrepository) << "branch"
599                            << qPrintable(prevbranch) << "path"
600                            << qPrintable(prevpath) << "rev" << rev_from << ")";
601             } else if (prevbranch == branch) {
602                 // same branch and same repository
603                 qDebug() << qPrintable(current) << "rev" << revnum
604                          << "is an SVN rename from"
605                          << qPrintable(previous) << "rev" << rev_from;
606                 return EXIT_SUCCESS;
607             } else {
608                 // same repository but not same branch
609                 // this means this is a plain branch
610                 qDebug() << qPrintable(repository) << ": branch"
611                          << qPrintable(branch) << "is branching from"
612                          << qPrintable(prevbranch);
613
614                 Repository *repo = repositories.value(repository, 0);
615                 if (!repo) {
616                     qCritical() << "Rule" << rule
617                                 << "references unknown repository" << repository;
618                     return EXIT_FAILURE;
619                 }
620
621                 repo->createBranch(branch, revnum, prevbranch, rev_from);
622                 if (rule.annotate) {
623                     // create an annotated tag
624                     fetchRevProps();
625                     repo->createAnnotatedTag(branch, svnprefix, revnum, authorident,
626                                              epoch, log);
627                 }
628                 return EXIT_SUCCESS;
629             }
630         }
631     }
632
633     Repository::Transaction *txn = transactions.value(repository + branch, 0);
634     if (!txn) {
635         Repository *repo = repositories.value(repository, 0);
636         if (!repo) {
637             qCritical() << "Rule" << rule
638                         << "references unknown repository" << repository;
639             return EXIT_FAILURE;
640         }
641
642         txn = repo->newTransaction(branch, svnprefix, revnum);
643         if (!txn)
644             return EXIT_FAILURE;
645
646         transactions.insert(repository + branch, txn);
647     }
648
649     if (change->change_kind == svn_fs_path_change_delete) {
650         txn->deleteFile(path);
651     } else if (!current.endsWith('/')) {
652         dumpBlob(txn, fs_root, key, path, pool);
653     } else {
654         txn->deleteFile(path);
655         recursiveDumpDir(txn, fs_root, key, path, pool);
656     }
657
658     return EXIT_SUCCESS;
659 }
660
661 int SvnRevision::recurse(const char *path, const svn_fs_path_change_t *change,
662                          const char *path_from, svn_revnum_t rev_from,
663                          apr_hash_t *changes, apr_pool_t *pool)
664 {
665     // get the dir listing
666     apr_hash_t *entries;
667     SVN_ERR(svn_fs_dir_entries(&entries, fs_root, path, pool));
668
669     AprAutoPool dirpool(pool);
670     for (apr_hash_index_t *i = apr_hash_first(pool, entries); i; i = apr_hash_next(i)) {
671         dirpool.clear();
672         const void *vkey;
673         void *value;
674         apr_hash_this(i, &vkey, NULL, &value);
675
676         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
677         if (dirent->kind != svn_node_dir)
678             continue;           // not a directory, so can't recurse; skip
679
680         QByteArray entry = path + QByteArray("/") + dirent->name;
681         QByteArray entryFrom;
682         if (path_from)
683             entryFrom = path_from + QByteArray("/") + dirent->name;
684
685         // check if this entry is in the changelist for this revision already
686         svn_fs_path_change_t *otherchange =
687             (svn_fs_path_change_t*)apr_hash_get(changes, entry.constData(), APR_HASH_KEY_STRING);
688         if (otherchange && otherchange->change_kind == svn_fs_path_change_add) {
689             qDebug() << entry << "rev" << revnum
690                      << "is in the change-list, deferring to that one";
691             continue;
692         }
693
694         QString current = QString::fromUtf8(entry);
695         if (dirent->kind == svn_node_dir)
696             current += '/';
697
698         // find the first rule that matches this pathname
699         MatchRuleList::ConstIterator match = findMatchRule(matchRules, revnum, current);
700         if (match != matchRules.constEnd()) {
701             if (exportDispatch(entry, change, entryFrom.isNull() ? 0 : entryFrom.constData(),
702                                rev_from, changes, current, *match, dirpool) == EXIT_FAILURE)
703                 return EXIT_FAILURE;
704         } else {
705             qCritical() << current << "rev" << revnum
706                         << "did not match any rules; cannot continue";
707             return EXIT_FAILURE;
708         }
709     }
710
711     return EXIT_SUCCESS;
712 }