Skip to content

Commit

Permalink
odb--daemon: rename get-nth-ancestor to get-ancestor
Browse files Browse the repository at this point in the history
Reduce the length of the IPC API `get-nth-ancestor` to be shorter, so
that the request key is less than 15 characters + 1 null terminator.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
  • Loading branch information
mjcheetham committed Apr 24, 2024
1 parent fb50118 commit 73ffe3c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions builtin/odb--daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,21 @@ static int odb_ipc_cb__get_parent(struct my_odb_ipc_state *state,
return 0;
}

static int odb_ipc_cb__get_nth_ancestor(struct my_odb_ipc_state *state,
const char *command, size_t command_len,
ipc_server_reply_cb *reply_cb,
struct ipc_server_reply_data *reply_data)
static int odb_ipc_cb__get_ancestor(struct my_odb_ipc_state *state,
const char *command, size_t command_len,
ipc_server_reply_cb *reply_cb,
struct ipc_server_reply_data *reply_data)
{
struct odb_over_ipc__get_nth_ancestor__request *req;
struct odb_over_ipc__get_nth_ancestor__response *resp;
struct odb_over_ipc__get_ancestor__request *req;
struct odb_over_ipc__get_ancestor__response *resp;
const char *name;
size_t name_len;
int ret;

if (command_len < sizeof(*req))
BUG("incorrect size for binary data");

req = (struct odb_over_ipc__get_nth_ancestor__request *)command;
req = (struct odb_over_ipc__get_ancestor__request *)command;

name = command + sizeof(*req);
name_len = command_len - sizeof(*req);
Expand All @@ -278,7 +278,7 @@ static int odb_ipc_cb__get_nth_ancestor(struct my_odb_ipc_state *state,
BUG("incorrect data length");

resp = xmalloc(sizeof(*resp));
memcpy(&resp->key.key, "get-nth-ancestor", 11);
memcpy(&resp->key.key, "get-ancestor", 11);

ret = get_nth_ancestor(the_repository, name, name_len, &resp->oid,
req->generation);
Expand Down Expand Up @@ -377,14 +377,14 @@ static int odb_ipc_cb(void *data,
return 0;
}

if (!strcmp(command, "get-nth-ancestor")) {
if (!strcmp(command, "get-ancestor")) {
/*
* A client has requested that we find the nth ancestpr of a
* given object.
*/
trace2_region_enter("odb-daemon", "get-nth-ancestor", NULL);
ret = odb_ipc_cb__get_nth_ancestor(state, command, command_len,
reply_cb, reply_data);
ret = odb_ipc_cb__get_ancestor(state, command, command_len,
reply_cb, reply_data);
trace2_region_leave("odb-daemon", "get-nth-ancestor", NULL);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion object-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ enum get_oid_result get_nth_ancestor(struct repository *r,
struct commit *commit;
int ret;

if (odb_over_ipc__get_nth_ancestor(r, name, len, generation, result) == 0)
if (odb_over_ipc__get_ancestor(r, name, len, generation, result) == 0)
return FOUND;

ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
Expand Down
14 changes: 7 additions & 7 deletions odb-over-ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ int odb_over_ipc__get_parent(struct repository *r, const char *name, int len,
return ret;
}

int odb_over_ipc__get_nth_ancestor(struct repository *r, const char *name,
int len, int generation,
struct object_id *result)
int odb_over_ipc__get_ancestor(struct repository *r, const char *name,
int len, int generation,
struct object_id *result)
{
struct odb_over_ipc__get_nth_ancestor__request req;
struct odb_over_ipc__get_nth_ancestor__response *resp;
struct odb_over_ipc__get_ancestor__request req;
struct odb_over_ipc__get_ancestor__response *resp;
struct strbuf msg = STRBUF_INIT;
struct strbuf answer = STRBUF_INIT;
int ret;
Expand All @@ -331,7 +331,7 @@ int odb_over_ipc__get_nth_ancestor(struct repository *r, const char *name,
return -1;

memset(&req, 0, sizeof(req));
memcpy(req.key.key, "get-nth-ancestor", 16);
memcpy(req.key.key, "get-ancestor", 12);
req.generation = generation;
req.name_len = len;

Expand All @@ -351,7 +351,7 @@ int odb_over_ipc__get_nth_ancestor(struct repository *r, const char *name,

if (answer.len != sizeof(*resp))
BUG("incorrect size for binary data");
resp = (struct odb_over_ipc__get_nth_ancestor__response *)answer.buf;
resp = (struct odb_over_ipc__get_ancestor__response *)answer.buf;

oidcpy(result, &resp->oid);

Expand Down
10 changes: 5 additions & 5 deletions odb-over-ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ struct odb_over_ipc__get_parent__response
struct object_id oid;
};

struct odb_over_ipc__get_nth_ancestor__request
struct odb_over_ipc__get_ancestor__request
{
struct odb_over_ipc__key key;
int generation;
int name_len;
};

struct odb_over_ipc__get_nth_ancestor__response
struct odb_over_ipc__get_ancestor__response
{
struct odb_over_ipc__key key;
struct object_id oid;
Expand All @@ -129,9 +129,9 @@ int odb_over_ipc__hash_object(struct repository *r, struct object_id *oid,
int odb_over_ipc__get_parent(struct repository *r, const char *name, int len,
int idx, struct object_id *result);

int odb_over_ipc__get_nth_ancestor(struct repository *r, const char *name,
int len, int generation,
struct object_id *result);
int odb_over_ipc__get_ancestor(struct repository *r, const char *name,
int len, int generation,
struct object_id *result);

/*
* Explicitly shutdown IPC connection to the `git odb--daemon` process.
Expand Down

0 comments on commit 73ffe3c

Please sign in to comment.