1
- // #include <iostream>
2
- // #include <ostream>
3
- // #include <string>
4
-
1
+ #include < format>
5
2
#include < git2.h>
6
3
#include < git2/revwalk.h>
7
4
#include < git2/types.h>
5
+ #include < string_view>
8
6
9
7
#include " log_subcommand.hpp"
10
8
#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"
17
10
18
11
log_subcommand::log_subcommand (const libgit2_object&, CLI::App& app)
19
12
{
@@ -26,7 +19,7 @@ log_subcommand::log_subcommand(const libgit2_object&, CLI::App& app)
26
19
sub->callback ([this ]() { this ->run (); });
27
20
};
28
21
29
- void print_time (git_time intime, const char * prefix)
22
+ void print_time (git_time intime, std::string prefix)
30
23
{
31
24
char sign, out[32 ];
32
25
struct tm *intm;
@@ -37,7 +30,9 @@ void print_time(git_time intime, const char *prefix)
37
30
if (offset < 0 ) {
38
31
sign = ' -' ;
39
32
offset = -offset;
40
- } else {
33
+ }
34
+ else
35
+ {
41
36
sign = ' +' ;
42
37
}
43
38
@@ -49,38 +44,37 @@ void print_time(git_time intime, const char *prefix)
49
44
intm = gmtime (&t);
50
45
strftime (out, sizeof (out), " %a %b %e %T %Y" , intm);
51
46
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 ;
53
48
}
54
49
55
50
void print_commit (const commit_wrapper& commit, std::string m_format_flag)
56
51
{
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 ();
63
53
64
54
signature_wrapper author = signature_wrapper::get_commit_author (commit);
65
55
signature_wrapper committer = signature_wrapper::get_commit_committer (commit);
66
56
67
57
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" )
74
59
{
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: " );
78
64
}
79
65
else
80
66
{
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
+ }
82
76
}
83
- std::cout << git_commit_message (commit) << " \n " << std::endl;
77
+ std::cout << " \n " << git_commit_message (commit) << " \n " << std::endl;
84
78
}
85
79
86
80
void log_subcommand::run ()
0 commit comments