From 9d043bec3f5513985d613c007922f05bc6bcfd4b Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 1 Jul 2020 22:10:58 +0200 Subject: [PATCH] Made git branch iteration more compact. --- src/git.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/git.cpp b/src/git.cpp index 6110e00..5cfefc6 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -19,10 +19,10 @@ #include "fs-compat.hpp" #include "json.hpp" -#include -#include #include +#include +#include #include #include #include @@ -82,7 +82,7 @@ uint64_t get_last_id() uint64_t id{0}; git_branch_iterator *it; - if (git_branch_iterator_new(&it, _repo, GIT_BRANCH_ALL) == 0) + if (git_branch_iterator_new(&it, _repo, GIT_BRANCH_REMOTE) == 0) { git_reference *ref; git_branch_t type; @@ -90,18 +90,16 @@ uint64_t get_last_id() { const char *out{nullptr}; git_branch_name(&out, ref); - if (type == GIT_BRANCH_REMOTE) + const string branch_name{out}; + + size_t pos{branch_name.find(branch_prefix)}; + if (pos != string::npos) { - const string branch_name{out}; - size_t pos{branch_name.find(branch_prefix)}; - if (pos != string::npos) + pos += branch_prefix.size(); + uint64_t newid{stoull(branch_name.substr(pos))}; + if (newid > id) { - pos += branch_prefix.size(); - uint64_t newid{stoull(branch_name.substr(pos))}; - if (newid > id) - { - id = newid; - } + id = newid; } } git_reference_free(ref);