1- // #include <iostream>
2- // #include <ostream>
3- // #include <string>
4-
1+ #include < format>
52#include < git2.h>
63#include < git2/revwalk.h>
74#include < git2/types.h>
5+ #include < string_view>
86
97#include " log_subcommand.hpp"
108#include " ../wrapper/repository_wrapper.hpp"
11-
12- // TODO: put in another file
13- /* * Size (in bytes) of a raw/binary sha1 oid */
14- #define GIT_OID_SHA1_SIZE 20
15- /* * Size (in bytes) of a hex formatted sha1 oid */
16- #define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2 )
9+ #include " ../wrapper/commit_wrapper.hpp"
1710
1811log_subcommand::log_subcommand (const libgit2_object&, CLI::App& app)
1912{
@@ -26,7 +19,7 @@ log_subcommand::log_subcommand(const libgit2_object&, CLI::App& app)
2619 sub->callback ([this ]() { this ->run (); });
2720};
2821
29- void print_time (git_time intime, const char * prefix)
22+ void print_time (git_time intime, std::string prefix)
3023{
3124 char sign, out[32 ];
3225 struct tm *intm;
@@ -37,7 +30,9 @@ void print_time(git_time intime, const char *prefix)
3730 if (offset < 0 ) {
3831 sign = ' -' ;
3932 offset = -offset;
40- } else {
33+ }
34+ else
35+ {
4136 sign = ' +' ;
4237 }
4338
@@ -49,38 +44,37 @@ void print_time(git_time intime, const char *prefix)
4944 intm = gmtime (&t);
5045 strftime (out, sizeof (out), " %a %b %e %T %Y" , intm);
5146
52- printf ( " %s%s %c%02d%02d \n " , prefix, out, sign, hours, minutes);
47+ std::cout << prefix << out << " " << sign << std::format ( " {:02d} " , hours) << std::format ( " {:02d} " , minutes) <<std::endl ;
5348}
5449
5550void print_commit (const commit_wrapper& commit, std::string m_format_flag)
5651{
57- // TODO: put in commit_wrapper ?
58- char buf[GIT_OID_SHA1_HEXSIZE + 1 ];
59- int i, count;
60-
61- git_oid_tostr (buf, sizeof (buf), &commit.oid ());
62- // TODO end
52+ std::string buf = commit.commit_oid_tostr ();
6353
6454 signature_wrapper author = signature_wrapper::get_commit_author (commit);
6555 signature_wrapper committer = signature_wrapper::get_commit_committer (commit);
6656
6757 std::cout << " \033 [0;33m" << " commit " << buf << " \033 [0m" << std::endl;
68- std::cout << " Author:\t " << author.name () << " " << author.email () << std::endl;
69- if (m_format_flag==" full" )
70- {
71- std::cout << " Commit:\t " << committer.name () << " " << committer.email () << std::endl;
72- }
73- else if (m_format_flag==" fuller" )
58+ if (m_format_flag==" fuller" )
7459 {
75- print_time (author.when (), " AuthorDate:\t " );
76- std::cout << " Commit:\t " << committer.name () << " " << committer.email () << std::endl;
77- print_time (committer.when (), " CommitDate:\t " );
60+ std::cout << " Author:\t " << author.name () << " " << author.email () << std::endl;
61+ print_time (author.when (), " AuthorDate: " );
62+ std::cout << " Commit:\t " << committer.name () << " " << committer.email () << std::endl;
63+ print_time (committer.when (), " CommitDate: " );
7864 }
7965 else
8066 {
81- print_time (author.when (), " Date:\t " );
67+ std::cout << " Author:\t " << author.name () << " " << author.email () << std::endl;
68+ if (m_format_flag==" full" )
69+ {
70+ std::cout << " Commit:\t " << committer.name () << " " << committer.email () << std::endl;
71+ }
72+ else
73+ {
74+ print_time (author.when (), " Date:\t " );
75+ }
8276 }
83- std::cout << git_commit_message (commit) << " \n " << std::endl;
77+ std::cout << " \n " << git_commit_message (commit) << " \n " << std::endl;
8478}
8579
8680void log_subcommand::run ()
0 commit comments