1 #include "git-compat-util.h"
2 #include "protocol-caps.h"
9 #include "object-store-ll.h"
10 #include "string-list.h"
13 struct requested_info
{
18 * Parses oids from the given line and collects them in the given
19 * oid_str_list. Returns 1 if parsing was successful and 0 otherwise.
21 static int parse_oid(const char *line
, struct string_list
*oid_str_list
)
25 if (!skip_prefix(line
, "oid ", &arg
))
28 string_list_append(oid_str_list
, arg
);
34 * Validates and send requested info back to the client. Any errors detected
35 * are returned as they are detected.
37 static void send_info(struct repository
*r
, struct packet_writer
*writer
,
38 struct string_list
*oid_str_list
,
39 struct requested_info
*info
)
41 struct string_list_item
*item
;
42 struct strbuf send_buffer
= STRBUF_INIT
;
44 if (!oid_str_list
->nr
)
48 packet_writer_write(writer
, "size");
50 for_each_string_list_item (item
, oid_str_list
) {
51 const char *oid_str
= item
->string
;
53 unsigned long object_size
;
55 if (get_oid_hex(oid_str
, &oid
) < 0) {
58 "object-info: protocol error, expected to get oid, not '%s'",
63 strbuf_addstr(&send_buffer
, oid_str
);
66 if (oid_object_info(r
, &oid
, &object_size
) < 0) {
67 strbuf_addstr(&send_buffer
, " ");
69 strbuf_addf(&send_buffer
, " %lu", object_size
);
73 packet_writer_write(writer
, "%s", send_buffer
.buf
);
74 strbuf_reset(&send_buffer
);
76 strbuf_release(&send_buffer
);
79 int cap_object_info(struct repository
*r
, struct packet_reader
*request
)
81 struct requested_info info
= { 0 };
82 struct packet_writer writer
;
83 struct string_list oid_str_list
= STRING_LIST_INIT_DUP
;
85 packet_writer_init(&writer
, 1);
87 while (packet_reader_read(request
) == PACKET_READ_NORMAL
) {
88 if (!strcmp("size", request
->line
)) {
93 if (parse_oid(request
->line
, &oid_str_list
))
96 packet_writer_error(&writer
,
97 "object-info: unexpected line: '%s'",
101 if (request
->status
!= PACKET_READ_FLUSH
) {
103 &writer
, "object-info: expected flush after arguments");
104 die(_("object-info: expected flush after arguments"));
107 send_info(r
, &writer
, &oid_str_list
, &info
);
109 string_list_clear(&oid_str_list
, 1);