Commit 68b50c29 authored by Simon Persson's avatar Simon Persson

Filedigger: Complete the error handling for opening a bup repo

Previously did not abort and inform user when a branch failed to open. Restructure logic a bit to be able to detect different failures.
Fixes #21.
parent 2e91353c
......@@ -58,8 +58,16 @@ int main(int pArgCount, char **pArgArray) {
git_threads_init();
MergedRepository *lRepository = new MergedRepository(NULL, lParsedArguments->arg(0),
lParsedArguments->getOption("branch"));
if(!lRepository->openedSuccessfully()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox", "The specified bup repository could not be opened."));
if(!lRepository->open()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox, %1 is a folder path",
"The bup repository \"%1\" could not be opened. Check if the backups really are located there.",
lParsedArguments->arg(0)));
return -1;
}
if(!lRepository->readBranch()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox, %1 is the name of a repository branch",
"The branch \"%1\" could not be read. Either it does not exist or you do not have permission to read it.",
lParsedArguments->getOption("branch")));
return -1;
}
......
......@@ -30,8 +30,6 @@
typedef QMap<QString, MergedNode *> NameMap;
typedef QMapIterator<QString, MergedNode *> NameMapIterator;
git_revwalk *MergedNode::mRevisionWalker = NULL;
git_repository *MergedNode::mRepository = NULL;
bool mergedNodeLessThan(const MergedNode *a, const MergedNode *b) {
......@@ -196,41 +194,54 @@ MergedRepository::MergedRepository(QObject *pParent, const QString &pRepositoryP
if(!objectName().endsWith(QLatin1Char('/'))) {
setObjectName(objectName() + QLatin1Char('/'));
}
if(0 != git_repository_open(&mRepository, pRepositoryPath.toLocal8Bit())) {
qWarning() << "could not open repository " << pRepositoryPath;
}
MergedRepository::~MergedRepository() {
if(mRepository != NULL) {
git_repository_free(mRepository);
}
}
bool MergedRepository::open() {
if(0 != git_repository_open(&mRepository, objectName().toLocal8Bit())) {
qWarning() << "could not open repository " << objectName();
mRepository = NULL;
return;
return false;
}
if(0 != git_revwalk_new(&mRevisionWalker, mRepository)) {
qWarning() << "could not create a revision walker in repository " << pRepositoryPath;
mRevisionWalker = NULL;
return;
return true;
}
bool MergedRepository::readBranch() {
if(mRepository == NULL) {
return false;
}
git_revwalk *lRevisionWalker;
if(0 != git_revwalk_new(&lRevisionWalker, mRepository)) {
qWarning() << "could not create a revision walker in repository " << objectName();
return false;
}
QString lCompleteBranchName = QString::fromLatin1("refs/heads/");
lCompleteBranchName.append(mBranchName);
if(0 != git_revwalk_push_ref(mRevisionWalker, lCompleteBranchName.toLocal8Bit())) {
return;
if(0 != git_revwalk_push_ref(lRevisionWalker, lCompleteBranchName.toLocal8Bit())) {
qWarning() << "Unable to read branch \"" << mBranchName << "\" in repository " << objectName();
git_revwalk_free(lRevisionWalker);
return false;
}
bool lEmptyList = true;
git_oid lOid;
while(0 == git_revwalk_next(&lOid, mRevisionWalker)) {
while(0 == git_revwalk_next(&lOid, lRevisionWalker)) {
git_commit *lCommit;
if(0 != git_commit_lookup(&lCommit, mRepository, &lOid)) {
continue;
}
git_time_t lTime = git_commit_time(lCommit);
mVersionList.append(new VersionData(git_commit_tree_id(lCommit), lTime, lTime, 0));
lEmptyList = false;
git_commit_free(lCommit);
}
}
MergedRepository::~MergedRepository() {
if(mRepository != NULL) {
git_repository_free(mRepository);
}
if(mRevisionWalker != NULL) {
git_revwalk_free(mRevisionWalker);
}
git_revwalk_free(lRevisionWalker);
return !lEmptyList;
}
uint qHash(git_oid pOid) {
......
......@@ -81,7 +81,6 @@ public:
protected:
virtual void generateSubNodes();
static git_revwalk *mRevisionWalker;
static git_repository *mRepository;
uint mMode;
VersionList mVersionList;
......@@ -93,8 +92,11 @@ class MergedRepository: public MergedNode {
public:
MergedRepository(QObject *pParent, const QString &pRepositoryPath, const QString &pBranchName);
virtual ~MergedRepository();
bool open();
bool readBranch();
QString mBranchName;
bool openedSuccessfully() {return mRepository != NULL; }
};
#endif // MERGEDVFS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment