-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse-pkt-line.c
57 lines (49 loc) · 1.19 KB
/
parse-pkt-line.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
#include <git2.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
int parse_pkt_line(git_repository *repo, int argc, char **argv)
{
char *line = argv[1];
char oid[GIT_OID_HEXSZ+1] = {0};
const char *after = line;
int error;
unsigned int len;
git_pkt *pkt;
/*
* Assume that the user has piped a file in
*/
fseek(stdin, 0, SEEK_END);
len = ftell(stdin);
fseek(stdin, 0, SEEK_SET);
line = malloc(len+1);
if(line == NULL)
return GIT_ENOMEM;
memset(line, 0, len+1);
fread(line, len, sizeof(char), stdin);
after = line;
while(*after != '\0'){
error = git_pkt_parse_line(&pkt, line, &after, len);
if (error < GIT_SUCCESS)
return error;
line = (char *) after;
switch(pkt->type){
case GIT_PKT_REF:
{
git_remote_head *h = &(((git_pkt_ref *)pkt)->head);
const char *caps = ((git_pkt_ref *)pkt)->capabilities;
//puts("Found a ref pkt");
git_oid_fmt(oid, &h->oid);
printf("%s\t%s\n", oid, h->name);
if(caps != NULL)
printf(" Capabilities: %s\n", caps);
break;
}
case GIT_PKT_FLUSH:
puts("flush! do something!");
default:
printf("default: %d\n", *after);
}
}
return error;
}