diff options
-rw-r--r-- | gentoobrowse-api/service/maintenanceGitOperations.cpp | 18 | ||||
-rw-r--r-- | gentoobrowse-api/service/utils/git.cpp | 31 | ||||
-rw-r--r-- | gentoobrowse-api/service/utils/git.h | 7 |
3 files changed, 50 insertions, 6 deletions
diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp index bf90116..33340e8 100644 --- a/gentoobrowse-api/service/maintenanceGitOperations.cpp +++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp @@ -16,6 +16,7 @@ #include <portage-models.h> #include "utils/git.h" #include "converters.h" +#include <compileTimeFormatter.h> namespace Gentoo { namespace Service { @@ -40,10 +41,13 @@ namespace Gentoo { return onFile(delta, fileset); } + AdHocFormatter(UpdatingChangeLog, "Updating change log for repository %? with range %?...%?\n"); + AdHocFormatter(UpdatedChangeLog, "Updated change log for repository %?, added %? new entries\n"); static void writeChangeLog(DB::Connection * db, int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, const git_oid & headCommitOid) { + UpdatingChangeLog::write(std::cerr, repoId, lastCommitOid, headCommitOid); auto cli = sql::maintenance::changeLogInsert.modify(db); cli->bindParamI(0, repoId); // Set up walker @@ -52,7 +56,7 @@ namespace Gentoo { gitSafe(git_revwalk_hide, walker.get(), &lastCommitOid); git_oid oid; - char str[GIT_OID_HEXSZ + 1]; + unsigned int count = 0; // Walk through revisions while (!git_revwalk_next(&oid, walker.get())) { // Get commit @@ -75,17 +79,17 @@ namespace Gentoo { gitSafe(git_diff_foreach, diff.get(), onFile<float>, onFile<const git_diff_binary *>, nullptr, nullptr, &fs); // Insert commit into DB - git_oid_tostr(str, sizeof(str), &oid); - cli->bindParamS(1, str); auto sig = git_commit_author(commit.get()); + cli->bindParamS(1, *oid); cli->bindParamT(2, boost::posix_time::from_time_t(sig->when.time)); cli->bindParamS(3, git_commit_summary(commit.get())); cli->bindParamS(4, git_commit_body(commit.get())); cli->bindParamS(5, sig->name); cli->bindParamS(6, sig->email); cli->bindParamS(7, Slicer::packPqArray(fs)); - cli->execute(); + count += cli->execute(); } + UpdatedChangeLog::write(std::cerr, repoId, count); } void @@ -152,9 +156,11 @@ namespace Gentoo { writeChangesToFileList(db, repoId, repo.get(), lastCommitOid, headCommitOid); } + AdHocFormatter(FindingChanges, "Finding changes for repository %? with range %?...%?\n"); void writeChangesToFileList(DB::Connection * db, int64_t repoId, git_repository * repo, const git_oid & lastCommitOid, const git_oid & headCommitOid) { + FindingChanges::write(std::cerr, repoId, lastCommitOid, headCommitOid); auto lastCommit = gitSafeGet(git_commit_lookup, git_commit_free, repo, &lastCommitOid); auto headCommit = gitSafeGet(git_commit_lookup, git_commit_free, repo, &headCommitOid); auto lastTree = gitSafeGet(git_commit_tree, git_tree_free, lastCommit.get()); @@ -188,9 +194,12 @@ namespace Gentoo { dbc->execute("SET search_path = public, pg_catalog"); } + AdHocFormatter(UpdatingFileContent, "Updating file content\n"); + AdHocFormatter(UpdatedFileContent, "Updated file content\n"); void Maintenance::applyFileChanges(DB::Connection * dbc, const boost::filesystem::path & repoRoot) const { + UpdatingFileContent::write(std::cerr); FileProcessors fps; for (const auto & fpf : fpfs) { fps[fpf.first] = fpf.second(); @@ -229,6 +238,7 @@ namespace Gentoo { for (const auto & fp : fps) { fp.second->tidy(dbc); } + UpdatedFileContent::write(std::cerr); } } diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp index ce1556a..52c31d1 100644 --- a/gentoobrowse-api/service/utils/git.cpp +++ b/gentoobrowse-api/service/utils/git.cpp @@ -16,6 +16,14 @@ namespace Gentoo { throw ::Gentoo::GitError(*fn, err, e->klass, e->message); } + std::string + operator*(const git_oid & oid) + { + std::string str(GIT_OID_HEXSZ, ' '); + git_oid_tostr(&str.front(), GIT_OID_HEXSZ + 1, &oid); + return str; + } + AdHocFormatter(RefSpec, "refs/heads/%?:refs/remotes/%?/%?"); std::unique_ptr<git_annotated_commit, void (*)(git_annotated_commit*)> gitFetch(git_repository * repo, git_remote * remote, const char * remoteBranchName) @@ -32,6 +40,8 @@ namespace Gentoo { return gitSafeGet(git_annotated_commit_from_revspec, git_annotated_commit_free, repo, "FETCH_HEAD"); } + AdHocFormatter(FastForward, "Performing fast-forward %? -> %?\n"); + AdHocFormatter(CheckOut, "Checking out %?\n"); git_oid gitFastForward(git_repository * repo, git_annotated_commit * fetch_head) { @@ -52,24 +62,41 @@ namespace Gentoo { // Perform fast-forward auto fetch_head_id = *git_annotated_commit_id(fetch_head); auto fetch_head_object = gitSafeGet(git_object_lookup, git_object_free, repo, &fetch_head_id, GIT_OBJ_ANY); + FastForward::write(std::cerr, *git_reference_target(head.get()), fetch_head_id); gitSafeGet(git_reference_set_target, git_reference_free, head.get(), &fetch_head_id, "fast-forward"); // Checkout new head + CheckOut::write(std::cerr, fetch_head_id); auto checkout_options = gitSafeGet(git_checkout_init_options, 0u + GIT_CHECKOUT_OPTIONS_VERSION); checkout_options.checkout_strategy = GIT_CHECKOUT_FORCE; gitSafe(git_checkout_head, repo, &checkout_options); return fetch_head_id; } + AdHocFormatter(Updating, "Updating repository in %? from %?/%?\n"); + AdHocFormatter(UpdateComplete, "Update complete to %?\n"); void updateRepository(const std::string & path, const std::string & upstream, const std::string & branch) { + Updating::write(std::cerr, path, upstream, branch); auto repo = gitSafeGet(git_repository_open, git_repository_free, path.c_str()); auto origin = gitSafeGet(git_remote_lookup, git_remote_free, repo.get(), upstream.c_str()); auto fetchHead = gitFetch(repo.get(), origin.get(), branch.c_str()); - gitFastForward(repo.get(), fetchHead.get()); + auto oid = gitFastForward(repo.get(), fetchHead.get()); + UpdateComplete::write(std::cerr, oid); } - } } } + +namespace std { + std::ostream & + operator<<(std::ostream & s, const git_oid & oid) + { + char str[GIT_OID_HEXSZ + 1]; + git_oid_tostr(str, sizeof(str), &oid); + s.write(str, GIT_OID_HEXSZ); + return s; + } +} + diff --git a/gentoobrowse-api/service/utils/git.h b/gentoobrowse-api/service/utils/git.h index ec3afad..d1e6336 100644 --- a/gentoobrowse-api/service/utils/git.h +++ b/gentoobrowse-api/service/utils/git.h @@ -1,5 +1,6 @@ #include <memory> #include <git2.h> +#include <ostream> namespace Gentoo { namespace Utils { @@ -33,6 +34,8 @@ namespace Gentoo { return r; } + std::string operator*(const git_oid &); + std::unique_ptr<git_annotated_commit, void (*)(git_annotated_commit*)> gitFetch(git_repository * repo, git_remote * remote, const char * branch); @@ -45,3 +48,7 @@ namespace Gentoo { } } +namespace std { + std::ostream & operator<<(std::ostream &, const git_oid &); +} + |