git-receive-pack: start parsing ref update commands
We don't act on them yet, but we parse them.
This commit is contained in:
@ -86,12 +86,14 @@ static void write_head_info(const char *base, int nr, char **match)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct line {
|
struct command {
|
||||||
struct line *next;
|
struct command *next;
|
||||||
char data[0];
|
unsigned char old_sha1[20];
|
||||||
|
unsigned char new_sha1[20];
|
||||||
|
char ref_name[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line *commands = NULL;
|
struct command *commands = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This gets called after(if) we've successfully
|
* This gets called after(if) we've successfully
|
||||||
@ -99,28 +101,44 @@ struct line *commands = NULL;
|
|||||||
*/
|
*/
|
||||||
static void execute_commands(void)
|
static void execute_commands(void)
|
||||||
{
|
{
|
||||||
struct line *line = commands;
|
struct command *cmd = commands;
|
||||||
|
|
||||||
while (line) {
|
while (cmd) {
|
||||||
fprintf(stderr, "%s", line->data);
|
char old_hex[60], *new_hex;
|
||||||
line = line->next;
|
strcpy(old_hex, sha1_to_hex(cmd->old_sha1));
|
||||||
|
new_hex = sha1_to_hex(cmd->new_sha1);
|
||||||
|
fprintf(stderr, "%s: %s -> %s\n", cmd->ref_name, old_hex, new_hex);
|
||||||
|
cmd = cmd->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_head_info(void)
|
static void read_head_info(void)
|
||||||
{
|
{
|
||||||
struct line **p = &commands;
|
struct command **p = &commands;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
static char line[1000];
|
static char line[1000];
|
||||||
int len = packet_read_line(0, line, sizeof(line));
|
unsigned char old_sha1[20], new_sha1[20];
|
||||||
struct line *n;
|
struct command *cmd;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = packet_read_line(0, line, sizeof(line));
|
||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
n = xmalloc(sizeof(struct line) + len);
|
if (line[len-1] == '\n')
|
||||||
n->next = NULL;
|
line[--len] = 0;
|
||||||
memcpy(n->data, line + 4, len - 3);
|
if (len < 83 ||
|
||||||
*p = n;
|
line[40] != ' ' ||
|
||||||
p = &n->next;
|
line[81] != ' ' ||
|
||||||
|
get_sha1_hex(line, old_sha1) ||
|
||||||
|
get_sha1_hex(line + 41, new_sha1))
|
||||||
|
die("protocol error: expected old/new/ref, got '%s'", line);
|
||||||
|
cmd = xmalloc(sizeof(struct command) + len - 80);
|
||||||
|
memcpy(cmd->old_sha1, old_sha1, 20);
|
||||||
|
memcpy(cmd->new_sha1, new_sha1, 20);
|
||||||
|
memcpy(cmd->ref_name, line + 82, len - 81);
|
||||||
|
cmd->next = NULL;
|
||||||
|
*p = cmd;
|
||||||
|
p = &cmd->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user