diff options
author | Raja R Harinath <harinath@hurrynot.org> | 2010-07-11 19:08:53 +0530 |
---|---|---|
committer | Raja R Harinath <harinath@hurrynot.org> | 2010-07-11 21:01:22 +0530 |
commit | 2a7a37ff0f62f5dc06acf95d8084cd0521d6a651 (patch) | |
tree | d81e5473c68ec6945574a240d0f2ca7d0d168a43 /src/repository.cpp | |
parent | c0bc64179f96b5d2e13a905f1f6867cce3ac9558 (diff) | |
download | svn2git-2a7a37ff0f62f5dc06acf95d8084cd0521d6a651.tar svn2git-2a7a37ff0f62f5dc06acf95d8084cd0521d6a651.tar.gz svn2git-2a7a37ff0f62f5dc06acf95d8084cd0521d6a651.tar.bz2 svn2git-2a7a37ff0f62f5dc06acf95d8084cd0521d6a651.tar.xz svn2git-2a7a37ff0f62f5dc06acf95d8084cd0521d6a651.zip |
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.
Diffstat (limited to 'src/repository.cpp')
-rw-r--r-- | src/repository.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/repository.cpp b/src/repository.cpp index f57cdbb..57db6c7 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -154,6 +154,8 @@ int Repository::setupIncremental(int &cutoff) int last_revnum = 0; qint64 pos = 0; + int retval = 0; + QString bkup = logfile.fileName() + ".old"; while (!logfile.atEnd()) { pos = logfile.pos(); @@ -179,9 +181,8 @@ int Repository::setupIncremental(int &cutoff) << "got" << QString::number(last_revnum) << "and then" << QString::number(revnum); - if (mark > last_valid_mark) { - qWarning() << name << "unknown commit mark found: rewinding"; + qWarning() << name << "unknown commit mark found: rewinding -- did you hit Ctrl-C?"; cutoff = revnum; goto beyond_cutoff; } @@ -198,20 +199,37 @@ int Repository::setupIncremental(int &cutoff) br.marks.append(mark); } - return last_revnum + 1; + retval = last_revnum + 1; + if (retval == cutoff) + /* + * If a stale backup file exists already, remove it, so that + * we don't confuse ourselves in 'restoreLog()' + */ + QFile::remove(bkup); + + return retval; beyond_cutoff: // backup file, since we'll truncate - QString bkup = logfile.fileName() + ".old"; QFile::remove(bkup); logfile.copy(bkup); // truncate, so that we ignore the rest of the revisions - qDebug() << name << "truncating history to" << cutoff; + qDebug() << name << "truncating history to revision" << cutoff; logfile.resize(pos); return cutoff; } +void Repository::restoreLog() +{ + QString file = logFileName(name); + QString bkup = file + ".old"; + if (!QFile::exists(bkup)) + return; + QFile::remove(file); + QFile::rename(bkup, file); +} + Repository::~Repository() { Q_ASSERT(outstandingTransactions == 0); |