Changeset View
Changeset View
Standalone View
Standalone View
gemini/cloud/git/gitlogmodel.cpp
Show All 15 Lines | |||||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "gitlogmodel.h" | 22 | #include "gitlogmodel.h" | ||
23 | 23 | | |||
24 | #include <qgit2.h> | 24 | // #include <qgit2.h> | ||
25 | #include <qgit2/qgitglobal.h> | 25 | // #include <qgit2/qgitglobal.h> | ||
26 | | ||||
27 | #include <git2.h> | ||||
28 | #include <git2/repository.h> | ||||
26 | 29 | | |||
27 | #include <QDateTime> | 30 | #include <QDateTime> | ||
28 | #include <QDebug> | 31 | #include <QDebug> | ||
29 | 32 | | |||
30 | struct LogEntry { | 33 | struct LogEntry { | ||
31 | public: | 34 | public: | ||
32 | LogEntry() {} | 35 | LogEntry() {} | ||
33 | QString authorName; | 36 | QString authorName; | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 121 | { | |||
123 | } | 126 | } | ||
124 | } | 127 | } | ||
125 | 128 | | |||
126 | void GitLogModel::refreshLog() | 129 | void GitLogModel::refreshLog() | ||
127 | { | 130 | { | ||
128 | beginResetModel(); | 131 | beginResetModel(); | ||
129 | qDeleteAll(d->entries); | 132 | qDeleteAll(d->entries); | ||
130 | d->entries.clear(); | 133 | d->entries.clear(); | ||
131 | try { | | |||
132 | LibQGit2::Repository repo; | | |||
133 | repo.open(QString("%1/.git").arg(d->repoDir)); | | |||
134 | | ||||
135 | LibQGit2::RevWalk rw(repo); | | |||
136 | 134 | | |||
137 | rw.setSorting(LibQGit2::RevWalk::Topological); | 135 | git_repository* repository; | ||
136 | int error = git_repository_open(&repository, QString("%1/.git").arg(d->repoDir).toLatin1()); | ||||
137 | if(error != 0) { const git_error* err = giterr_last(); qDebug() << "Kapow, error code from git2 was" << error << "which is described as" << err->message; return; } | ||||
138 | | ||||
139 | git_revwalk *walker; | ||||
140 | error = git_revwalk_new(&walker, repository); | ||||
141 | if(error != 0) { const git_error* err = giterr_last(); qDebug() << "Kapow, error code from git2 was" << error << "which is described as" << err->message; return; } | ||||
142 | error = git_revwalk_push_range(walker, "HEAD~100..HEAD"); | ||||
143 | if(error != 0) { const git_error* err = giterr_last(); qDebug() << "Kapow, error code from git2 was" << error << "which is described as" << err->message; return; } | ||||
144 | | ||||
145 | git_oid oid; | ||||
146 | git_commit *commit = NULL; | ||||
147 | while (git_revwalk_next(&oid, walker) == 0) { | ||||
148 | error = git_commit_lookup(&commit, repository, &oid); | ||||
149 | if(error != 0) { const git_error* err = giterr_last(); qDebug() << "Kapow, error code from git2 was" << error << "which is described as" << err->message; return; } | ||||
138 | 150 | | |||
139 | rw.pushHead(); | 151 | const git_signature *author = git_commit_author(commit); | ||
140 | 152 | | |||
141 | LibQGit2::Commit commit; | | |||
142 | // loop control, limit the run to the hundred most recent commits | | |||
143 | int i = 100; | | |||
144 | while(rw.next(commit)) { | | |||
145 | if(--i < 0) { | | |||
146 | break; | | |||
147 | } | | |||
148 | LogEntry* entry = new LogEntry(); | 153 | LogEntry* entry = new LogEntry(); | ||
149 | entry->authorName = commit.author().name(); | 154 | entry->authorName = author->name; | ||
150 | if(entry->authorName.isEmpty()) | 155 | if(entry->authorName.isEmpty()) | ||
151 | entry->authorName = "Unknown"; | 156 | entry->authorName = "Unknown"; | ||
152 | entry->authorEmail = commit.author().email(); | 157 | entry->authorEmail = author->email; | ||
153 | entry->time = commit.dateTime(); | 158 | | ||
154 | entry->oid = commit.oid().format(); | 159 | git_time_t time = git_commit_time(commit); | ||
155 | entry->shortMessage = commit.shortMessage(); | 160 | entry->time = QDateTime::fromMSecsSinceEpoch(time * 1000); | ||
156 | entry->message = commit.message(); | 161 | | ||
162 | entry->oid = QString::fromAscii(git_oid_tostr_s(git_commit_id(commit))); | ||||
163 | entry->message = QString::fromAscii(git_commit_message(commit)); | ||||
164 | entry->shortMessage = entry->message.left(120).split(QRegExp("(\\r|\\n)")).first(); | ||||
165 | | ||||
157 | d->entries.append(entry); | 166 | d->entries.append(entry); | ||
158 | } | | |||
159 | 167 | | |||
160 | } catch (const LibQGit2::Exception& ex) { | 168 | git_commit_free(commit); | ||
161 | qDebug() << ex.what() << ex.category(); | | |||
162 | } | 169 | } | ||
170 | git_repository_free(repository); | ||||
163 | endResetModel(); | 171 | endResetModel(); | ||
164 | } | 172 | } |