Commit 33379258 authored by Simon Persson's avatar Simon Persson
Browse files

Update to work with version 0.18 of libgit2.

parent ee729e4f
......@@ -5,24 +5,18 @@
#include <QListView>
#include <QTreeView>
#include <KLocale>
#include <KMessageBox>
#include <KRun>
FileDigger::FileDigger(const QString &pRepositoryPath, const QString &pBranchName, QWidget *parent) :
QSplitter(parent)
FileDigger::FileDigger(MergedRepository *pRepository, QWidget *pParent)
: QSplitter(pParent)
{
mTreeView = new QTreeView();
mTreeView->setHeaderHidden(true);
mTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
MergedRepository *lRepository = new MergedRepository(this, pRepositoryPath, pBranchName);
if(!lRepository->openedSuccessfully()) {
KMessageBox::sorry(this, i18nc("@info:label messagebox", "The specified bup repository could not be opened."));
return;
}
mTreeModel = new MergedVfsModel(lRepository, this);
mTreeView->setModel(mTreeModel);
addWidget(mTreeView);
connect(mTreeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
mMergedVfsModel = new MergedVfsModel(pRepository, this);
mMergedVfsView = new QTreeView();
mMergedVfsView->setHeaderHidden(true);
mMergedVfsView->setSelectionMode(QAbstractItemView::SingleSelection);
mMergedVfsView->setModel(mMergedVfsModel);
addWidget(mMergedVfsView);
connect(mMergedVfsView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(updateVersionModel(QModelIndex,QModelIndex)));
mListView = new QListView();
......@@ -32,12 +26,12 @@ FileDigger::FileDigger(const QString &pRepositoryPath, const QString &pBranchNam
addWidget(mListView);
connect(mListView, SIGNAL(activated(QModelIndex)), SLOT(open(QModelIndex)));
mTreeView->setFocus();
mMergedVfsView->setFocus();
}
void FileDigger::updateVersionModel(const QModelIndex &pCurrent, const QModelIndex &pPrevious) {
Q_UNUSED(pPrevious)
mVersionModel->setNode(mTreeModel->node(pCurrent));
mVersionModel->setNode(mMergedVfsModel->node(pCurrent));
}
void FileDigger::open(const QModelIndex &pIndex) {
......
......@@ -3,6 +3,7 @@
#include <QSplitter>
class MergedVfsModel;
class MergedRepository;
class VersionListModel;
class QTreeView;
class QListView;
......@@ -12,15 +13,15 @@ class FileDigger : public QSplitter
{
Q_OBJECT
public:
explicit FileDigger(const QString &pRepositoryPath, const QString &pBranchName, QWidget *parent = 0);
explicit FileDigger(MergedRepository *pRepository, QWidget *pParent = 0);
protected slots:
void updateVersionModel(const QModelIndex &pCurrent, const QModelIndex &pPrevious);
void open(const QModelIndex &pIndex);
protected:
MergedVfsModel *mTreeModel;
QTreeView *mTreeView;
MergedVfsModel *mMergedVfsModel;
QTreeView *mMergedVfsView;
VersionListModel *mVersionModel;
QListView *mListView;
......
#include "filedigger.h"
#include "mergedvfs.h"
#include <git2/threads.h>
#include <QFile>
#include <QTextStream>
#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <KMessageBox>
static const char version[] = "0.4";
static const char description[] = I18N_NOOP("Browser for bup archives.");
......@@ -29,8 +33,21 @@ int main(int pArgCount, char **pArgArray) {
"You must supply the path to a bup or git repository that "
"you wish to open for viewing.").toString());
}
FileDigger *lFileDigger = new FileDigger(lParsedArguments->arg(0),
lParsedArguments->getOption("branch"));
// This needs to be called first thing, before any other calls to libgit2.
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."));
return -1;
}
FileDigger *lFileDigger = new FileDigger(lRepository);
lFileDigger->show();
return lApp.exec();
int lRetVal = lApp.exec();
delete lFileDigger;
delete lRepository;
git_threads_shutdown();
return lRetVal;
}
......@@ -176,7 +176,7 @@ MergedRepository::MergedRepository(QObject *pParent, const QString &pRepositoryP
continue;
}
git_time_t lTime = git_commit_time(lCommit);
mVersionMap.insert(*git_commit_tree_oid(lCommit), mVersions.count());
mVersionMap.insert(*git_commit_tree_id(lCommit), mVersions.count());
mVersions.append(new VersionData(lTime, lTime, 0));
git_commit_free(lCommit);
}
......
......@@ -234,7 +234,7 @@ int ChunkFile::seek(quint64 pOffset) {
// the remainder of the offset will be a local offset into the blob or into the subtree.
lLocalOffset -= lLowerOffset;
if(S_ISDIR(git_tree_entry_attributes(lLowerEntry))) {
if(S_ISDIR(git_tree_entry_filemode(lLowerEntry))) {
git_tree *lTree;
if(0 != git_tree_lookup(&lTree, mRepository, git_tree_entry_id(lLowerEntry))) {
return KIO::ERR_COULD_NOT_SEEK;
......@@ -293,7 +293,7 @@ int ChunkFile::read(QByteArray &pChunk, int pReadSize) {
while(true) {
if(lCurrentPos->mIndex < git_tree_entrycount(lCurrentPos->mTree)) {
const git_tree_entry *lTreeEntry = git_tree_entry_byindex(lCurrentPos->mTree, lCurrentPos->mIndex);
if(S_ISDIR(git_tree_entry_attributes(lTreeEntry))) {
if(S_ISDIR(git_tree_entry_filemode(lTreeEntry))) {
git_tree *lTree;
if(0 != git_tree_lookup(&lTree, mRepository, git_tree_entry_id(lTreeEntry))) {
return KIO::ERR_COULD_NOT_READ;
......@@ -423,7 +423,7 @@ void Branch::generateSubNodes() {
}
QString lCommitTimeLocal = vfsTimeToString(git_commit_time(lCommit));
if(!mSubNodes->contains(lCommitTimeLocal)) {
Directory * lDirectory = new ArchivedDirectory(this, git_commit_tree_oid(lCommit),
Directory * lDirectory = new ArchivedDirectory(this, git_commit_tree_id(lCommit),
lCommitTimeLocal, DEFAULT_MODE_DIRECTORY);
lDirectory->mMtime = git_commit_time(lCommit);
mSubNodes->insert(lCommitTimeLocal, lDirectory);
......@@ -444,17 +444,20 @@ Repository::Repository(QObject *pParent, const QString &pRepositoryPath)
return;
}
git_strarray lBranchNames;
git_branch_list(&lBranchNames, mRepository, GIT_BRANCH_LOCAL);
git_reference_list(&lBranchNames, mRepository, GIT_REF_LISTALL);
for(uint i = 0; i < lBranchNames.count; ++i) {
QString lPath = objectName();
lPath.append(QString::fromLocal8Bit(lBranchNames.strings[i]));
struct stat lStat;
stat(lPath.toLocal8Bit(), &lStat);
if(lStat.st_atime > mAtime) {
mAtime = lStat.st_atime;
}
if(lStat.st_mtime > mMtime) {
mMtime = lStat.st_mtime;
QString lRefName = QString::fromLocal8Bit(lBranchNames.strings[i]);
if(lRefName.startsWith(QLatin1String("refs/heads/"))) {
QString lPath = objectName();
lPath.append(lRefName);
struct stat lStat;
stat(lPath.toLocal8Bit(), &lStat);
if(lStat.st_atime > mAtime) {
mAtime = lStat.st_atime;
}
if(lStat.st_mtime > mMtime) {
mMtime = lStat.st_mtime;
}
}
}
git_strarray_free(&lBranchNames);
......@@ -477,10 +480,13 @@ Repository::~Repository() {
void Repository::generateSubNodes() {
git_strarray lBranchNames;
git_branch_list(&lBranchNames, mRepository, GIT_BRANCH_LOCAL);
git_reference_list(&lBranchNames, mRepository, GIT_REF_LISTALL);
for(uint i = 0; i < lBranchNames.count; ++i) {
Branch *lBranch = new Branch(this, lBranchNames.strings[i]);
mSubNodes->insert(lBranch->objectName(), lBranch);
QString lRefName = QString::fromLocal8Bit(lBranchNames.strings[i]);
if(lRefName.startsWith(QLatin1String("refs/heads/"))) {
Branch *lBranch = new Branch(this, lBranchNames.strings[i]);
mSubNodes->insert(lBranch->objectName(), lBranch);
}
}
git_strarray_free(&lBranchNames);
}
......
......@@ -151,7 +151,7 @@ quint64 calculateChunkFileSize(const git_oid *pOid, git_repository *pRepository)
}
lLastChunkOffset += lEntryOffset;
pOid = git_tree_entry_id(lEntry);
lMode = git_tree_entry_attributes(lEntry);
lMode = git_tree_entry_filemode(lEntry);
git_tree_free(lTree);
} while(S_ISDIR(lMode));
......@@ -172,7 +172,7 @@ bool offsetFromName(const git_tree_entry *pEntry, quint64 &pUint) {
void getEntryAttributes(const git_tree_entry *pTreeEntry, uint &pMode, bool &pChunked, const git_oid *&pOid, QString &pName) {
pMode = git_tree_entry_attributes(pTreeEntry);
pMode = git_tree_entry_filemode(pTreeEntry);
pOid = git_tree_entry_id(pTreeEntry);
pName = QString::fromUtf8(git_tree_entry_name(pTreeEntry));
pChunked = false;
......
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