- n = xmalloc(sizeof(struct line) + len);
- n->next = NULL;
- memcpy(n->data, line + 4, len - 3);
- *p = n;
- p = &n->next;
+ if (line[len-1] == '\n')
+ line[--len] = 0;
+ if (len < 83 ||
+ line[40] != ' ' ||
+ 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;