mirror of
https://github.com/git/git.git
synced 2026-08-08 17:11:48 +00:00
fetch-object-info: parse type from server response
The server can handle type requests but does not advertise the capability yet. Prepare the client to know how to parse the server response once the server advertises the capability. Mentored-by: Karthik Nayak <karthik.188@gmail.com> Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
1de7fe1111
commit
0f61542dbc
@@ -854,6 +854,8 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
string_list_append(&data->remote_allowed_atoms, "objectname");
|
||||
if (results.sizes)
|
||||
string_list_append(&data->remote_allowed_atoms, "objectsize");
|
||||
if (results.types)
|
||||
string_list_append(&data->remote_allowed_atoms, "objecttype");
|
||||
|
||||
data->skip_object_info = 1;
|
||||
for (size_t i = 0; i < results.nr; i++) {
|
||||
@@ -872,6 +874,9 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
if (results.sizes)
|
||||
data->size = results.sizes[i];
|
||||
|
||||
if (results.types)
|
||||
data->type = results.types[i];
|
||||
|
||||
opt->batch_mode = BATCH_MODE_INFO;
|
||||
data->is_remote = 1;
|
||||
batch_object_write(argv[i + 1], output, opt, data, NULL, 0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "git-compat-util.h"
|
||||
#include "gettext.h"
|
||||
#include "hex.h"
|
||||
#include "object.h"
|
||||
#include "pkt-line.h"
|
||||
#include "connect.h"
|
||||
#include "oid-array.h"
|
||||
@@ -62,6 +63,7 @@ int fetch_object_info(const enum protocol_version version,
|
||||
unsigned ask_size = 0;
|
||||
unsigned ask_type = 0;
|
||||
int size_index = -1;
|
||||
int type_index = -1;
|
||||
size_t wanted;
|
||||
size_t i;
|
||||
|
||||
@@ -110,8 +112,15 @@ int fetch_object_info(const enum protocol_version version,
|
||||
die(_("object-info: duplicate 'size' attribute"));
|
||||
size_index = (int)i;
|
||||
CALLOC_ARRAY(results->sizes, results->nr);
|
||||
} else if (!strcmp(reader->line, "type")) {
|
||||
if (!ask_type)
|
||||
die(_("object-info: unrequested 'type' attribute"));
|
||||
if (results->types)
|
||||
die(_("object-info: duplicate 'type' attribute"));
|
||||
type_index = (int)i;
|
||||
CALLOC_ARRAY(results->types, results->nr);
|
||||
} else {
|
||||
BUG("only size is supported");
|
||||
BUG("unexpected object-info option: %s", reader->line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +166,18 @@ int fetch_object_info(const enum protocol_version version,
|
||||
object_info_values.items[0].string,
|
||||
object_info_values.items[size_index + 1].string);
|
||||
|
||||
if (results->types) {
|
||||
const char *type_str =
|
||||
object_info_values.items[type_index + 1].string;
|
||||
int type = type_from_string_gently(type_str, -1, 1);
|
||||
|
||||
if (type < 0)
|
||||
die(_("object-info: object %s has invalid type '%s'"),
|
||||
object_info_values.items[0].string, type_str);
|
||||
|
||||
results->types[i] = type;
|
||||
}
|
||||
|
||||
string_list_clear(&object_info_values, 0);
|
||||
}
|
||||
|
||||
@@ -172,6 +193,7 @@ int fetch_object_info(const enum protocol_version version,
|
||||
void free_fetch_object_info_results(struct fetch_object_info_results *results)
|
||||
{
|
||||
free(results->sizes);
|
||||
free(results->types);
|
||||
free(results->unrecognized);
|
||||
memset(results, 0, sizeof(*results));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#ifndef FETCH_OBJECT_INFO_H
|
||||
#define FETCH_OBJECT_INFO_H
|
||||
|
||||
#include "object.h"
|
||||
#include "pkt-line.h"
|
||||
#include "protocol.h"
|
||||
|
||||
struct fetch_object_info_results {
|
||||
size_t *sizes;
|
||||
enum object_type *types;
|
||||
uint8_t *unrecognized;
|
||||
size_t nr;
|
||||
unsigned wants_size:1;
|
||||
|
||||
Reference in New Issue
Block a user