1- #include < exception>
21#include < format>
32#include < git2.h>
43#include < git2/oid.h>
54#include < git2/refs.h>
65#include < git2/types.h>
6+ #include < sstream>
77#include < string_view>
88#include < vector>
99
@@ -77,11 +77,11 @@ std::vector<std::string> get_tags_for_commit(repository_wrapper& repo, const git
7777 }
7878 }
7979
80- git_strarray_dispose (&tag_names);
80+ git_strarray_dispose (&tag_names); // TODO: refactor git_strarray_wrapper to use it here
8181 return tags;
8282}
8383
84- std::vector<std::string> get_branches_for_commit (repository_wrapper& repo, git_branch_t type, const git_oid* commit_oid, const std::string exclude_branch)
84+ std::vector<std::string> get_branches_for_commit (repository_wrapper& repo, git_branch_t type, const git_oid& commit_oid, const std::string exclude_branch)
8585{
8686 std::vector<std::string> branches;
8787
@@ -105,7 +105,7 @@ std::vector<std::string> get_branches_for_commit(repository_wrapper& repo, git_b
105105 }
106106 }
107107
108- if (branch_target && git_oid_equal (branch_target, commit_oid))
108+ if (branch_target && git_oid_equal (branch_target, & commit_oid))
109109 {
110110 std::string branch_name;
111111 branch_name = branch->name ();
@@ -139,28 +139,28 @@ struct commit_refs
139139 }
140140};
141141
142- commit_refs get_refs_for_commit (repository_wrapper& repo, const git_oid* commit_oid)
142+ commit_refs get_refs_for_commit (repository_wrapper& repo, const git_oid& commit_oid)
143143{
144144 commit_refs refs;
145145
146146 if (!repo.is_head_unborn ())
147147 {
148148 auto head = repo.head ();
149149 auto head_taget = head.target ();
150- if (git_oid_equal (head_taget, commit_oid))
150+ if (git_oid_equal (head_taget, & commit_oid))
151151 {
152152 refs.head_branch = head.short_name ();
153153 }
154154 }
155155
156- refs.tags = get_tags_for_commit (repo, commit_oid);
156+ refs.tags = get_tags_for_commit (repo, & commit_oid);
157157 refs.local_branches = get_branches_for_commit (repo, GIT_BRANCH_LOCAL, commit_oid, refs.head_branch );
158158 refs.remote_branches = get_branches_for_commit (repo, GIT_BRANCH_REMOTE, commit_oid, " " );
159159
160160 return refs;
161161}
162162
163- void print_refs (commit_refs refs)
163+ void print_refs (const commit_refs& refs)
164164{
165165 if (!refs.has_refs ())
166166 {
@@ -223,7 +223,7 @@ void print_commit(repository_wrapper& repo, const commit_wrapper& commit, std::s
223223 stream_colour_fn colour = termcolor::yellow;
224224 std::cout << colour << " commit " << buf;
225225
226- commit_refs refs = get_refs_for_commit (repo, & commit.oid ());
226+ commit_refs refs = get_refs_for_commit (repo, commit.oid ());
227227 print_refs (refs);
228228
229229 std::cout << termcolor::reset << std::endl;
@@ -247,7 +247,19 @@ void print_commit(repository_wrapper& repo, const commit_wrapper& commit, std::s
247247 print_time (author.when (), " Date:\t " );
248248 }
249249 }
250- std::cout << " \n " << commit.message ();
250+
251+ std::string message = commit.message ();
252+ while (!message.empty () && message.back () == ' \n ' )
253+ {
254+ message.pop_back ();
255+ }
256+ std::istringstream message_stream (message);
257+ std::string line;
258+ while (std::getline (message_stream, line))
259+ {
260+ std::cout << " \n " << line;
261+ }
262+ std::cout << std::endl;
251263}
252264
253265void log_subcommand::run ()
0 commit comments