From 2a7a37ff0f62f5dc06acf95d8084cd0521d6a651 Mon Sep 17 00:00:00 2001 From: Raja R Harinath Date: Sun, 11 Jul 2010 19:08:53 +0530 Subject: Make error handling of --incremental and --resume-from idempotent When --resume-from failed in incremental mode, the log files that detected the error condition were truncated. So, if the same command line was executed again, the invocation would go through. We now restore the log files from backup when we detect we're going to fail. The restored log files may not all be the same as we originally started with, but we only truncate information that would anyway be truncated on the next successful run. --- src/main.cpp | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 5d0a1fc..37b8615 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,34 +123,50 @@ int main(int argc, char **argv) int cutoff = resume_from ? resume_from : INT_MAX; retry: - int min_rev = 0; + int min_rev = 1; foreach (Rules::Repository rule, rules.repositories()) { Repository *repo = new Repository(rule); repositories.insert(rule.name, repo); if (incremental) { int repo_next = repo->setupIncremental(cutoff); - if (cutoff < min_rev) { - qWarning() << "rewinding; did you hit Ctrl-C?"; + + /* + * cutoff < resume_from => error exit eventually + * repo_next == cutoff => probably truncated log + */ + if (cutoff < resume_from && repo_next == cutoff) + /* + * Restore the log file so we fail the next time + * svn2git is invoked with the same arguments + */ + repo->restoreLog(); + + if (cutoff < min_rev) + /* + * We've rewound before the last revision of some + * repository that we've already seen. Start over + * from the beginning. (since cutoff is decreasing, + * we're sure we'll make forward progress eventually) + */ goto retry; - } + if (min_rev < repo_next) min_rev = repo_next; } } - if (incremental && resume_from) { - if (cutoff < resume_from) { - qCritical() << "Cannot resume from" << resume_from << "as there are errors in revision" << cutoff; - return EXIT_FAILURE; - } - if (min_rev < resume_from) - qDebug() << "skipping revisions" << min_rev << "to" << resume_from - 1 << "as requested"; - min_rev = resume_from; + if (cutoff < resume_from) { + qCritical() << "Cannot resume from" << resume_from + << "as there are errors in revision" << cutoff; + return EXIT_FAILURE; } - if (min_rev < 1) - min_rev = 1; + if (min_rev < resume_from) + qDebug() << "skipping revisions" << min_rev << "to" << resume_from - 1 << "as requested"; + + if (resume_from) + min_rev = resume_from; Svn::initialize(); Svn svn(args->arguments().first()); -- cgit v1.2.1