forked from libgit2/libgit2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grabtag.c
77 lines (65 loc) · 1.79 KB
/
grabtag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <git2.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"
static void print_signature(const char *header, const git_signature *sig)
{
char sign;
int offset, hours, minutes;
if (!sig)
return;
offset = sig->when.offset;
if (offset < 0) {
sign = '-';
offset = -offset;
} else {
sign = '+';
}
hours = offset / 60;
minutes = offset % 60;
printf("%s %s <%s> %ld %c%02d%02d\n",
header, sig->name, sig->email, (long)sig->when.time,
sign, hours, minutes);
}
void show_tag (char * rname, char *oidstr, git_tag *tag)
{
char tidstr [GIT_OID_HEXSZ + 1];
git_oid_tostr (tidstr, sizeof(tidstr), git_tag_target_id(tag));
printf ("repo;%s;%s;%s\n", rname, git_tag_name(tag), oidstr);
printf("object %s\n", tidstr);
printf("type %s\n", git_object_type2string(git_tag_target_type(tag)));
printf("tag %s\n", git_tag_name(tag));
print_signature("tagger", git_tag_tagger(tag));
if (git_tag_message(tag))
printf("\n%s", git_tag_message(tag));
printf ("repo;%s;%s;%s\n", rname, git_tag_name(tag), oidstr);
}
int main(int argc, char *argv[])
{
git_repository *repo;
git_object *obj = NULL;
git_libgit2_init();
if (check_lg2 (git_repository_open_bare(&repo, argv[1]),
"Could not open repository", NULL) != 0)
exit (-1);
size_t size = 0;
char *l0 = NULL;
while (getline(&l0, &size, stdin)>=0){
char* l1 = strdup (l0);
l1 [strlen(l1)-1] = 0;
if (obj != NULL) git_object_free(obj);
if (check_lg2(git_revparse_single(&obj, repo, l1),
"Could not resolve", l1) != 0){
}else{
if (git_object_type (obj) == GIT_OBJ_TAG){
git_tag *tag = (git_tag*)obj;
show_tag (argv[1], l1, tag);
}
}
free (l1);
}
git_repository_free (repo);
git_libgit2_shutdown ();
return 0;
}