Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "sha1-array.h"
#include "gpg-interface.h"
#include "cache.h"
#include "gvfs.h"

int option_parse_push_signed(const struct option *opt,
const char *arg, int unset)
Expand Down Expand Up @@ -49,15 +48,15 @@ static int send_pack_config(const char *var, const char *value, void *unused)
return 0;
}

static void feed_object(const struct object_id *oid, FILE *fh, int negative)
static void add_to_oid_list(const struct object_id *oid, struct string_list *list, int negative)
{
if (negative && !gvfs_config_is_set(GVFS_MISSING_OK) && !has_sha1_file(oid->hash))
if (negative && !has_sha1_file(oid->hash))
return;

if (negative)
putc('^', fh);
fputs(oid_to_hex(oid), fh);
putc('\n', fh);
string_list_append(list, xstrfmt("^%s", oid_to_hex(oid)));
else
string_list_append(list, oid_to_hex(oid));
}

/*
Expand All @@ -74,6 +73,19 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
FILE *po_in;
int i;
int rc;
struct string_list oid_list = STRING_LIST_INIT_NODUP;
struct string_list_item *item;

for (i = 0; i < extra->nr; i++)
add_to_oid_list(&extra->oid[i], &oid_list, 1);

while (refs) {
if (!is_null_oid(&refs->old_oid))
add_to_oid_list(&refs->old_oid, &oid_list, 1);
if (!is_null_oid(&refs->new_oid))
add_to_oid_list(&refs->new_oid, &oid_list, 0);
refs = refs->next;
}

argv_array_push(&po.args, "pack-objects");
argv_array_push(&po.args, "--all-progress-implied");
Expand All @@ -100,15 +112,10 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
* parameters by writing to the pipe.
*/
po_in = xfdopen(po.in, "w");
for (i = 0; i < extra->nr; i++)
feed_object(&extra->oid[i], po_in, 1);

while (refs) {
if (!is_null_oid(&refs->old_oid))
feed_object(&refs->old_oid, po_in, 1);
if (!is_null_oid(&refs->new_oid))
feed_object(&refs->new_oid, po_in, 0);
refs = refs->next;

for_each_string_list_item(item, &oid_list) {
fputs(item->string, po_in);
putc('\n', po_in);
}

fflush(po_in);
Expand All @@ -130,6 +137,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
}

rc = finish_command(&po);
string_list_clear(&oid_list, 0);
if (rc) {
/*
* For a normal non-zero exit, we assume pack-objects wrote
Expand Down