ソースを参照

Test with revwalk

Alexey Edelev 8 年 前
コミット
29e4d3cfcd
6 ファイル変更88 行追加14 行削除
  1. 4 4
      NiceGit.pro
  2. 0 3
      githandler.cpp
  3. 6 0
      gitreflog.cpp
  4. 16 0
      gitreflog.h
  5. 61 3
      gitrepository.cpp
  6. 1 4
      gitrepository.h

+ 4 - 4
NiceGit.pro

@@ -8,17 +8,17 @@ SOURCES += \
     main.cpp \
     githandler.cpp \
     gitrepository.cpp \
-    repositorymodel.cpp
+    repositorymodel.cpp \
+    gitreflog.cpp
 
 HEADERS += \
     githandler.h \
     gitrepository.h \
-    repositorymodel.h
+    repositorymodel.h \
+    gitreflog.h
 
 DISTFILES += \
     qml/MainView.qml
 
-DEPLOYMENT += $$DISTFILES
-
 RESOURCES += \
     resources.qrc

+ 0 - 3
githandler.cpp

@@ -5,10 +5,7 @@
 #include <qqml.h>
 
 #include <gitrepository.h>
-
-extern "C" {
 #include <git2.h>
-}
 
 GitHandler::GitHandler() : QObject()
   ,m_repositories(new RepositoryModel(this))

+ 6 - 0
gitreflog.cpp

@@ -0,0 +1,6 @@
+#include "gitreflog.h"
+
+GitReflog::GitReflog(GitRepository *repo)
+{
+
+}

+ 16 - 0
gitreflog.h

@@ -0,0 +1,16 @@
+#ifndef GITREFLOG_H
+#define GITREFLOG_H
+
+struct git_reflog;
+
+class GitRepository;
+
+class GitReflog
+{
+public:
+    GitReflog(GitRepository* repo);
+private:
+    git_reflog* m_reflog;
+};
+
+#endif // GITREFLOG_H

+ 61 - 3
gitrepository.cpp

@@ -15,11 +15,69 @@ GitRepository::GitRepository(const QString& root) : QObject()
         return;
     }
 
-    QFileInfo info(root);
     m_root = root;
-    m_name = info.dirName();
-    m_path = info.filePath();
+    m_path = git_repository_workdir(m_repo);
+    m_name = m_path;//TODO: replace with Human readable name
     qDebug() << "New repo:" << m_name << m_root << m_path;
+
+    //    git_reflog* reflog;
+
+    //    if(git_reflog_read(&reflog, m_repo, "HEAD") != 0) {
+    //        qDebug() << "reflogs could not be read";
+    //        return;
+    //    }
+
+    //    quint64 count = git_reflog_entrycount(reflog);
+    //    qDebug() << count;
+
+    //    for(quint64 i = 0; i < count; i++)
+    //    {
+    //        git_reflog_entry* entry = git_reflog_entry_byindex(reflog, i);
+    //        git_oid* oid = git_reflog_entry_id_new(entry);
+    //    }
+    //    git_reflog_free(reflog);
+
+
+    git_reference *out;
+    git_branch_t branch;
+    git_branch_iterator* iter;
+    git_branch_iterator_new(&iter, m_repo, GIT_BRANCH_ALL);
+
+    while(git_branch_next(&out, &branch, iter) == 0)
+    {
+        const char* branch_name;
+        git_branch_name(&branch_name, out);
+        qDebug() << branch_name;
+
+        git_revwalk* walk;
+        git_revwalk_new(&walk, m_repo);
+        git_revwalk_push_head(walk);
+        git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL);
+
+        git_oid newoid;
+        while(git_revwalk_next(&newoid, walk) == 0)
+        {
+            git_commit *wcommit;
+            if(git_commit_lookup(&wcommit, m_repo, &newoid) != 0 )
+            {
+                qDebug() << "git_commit_lookup error";
+                continue;
+            }
+
+            qDebug() << git_commit_id(wcommit);
+            qDebug() << git_commit_time( wcommit );
+            qDebug() << git_commit_message( wcommit );
+            qDebug() << git_commit_author( wcommit );
+
+            qDebug() << "=================================================";
+            git_commit_free( wcommit );
+        }
+
+        git_revwalk_free( walk );
+
+        git_reference_free(out);
+    }
+
 }
 
 GitRepository::~GitRepository()

+ 1 - 4
gitrepository.h

@@ -4,10 +4,7 @@
 #include <QObject>
 #include <QString>
 
-extern "C"
-{
-    struct git_repository;
-}
+struct git_repository;
 
 
 class GitRepository : public QObject