mirror of
https://github.com/git/git.git
synced 2026-08-08 00:52:31 +00:00
Merge branch 'ps/cat-file-remote-object-info-type' into seen
The 'remote-object-info' command for 'git cat-file --batch-command' has been extended to support the '%(objecttype)' placeholder. * ps/cat-file-remote-object-info-type: cat-file: unify default format serve: advertise type capability fetch-object-info: parse type from server response protocol-caps: add type support to object-info fetch-object-info: use dedicated struct for the results fetch-object-info: pass arguments directly instead of a struct fetch-object-info: detect truncated server responses t5701: use test_file_size() to get the size of a file
This commit is contained in:
@@ -348,15 +348,12 @@ newline. The available atoms are:
|
||||
after that first run of whitespace (i.e., the "rest" of the
|
||||
line) are output in place of the `%(rest)` atom.
|
||||
|
||||
The command `remote-object-info` only supports the `%(objectname)` and
|
||||
`%(objectsize)` placeholders. See `CAVEATS` below for more information.
|
||||
The command `remote-object-info` only supports the `%(objectname)`,
|
||||
`%(objectsize)` and `%(objecttype)` placeholders. See `CAVEATS` below for more
|
||||
information.
|
||||
|
||||
If no format is specified, the default format is `%(objectname)
|
||||
%(objecttype) %(objectsize)`, except for `remote-object-info` commands which
|
||||
use `%(objectname) %(objectsize)` because `%(objecttype)` is not supported yet.
|
||||
|
||||
WARNING: When "%(objecttype)" is supported, the default format WILL be unified,
|
||||
so DO NOT RELY on the current default format to stay the same!!!
|
||||
%(objecttype) %(objectsize)`.
|
||||
|
||||
If `--batch` is specified, or if `--batch-command` is used with the `contents`
|
||||
command, the object information is followed by the object contents (consisting
|
||||
@@ -453,9 +450,9 @@ scripting purposes.
|
||||
CAVEATS
|
||||
-------
|
||||
|
||||
Note that only `%(objectname)` and `%(objectsize)` are currently
|
||||
supported by the `remote-object-info` command. Using any other placeholder in
|
||||
the format string will return an empty string in its position.
|
||||
Note that only `%(objectname)`, `%(objectsize)` and `%(objecttype)` are
|
||||
currently supported by the `remote-object-info` command. Using any other
|
||||
placeholder in the format string will return an empty string in its position.
|
||||
|
||||
Note that the sizes of objects on disk are reported accurately, but care
|
||||
should be taken in drawing conclusions about which refs or objects are
|
||||
|
||||
@@ -558,14 +558,17 @@ object-info
|
||||
|
||||
`object-info` is the command to retrieve information about one or more objects.
|
||||
Its main purpose is to allow a client to make decisions based on this
|
||||
information without having to fully fetch objects. Object size is the only
|
||||
information that is currently supported.
|
||||
information without having to fully fetch objects. Currently only object size
|
||||
and type are supported.
|
||||
|
||||
An `object-info` request takes the following arguments:
|
||||
|
||||
size
|
||||
Requests size information to be returned for each listed object id.
|
||||
|
||||
type
|
||||
Requests type information to be returned for each listed object id.
|
||||
|
||||
oid <oid>
|
||||
Indicates to the server an object which the client wants to obtain
|
||||
information for. They must be full OIDs.
|
||||
@@ -580,11 +583,18 @@ space.
|
||||
info = *PKT-LINE(attr LF)
|
||||
*PKT-LINE(obj-info LF)
|
||||
|
||||
attr = "size"
|
||||
attr = "size" | "type"
|
||||
|
||||
obj-size = 1*DIGIT
|
||||
|
||||
obj-info = obj-id [SP [obj-size]]
|
||||
obj-type = "blob" | "tree" | "commit" | "tag"
|
||||
|
||||
obj-val = obj-size | obj-type
|
||||
|
||||
obj-info = obj-id [SP [obj-val *(SP obj-val)]]
|
||||
|
||||
The values in `obj-info` appear in the same order as the corresponding `attr`
|
||||
lines, with exactly one value per requested attribute.
|
||||
|
||||
If the server does not recognize the OID, the response will be `<oid> SP`
|
||||
regardless of the number of attributes requested.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "alias.h"
|
||||
#include "remote.h"
|
||||
#include "transport.h"
|
||||
#include "fetch-object-info.h"
|
||||
|
||||
/*
|
||||
* Maximum length for a remote URL. While no universal standard exists,
|
||||
@@ -681,9 +682,8 @@ out:
|
||||
|
||||
static int get_remote_info(int argc,
|
||||
const char **argv,
|
||||
struct object_info **remote_object_info,
|
||||
struct oid_array *object_info_oids,
|
||||
struct string_list *object_info_options)
|
||||
struct fetch_object_info_results *results,
|
||||
struct oid_array *object_info_oids)
|
||||
{
|
||||
int retval = 0;
|
||||
struct remote *remote = NULL;
|
||||
@@ -724,11 +724,9 @@ static int get_remote_info(int argc,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
CALLOC_ARRAY(*remote_object_info, object_info_oids->nr);
|
||||
gtransport->smart_options->object_info_oids = object_info_oids;
|
||||
|
||||
gtransport->smart_options->object_info_options = object_info_options;
|
||||
gtransport->smart_options->object_info_data = *remote_object_info;
|
||||
gtransport->smart_options->object_info_results = results;
|
||||
retval = transport_fetch_object_info(gtransport);
|
||||
cleanup:
|
||||
transport_disconnect(gtransport);
|
||||
@@ -819,21 +817,6 @@ static void parse_cmd_mailmap(struct batch_options *opt UNUSED,
|
||||
load_mailmap();
|
||||
}
|
||||
|
||||
struct protocol_placeholder_entry {
|
||||
const char *option;
|
||||
const char *atom;
|
||||
};
|
||||
|
||||
static const struct protocol_placeholder_entry remote_atom_map[] = {
|
||||
{"size", "objectsize"},
|
||||
{"type", "objecttype"},
|
||||
/*
|
||||
* Add new protocol options here. Even if the server doesn't support
|
||||
* them the allow_list will drop them if the server doesn't advertise
|
||||
* them.
|
||||
*/
|
||||
};
|
||||
|
||||
static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
const char *line, struct strbuf *output,
|
||||
struct expand_data *data)
|
||||
@@ -841,18 +824,11 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
int count;
|
||||
const char **argv;
|
||||
char *line_to_split;
|
||||
struct object_info *remote_object_info = NULL;
|
||||
struct fetch_object_info_results results = FETCH_OBJECT_INFO_RESULTS_INIT;
|
||||
struct oid_array object_info_oids = OID_ARRAY_INIT;
|
||||
struct string_list object_info_options = STRING_LIST_INIT_NODUP;
|
||||
const char *saved_format = opt->format;
|
||||
|
||||
if (strlen(line) >= MAX_REMOTE_OBJ_INFO_LINE)
|
||||
die(_("remote-object-info command too long"));
|
||||
/*
|
||||
* TODO: Use the default format once %(objecttype) is supported.
|
||||
*/
|
||||
if (!opt->format)
|
||||
opt->format = "%(objectname) %(objectsize)";
|
||||
|
||||
line_to_split = xstrdup(line);
|
||||
count = split_cmdline(line_to_split, &argv);
|
||||
@@ -864,26 +840,25 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
MAX_ALLOWED_OBJ_LIMIT);
|
||||
|
||||
if (data->info.sizep)
|
||||
string_list_append(&object_info_options, "size");
|
||||
results.wants_size = 1;
|
||||
if (data->info.typep)
|
||||
string_list_append(&object_info_options, "type");
|
||||
results.wants_type = 1;
|
||||
|
||||
if (get_remote_info(count, argv, &remote_object_info,
|
||||
&object_info_oids, &object_info_options))
|
||||
if (get_remote_info(count, argv, &results, &object_info_oids))
|
||||
die(_("failed to get object info from the remote: %s"), argv[0]);
|
||||
|
||||
string_list_clear(&data->remote_allowed_atoms, 0);
|
||||
string_list_append(&data->remote_allowed_atoms, "objectname");
|
||||
for (size_t i = 0; i < ARRAY_SIZE(remote_atom_map); i++)
|
||||
if (unsorted_string_list_has_string(&object_info_options, remote_atom_map[i].option))
|
||||
string_list_append(&data->remote_allowed_atoms,
|
||||
remote_atom_map[i].atom);
|
||||
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 < object_info_oids.nr; i++) {
|
||||
for (size_t i = 0; i < results.nr; i++) {
|
||||
data->oid = object_info_oids.oid[i];
|
||||
|
||||
if (remote_object_info[i].unrecognized) {
|
||||
if (results.unrecognized[i]) {
|
||||
report_object_status(opt, oid_to_hex(&data->oid),
|
||||
&data->oid, "missing");
|
||||
continue;
|
||||
@@ -893,13 +868,11 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
* When reaching here, it means remote-object-info can retrieve
|
||||
* information from server without downloading them.
|
||||
*/
|
||||
if (remote_object_info[i].sizep) {
|
||||
data->size = *remote_object_info[i].sizep;
|
||||
}
|
||||
if (results.sizes)
|
||||
data->size = results.sizes[i];
|
||||
|
||||
if (remote_object_info[i].typep) {
|
||||
data->type = *remote_object_info[i].typep;
|
||||
}
|
||||
if (results.types)
|
||||
data->type = results.types[i];
|
||||
|
||||
opt->batch_mode = BATCH_MODE_INFO;
|
||||
data->is_remote = 1;
|
||||
@@ -907,14 +880,10 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
|
||||
data->is_remote = 0;
|
||||
}
|
||||
data->skip_object_info = 0;
|
||||
opt->format = saved_format;
|
||||
|
||||
for (size_t i = 0; i < object_info_oids.nr; i++)
|
||||
free_object_info_contents(&remote_object_info[i]);
|
||||
string_list_clear(&object_info_options, 0);
|
||||
free_fetch_object_info_results(&results);
|
||||
free(line_to_split);
|
||||
free(argv);
|
||||
free(remote_object_info);
|
||||
oid_array_clear(&object_info_oids);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -9,20 +10,26 @@
|
||||
#include "string-list.h"
|
||||
|
||||
/* Sends object-info command and its arguments into the request buffer. */
|
||||
static void send_object_info_request(const int fd_out, struct object_info_args *args)
|
||||
static void send_object_info_request(const int fd_out,
|
||||
const struct string_list *server_options,
|
||||
struct oid_array *oids,
|
||||
unsigned ask_size,
|
||||
unsigned ask_type)
|
||||
{
|
||||
struct strbuf req_buf = STRBUF_INIT;
|
||||
|
||||
write_command_and_capabilities(&req_buf, "object-info", args->server_options);
|
||||
write_command_and_capabilities(&req_buf, "object-info", server_options);
|
||||
|
||||
if (unsorted_string_list_has_string(args->object_info_options, "size"))
|
||||
if (ask_size)
|
||||
packet_buf_write(&req_buf, "size");
|
||||
else if (args->object_info_options->nr)
|
||||
BUG("only size should be in object_info_options");
|
||||
|
||||
if (args->oids)
|
||||
for (size_t i = 0; i < args->oids->nr; i++)
|
||||
packet_buf_write(&req_buf, "oid %s", oid_to_hex(&args->oids->oid[i]));
|
||||
if (ask_type)
|
||||
packet_buf_write(&req_buf, "type");
|
||||
|
||||
if (oids)
|
||||
for (size_t i = 0; i < oids->nr; i++)
|
||||
packet_buf_write(&req_buf, "oid %s",
|
||||
oid_to_hex(&oids->oid[i]));
|
||||
|
||||
packet_buf_flush(&req_buf);
|
||||
if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
|
||||
@@ -45,35 +52,43 @@ static int parse_object_size(const char *s, size_t *res)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fetch_object_info(const enum protocol_version version, struct object_info_args *args,
|
||||
struct packet_reader *reader, struct object_info *object_info_data,
|
||||
const int stateless_rpc, const int fd_out)
|
||||
int fetch_object_info(const enum protocol_version version,
|
||||
const struct string_list *server_options,
|
||||
struct oid_array *oids,
|
||||
struct packet_reader *reader,
|
||||
struct fetch_object_info_results *results,
|
||||
const int stateless_rpc,
|
||||
const int fd_out)
|
||||
{
|
||||
unsigned ask_size = 0;
|
||||
unsigned ask_type = 0;
|
||||
int size_index = -1;
|
||||
int type_index = -1;
|
||||
size_t wanted;
|
||||
size_t i;
|
||||
|
||||
results->nr = oids->nr;
|
||||
CALLOC_ARRAY(results->unrecognized, results->nr);
|
||||
|
||||
switch (version) {
|
||||
case protocol_v2:
|
||||
if (!server_supports_v2("object-info"))
|
||||
die(_("object-info capability is not enabled on the server"));
|
||||
/*
|
||||
* When removing an element from the list it gets swapped by the
|
||||
* last element, iterate backwards to prevent elements skipping
|
||||
* evaluation.
|
||||
*
|
||||
* object_info_options->nr can be safely casted without overflow
|
||||
* because the number of options is a small known number (the
|
||||
* supported placeholders which currently are size and type).
|
||||
*/
|
||||
for (int i = (int)args->object_info_options->nr - 1; i >= 0; i--)
|
||||
if (!server_supports_feature("object-info",
|
||||
args->object_info_options->items[i].string, 0))
|
||||
unsorted_string_list_delete_item(args->object_info_options, i, 0);
|
||||
|
||||
if (results->wants_size &&
|
||||
server_supports_feature("object-info", "size", 0))
|
||||
ask_size = 1;
|
||||
|
||||
if (results->wants_type &&
|
||||
server_supports_feature("object-info", "type", 0))
|
||||
ask_type = 1;
|
||||
|
||||
/*
|
||||
* Even if no options are left, we still send the oid so we get
|
||||
* at least an existence check.
|
||||
*/
|
||||
send_object_info_request(fd_out, args);
|
||||
send_object_info_request(fd_out, server_options, oids, ask_size,
|
||||
ask_type);
|
||||
break;
|
||||
case protocol_v1:
|
||||
case protocol_v0:
|
||||
@@ -81,43 +96,46 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
|
||||
case protocol_unknown_version:
|
||||
BUG("unknown protocol version");
|
||||
}
|
||||
wanted = ask_size + ask_type;
|
||||
|
||||
for (size_t i = 0; i < args->object_info_options->nr; i++) {
|
||||
for (i = 0; i < wanted; i++) {
|
||||
if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
|
||||
check_stateless_delimiter(stateless_rpc, reader,
|
||||
"stateless delimiter expected");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!unsorted_string_list_has_string(args->object_info_options, reader->line))
|
||||
return -1;
|
||||
|
||||
if (!strcmp(reader->line, "size")) {
|
||||
/*
|
||||
* i is the number of supported options which currently
|
||||
* is only size. No risk of overflow.
|
||||
*/
|
||||
if (!ask_size)
|
||||
die(_("object-info: unrequested 'size' attribute"));
|
||||
if (results->sizes)
|
||||
die(_("object-info: duplicate 'size' attribute"));
|
||||
size_index = (int)i;
|
||||
for (size_t j = 0; j < args->oids->nr; j++)
|
||||
object_info_data[j].sizep =
|
||||
xcalloc(1, sizeof(*object_info_data[j].sizep));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0;
|
||||
for (i = 0;
|
||||
packet_reader_read(reader) == PACKET_READ_NORMAL &&
|
||||
i < args->oids->nr;
|
||||
i < oids->nr;
|
||||
i++) {
|
||||
struct string_list object_info_values = STRING_LIST_INIT_DUP;
|
||||
|
||||
string_list_split(&object_info_values, reader->line, " ", -1);
|
||||
|
||||
if (strcmp(object_info_values.items[0].string,
|
||||
oid_to_hex(&args->oids->oid[i])))
|
||||
oid_to_hex(&oids->oid[i])))
|
||||
die(_("object-info: expected OID: %s, got %s"),
|
||||
oid_to_hex(&args->oids->oid[i]),
|
||||
oid_to_hex(&oids->oid[i]),
|
||||
object_info_values.items[0].string);
|
||||
|
||||
/*
|
||||
@@ -127,30 +145,55 @@ int fetch_object_info(const enum protocol_version version, struct object_info_ar
|
||||
*/
|
||||
if (object_info_values.nr >= 2 &&
|
||||
!strcmp(object_info_values.items[1].string, "")) {
|
||||
object_info_data[i].unrecognized = 1;
|
||||
results->unrecognized[i] = 1;
|
||||
string_list_clear(&object_info_values, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Because we filter the options to be only the supported by
|
||||
* the server we expect the server to answer with the same
|
||||
* number of attributes requested.
|
||||
* Because we only ask for attributes the server said it
|
||||
* supports, we expect the answer to have one value per
|
||||
* requested attribute, plus the OID.
|
||||
*/
|
||||
if (args->object_info_options->nr + 1 != object_info_values.nr)
|
||||
if (wanted + 1 != object_info_values.nr)
|
||||
die("object-info: unexpected number of attributes: %s",
|
||||
reader->line);
|
||||
|
||||
if (size_index >= 0 &&
|
||||
if (results->sizes &&
|
||||
parse_object_size(object_info_values.items[size_index + 1].string,
|
||||
object_info_data[i].sizep))
|
||||
die("object-info: ref %s has invalid size %s",
|
||||
&results->sizes[i]))
|
||||
die("object-info: object %s has invalid size %s",
|
||||
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);
|
||||
}
|
||||
|
||||
if (i != oids->nr)
|
||||
die(_("object-info: expected %" PRIuMAX " objects, got %" PRIuMAX),
|
||||
(uintmax_t)oids->nr, (uintmax_t)i);
|
||||
|
||||
check_stateless_delimiter(stateless_rpc, reader, "stateless delimiter expected");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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,25 +1,40 @@
|
||||
#ifndef FETCH_OBJECT_INFO_H
|
||||
#define FETCH_OBJECT_INFO_H
|
||||
|
||||
#include "object.h"
|
||||
#include "pkt-line.h"
|
||||
#include "protocol.h"
|
||||
|
||||
struct object_info_args {
|
||||
struct string_list *object_info_options;
|
||||
const struct string_list *server_options;
|
||||
struct oid_array *oids;
|
||||
struct fetch_object_info_results {
|
||||
size_t *sizes;
|
||||
enum object_type *types;
|
||||
uint8_t *unrecognized;
|
||||
size_t nr;
|
||||
unsigned wants_size:1;
|
||||
unsigned wants_type:1;
|
||||
};
|
||||
|
||||
struct object_info;
|
||||
#define FETCH_OBJECT_INFO_RESULTS_INIT { 0 }
|
||||
|
||||
struct oid_array;
|
||||
/*
|
||||
* Sends git-cat-file object-info command into the request buf and read the
|
||||
* Sends git-cat-file object-info command into the request buf and reads the
|
||||
* results from packets.
|
||||
*
|
||||
* Modifies args->object_info_options, on return it contains only the supported
|
||||
* options by the server.
|
||||
* The caller sets the wants_* flags in "results" to indicate which attributes
|
||||
* it is interested in. On return, "results" holds one array per attribute that
|
||||
* the server both advertised and answered with. An array left NULL means the
|
||||
* attribute is not available.
|
||||
* Release them with free_fetch_object_info_results().
|
||||
*/
|
||||
int fetch_object_info(enum protocol_version version, struct object_info_args *args,
|
||||
struct packet_reader *reader, struct object_info *object_info_data,
|
||||
int stateless_rpc, int fd_out);
|
||||
int fetch_object_info(enum protocol_version version,
|
||||
const struct string_list *server_options,
|
||||
struct oid_array *oids,
|
||||
struct packet_reader *reader,
|
||||
struct fetch_object_info_results *results,
|
||||
int stateless_rpc,
|
||||
int fd_out);
|
||||
|
||||
void free_fetch_object_info_results(struct fetch_object_info_results *results);
|
||||
|
||||
#endif /* FETCH_OBJECT_INFO_H */
|
||||
|
||||
@@ -1340,13 +1340,3 @@ int odb_transaction_files_begin(struct odb_source *source,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_object_info_contents(struct object_info *object_info)
|
||||
{
|
||||
if (!object_info)
|
||||
return;
|
||||
free(object_info->typep);
|
||||
free(object_info->sizep);
|
||||
free(object_info->disk_sizep);
|
||||
free(object_info->delta_base_oid);
|
||||
}
|
||||
|
||||
3
odb.h
3
odb.h
@@ -682,7 +682,4 @@ void parse_alternates(const char *string,
|
||||
const char *relative_base,
|
||||
struct strvec *out);
|
||||
|
||||
/* Free pointers inside of object_info, but not object_info itself */
|
||||
void free_object_info_contents(struct object_info *object_info);
|
||||
|
||||
#endif /* ODB_H */
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include "strbuf.h"
|
||||
|
||||
struct requested_info {
|
||||
unsigned size : 1;
|
||||
unsigned size:1;
|
||||
unsigned type:1;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -73,15 +74,20 @@ static void send_info(struct repository *r, struct packet_writer *writer,
|
||||
if (info->size)
|
||||
packet_writer_write(writer, "size");
|
||||
|
||||
if (info->type)
|
||||
packet_writer_write(writer, "type");
|
||||
|
||||
for_each_string_list_item (item, oid_str_list) {
|
||||
const char *oid_str = item->string;
|
||||
enum object_type object_type;
|
||||
struct object_id oid;
|
||||
size_t object_size;
|
||||
|
||||
if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
|
||||
packet_writer_error(
|
||||
writer,
|
||||
"object-info: protocol error, expected to get oid, not '%s'",
|
||||
"object-info: protocol error, expected to get "
|
||||
"oid, not '%s'",
|
||||
oid_str);
|
||||
continue;
|
||||
}
|
||||
@@ -93,7 +99,8 @@ static void send_info(struct repository *r, struct packet_writer *writer,
|
||||
* If an object is not recognized by the server append SP to
|
||||
* the response.
|
||||
*/
|
||||
if (get_object_info(r->objects, &oid, &object_size) <= OBJ_NONE) {
|
||||
object_type = get_object_info(r->objects, &oid, &object_size);
|
||||
if (object_type <= OBJ_NONE) {
|
||||
strbuf_addstr(&send_buffer, " ");
|
||||
goto write;
|
||||
}
|
||||
@@ -103,6 +110,9 @@ static void send_info(struct repository *r, struct packet_writer *writer,
|
||||
(uintmax_t)object_size);
|
||||
}
|
||||
|
||||
if (info->type)
|
||||
strbuf_addf(&send_buffer, " %s", type_name(object_type));
|
||||
|
||||
write:
|
||||
packet_writer_write(writer, "%s", send_buffer.buf);
|
||||
strbuf_reset(&send_buffer);
|
||||
@@ -124,6 +134,11 @@ int cap_object_info(struct repository *r, struct packet_reader *request)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp("type", request->line)) {
|
||||
info.type = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parse_oid(request->line, &oid_str_list))
|
||||
continue;
|
||||
|
||||
|
||||
4
serve.c
4
serve.c
@@ -97,9 +97,9 @@ static int object_info_advertise(struct repository *r, struct strbuf *value)
|
||||
/* disabled by default */
|
||||
advertise_object_info = 0;
|
||||
}
|
||||
/* Currently only size is supported */
|
||||
/* Currently only size and type are supported */
|
||||
if (value && advertise_object_info)
|
||||
strbuf_addstr(value, "size");
|
||||
strbuf_addstr(value, "size type");
|
||||
return advertise_object_info;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ test_description='git cat-file --batch-command with remote-object-info command'
|
||||
|
||||
hello_content="Hello World"
|
||||
hello_size=$(strlen "$hello_content")
|
||||
hello_type="blob"
|
||||
hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
|
||||
hello_short_oid=$(git rev-parse --short "$hello_oid")
|
||||
|
||||
@@ -19,6 +20,7 @@ unstored_oid=$(echo_without_newline "$unstored_content" | git hash-object --stdi
|
||||
# file name is hello, which is 5 characters
|
||||
# a space is 1 character and a null is 1 character
|
||||
tree_size=$(($(test_oid rawsz) + 13))
|
||||
tree_type="tree"
|
||||
|
||||
commit_message="Initial commit"
|
||||
|
||||
@@ -31,6 +33,7 @@ commit_message="Initial commit"
|
||||
# An easier way to calculate is: 1. use `git cat-file commit <commit hash> | wc -c`,
|
||||
# to get 177, 2. then deduct 40 hex characters to get 137
|
||||
commit_size=$(($(test_oid hexsz) + 137))
|
||||
commit_type="commit"
|
||||
|
||||
tag_header_without_oid="type blob
|
||||
tag hellotag
|
||||
@@ -44,6 +47,7 @@ $tag_description"
|
||||
|
||||
tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
|
||||
tag_size=$(strlen "$tag_content")
|
||||
tag_type="tag"
|
||||
|
||||
set_transport_variables () {
|
||||
hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
|
||||
@@ -135,10 +139,10 @@ test_expect_success 'batch-command remote-object-info git:// default filter' '
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
cd "$daemon_parent/daemon_client_empty" &&
|
||||
|
||||
echo "$hello_oid $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_size" >>expect &&
|
||||
echo "$hello_oid $hello_type $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
git cat-file --batch-command >actual <<-EOF &&
|
||||
remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
|
||||
@@ -148,7 +152,7 @@ test_expect_success 'batch-command remote-object-info git:// default filter' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'remote-object-info does not change the default format of info' '
|
||||
test_expect_success 'remote-object-info and info can be mixed using the unified default format' '
|
||||
(
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
cd "$daemon_parent/daemon_client_empty" &&
|
||||
@@ -158,7 +162,7 @@ test_expect_success 'remote-object-info does not change the default format of in
|
||||
local_size=$(strlen "$local_content") &&
|
||||
|
||||
echo "$local_oid blob $local_size" >expect &&
|
||||
echo "$hello_oid $hello_size" >>expect &&
|
||||
echo "$hello_oid blob $hello_size" >>expect &&
|
||||
echo "$local_oid blob $local_size" >>expect &&
|
||||
|
||||
git cat-file --batch-command >actual <<-EOF &&
|
||||
@@ -205,10 +209,10 @@ test_expect_success 'batch-command -Z remote-object-info git:// default filter'
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
cd "$daemon_parent/daemon_client_empty" &&
|
||||
|
||||
printf "%s\0" "$hello_oid $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_size" >>expect &&
|
||||
printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
printf "%s\0" "$hello_oid missing" >>expect &&
|
||||
printf "%s\0" "$tree_oid missing" >>expect &&
|
||||
@@ -256,14 +260,12 @@ test_expect_success 'remote-object-info does not die on missing oid like info' '
|
||||
)
|
||||
'
|
||||
|
||||
# This tests depends on %(objecttype) not being supported yet, once supported
|
||||
# it needs to be updated.
|
||||
test_expect_success 'unsupported placeholder on remote returns empty string' '
|
||||
test_expect_success 'objecttype is supported by remote-object-info' '
|
||||
(
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
cd "$daemon_parent/daemon_client_empty" &&
|
||||
|
||||
echo "" >expect &&
|
||||
echo "$hello_type" >expect &&
|
||||
git cat-file --batch-command="%(objecttype)" >actual <<-EOF &&
|
||||
remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
|
||||
EOF
|
||||
@@ -271,6 +273,22 @@ test_expect_success 'unsupported placeholder on remote returns empty string' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'unsupported placeholders on remote return empty string' '
|
||||
(
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
cd "$daemon_parent/daemon_client_empty" &&
|
||||
|
||||
fmt="%(objectmode) %(objectsize:disk) %(rest) %(deltabase)" &&
|
||||
|
||||
# The hardcoded SPs between the atoms are respected.
|
||||
echo " " >expect &&
|
||||
git cat-file --batch-command="$fmt" >actual <<-EOF &&
|
||||
remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'requesting only objectname echoes back' '
|
||||
(
|
||||
set_transport_variables "$daemon_parent" &&
|
||||
@@ -430,10 +448,10 @@ test_expect_success 'batch-command remote-object-info file:// default filter' '
|
||||
server_path="$(pwd)/server" &&
|
||||
cd file_client_empty &&
|
||||
|
||||
echo "$hello_oid $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_size" >>expect &&
|
||||
echo "$hello_oid $hello_type $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
git cat-file --batch-command >actual <<-EOF &&
|
||||
remote-object-info "file://${server_path}" $hello_oid $tree_oid
|
||||
@@ -449,10 +467,10 @@ test_expect_success 'batch-command -Z remote-object-info file:// default filter'
|
||||
server_path="$(pwd)/server" &&
|
||||
cd file_client_empty &&
|
||||
|
||||
printf "%s\0" "$hello_oid $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_size" >>expect &&
|
||||
printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
printf "%s\0" "$hello_oid missing" >>expect &&
|
||||
printf "%s\0" "$tree_oid missing" >>expect &&
|
||||
@@ -600,10 +618,10 @@ test_expect_success 'batch-command remote-object-info http:// default filter' '
|
||||
set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
|
||||
cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
|
||||
|
||||
echo "$hello_oid $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_size" >>expect &&
|
||||
echo "$hello_oid $hello_type $hello_size" >expect &&
|
||||
echo "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
echo "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
echo "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
git cat-file --batch-command >actual <<-EOF &&
|
||||
remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
|
||||
@@ -618,10 +636,10 @@ test_expect_success 'batch-command -Z remote-object-info http:// default filter'
|
||||
set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
|
||||
cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
|
||||
|
||||
printf "%s\0" "$hello_oid $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_size" >>expect &&
|
||||
printf "%s\0" "$hello_oid $hello_type $hello_size" >expect &&
|
||||
printf "%s\0" "$tree_oid $tree_type $tree_size" >>expect &&
|
||||
printf "%s\0" "$commit_oid $commit_type $commit_size" >>expect &&
|
||||
printf "%s\0" "$tag_oid $tag_type $tag_size" >>expect &&
|
||||
|
||||
batch_input="remote-object-info $HTTPD_URL/smart/http_parent $hello_oid $tree_oid
|
||||
remote-object-info $HTTPD_URL/smart/http_parent $commit_oid $tag_oid
|
||||
|
||||
@@ -344,20 +344,53 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
|
||||
test_expect_success 'basics of object-info' '
|
||||
test_config transfer.advertiseObjectInfo true &&
|
||||
|
||||
two_oid=$(git rev-parse two:two.t) &&
|
||||
two_size=$(test_file_size two.t) &&
|
||||
|
||||
test-tool pkt-line pack >in <<-EOF &&
|
||||
command=object-info
|
||||
object-format=$(test_oid algo)
|
||||
0001
|
||||
size
|
||||
oid $(git rev-parse two:two.t)
|
||||
oid $(git rev-parse two:two.t)
|
||||
oid $two_oid
|
||||
oid $two_oid
|
||||
0000
|
||||
EOF
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
size
|
||||
$(git rev-parse two:two.t) $(wc -c <two.t | xargs)
|
||||
$(git rev-parse two:two.t) $(wc -c <two.t | xargs)
|
||||
$two_oid $two_size
|
||||
$two_oid $two_size
|
||||
0000
|
||||
EOF
|
||||
|
||||
test-tool serve-v2 --stateless-rpc <in >out &&
|
||||
test-tool pkt-line unpack <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'object-info supports type' '
|
||||
test_config transfer.advertiseObjectInfo true &&
|
||||
|
||||
two_oid=$(git rev-parse two:two.t) &&
|
||||
two_size=$(test_file_size two.t) &&
|
||||
|
||||
test-tool pkt-line pack >in <<-EOF &&
|
||||
command=object-info
|
||||
object-format=$(test_oid algo)
|
||||
0001
|
||||
size
|
||||
type
|
||||
oid $two_oid
|
||||
oid $two_oid
|
||||
0000
|
||||
EOF
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
size
|
||||
type
|
||||
$two_oid $two_size blob
|
||||
$two_oid $two_size blob
|
||||
0000
|
||||
EOF
|
||||
|
||||
|
||||
12
transport.c
12
transport.c
@@ -438,11 +438,6 @@ static int fetch_object_info_via_pack(struct transport *transport)
|
||||
int ret = 0;
|
||||
struct git_transport_data *data = transport->data;
|
||||
struct packet_reader reader;
|
||||
struct object_info_args args = { 0 };
|
||||
|
||||
args.server_options = transport->server_options;
|
||||
args.oids = transport->smart_options->object_info_oids;
|
||||
args.object_info_options = transport->smart_options->object_info_options;
|
||||
|
||||
connect_setup(transport, 0);
|
||||
packet_reader_init(&reader, data->fd[0], NULL, 0,
|
||||
@@ -453,8 +448,11 @@ static int fetch_object_info_via_pack(struct transport *transport)
|
||||
data->version = discover_version(&reader);
|
||||
transport->hash_algo = reader.hash_algo;
|
||||
|
||||
ret = fetch_object_info(data->version, &args, &reader,
|
||||
data->options.object_info_data,
|
||||
ret = fetch_object_info(data->version,
|
||||
transport->server_options,
|
||||
transport->smart_options->object_info_oids,
|
||||
&reader,
|
||||
data->options.object_info_results,
|
||||
transport->stateless_rpc, data->fd[1]);
|
||||
|
||||
close(data->fd[0]);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "string-list.h"
|
||||
#include "connect.h"
|
||||
|
||||
struct fetch_object_info_results;
|
||||
|
||||
struct git_transport_options {
|
||||
unsigned thin : 1;
|
||||
unsigned keep : 1;
|
||||
@@ -57,8 +59,7 @@ struct git_transport_options {
|
||||
struct oidset *acked_commits;
|
||||
|
||||
struct oid_array *object_info_oids;
|
||||
struct object_info *object_info_data;
|
||||
struct string_list *object_info_options;
|
||||
struct fetch_object_info_results *object_info_results;
|
||||
};
|
||||
|
||||
enum transport_family {
|
||||
|
||||
Reference in New Issue
Block a user