mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
Merge branch 'cc/write-promisor-file'
A bit of code refactoring. * cc/write-promisor-file: pack-write: die on error in write_promisor_file() fetch-pack: refactor writing promisor file fetch-pack: rename helper to create_promisor_file()
This commit is contained in:
commit
7eefa1349b
|
@ -14,6 +14,7 @@
|
|||
#include "object-store.h"
|
||||
#include "promisor-remote.h"
|
||||
#include "shallow.h"
|
||||
#include "pack.h"
|
||||
|
||||
static int delta_base_offset = 1;
|
||||
static int pack_kept_objects = -1;
|
||||
|
@ -263,7 +264,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
|
|||
while (strbuf_getline_lf(&line, out) != EOF) {
|
||||
struct string_list_item *item;
|
||||
char *promisor_name;
|
||||
int fd;
|
||||
|
||||
if (line.len != the_hash_algo->hexsz)
|
||||
die(_("repack: Expecting full hex object ID lines only from pack-objects."));
|
||||
item = string_list_append(names, line.buf);
|
||||
|
@ -281,10 +282,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
|
|||
*/
|
||||
promisor_name = mkpathdup("%s-%s.promisor", packtmp,
|
||||
line.buf);
|
||||
fd = open(promisor_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
|
||||
if (fd < 0)
|
||||
die_errno(_("unable to create '%s'"), promisor_name);
|
||||
close(fd);
|
||||
write_promisor_file(promisor_name, NULL, 0);
|
||||
|
||||
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
|
||||
|
||||
|
|
16
fetch-pack.c
16
fetch-pack.c
|
@ -772,13 +772,11 @@ static int sideband_demux(int in, int out, void *data)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void write_promisor_file(const char *keep_name,
|
||||
struct ref **sought, int nr_sought)
|
||||
static void create_promisor_file(const char *keep_name,
|
||||
struct ref **sought, int nr_sought)
|
||||
{
|
||||
struct strbuf promisor_name = STRBUF_INIT;
|
||||
int suffix_stripped;
|
||||
FILE *output;
|
||||
int i;
|
||||
|
||||
strbuf_addstr(&promisor_name, keep_name);
|
||||
suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep");
|
||||
|
@ -787,11 +785,7 @@ static void write_promisor_file(const char *keep_name,
|
|||
keep_name);
|
||||
strbuf_addstr(&promisor_name, ".promisor");
|
||||
|
||||
output = xfopen(promisor_name.buf, "w");
|
||||
for (i = 0; i < nr_sought; i++)
|
||||
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
|
||||
sought[i]->name);
|
||||
fclose(output);
|
||||
write_promisor_file(promisor_name.buf, sought, nr_sought);
|
||||
|
||||
strbuf_release(&promisor_name);
|
||||
}
|
||||
|
@ -875,7 +869,7 @@ static int get_pack(struct fetch_pack_args *args,
|
|||
|
||||
if (args->from_promisor)
|
||||
/*
|
||||
* write_promisor_file() may be called afterwards but
|
||||
* create_promisor_file() may be called afterwards but
|
||||
* we still need index-pack to know that this is a
|
||||
* promisor pack. For example, if transfer.fsckobjects
|
||||
* is true, index-pack needs to know that .gitmodules
|
||||
|
@ -943,7 +937,7 @@ static int get_pack(struct fetch_pack_args *args,
|
|||
* obtained .keep filename if necessary
|
||||
*/
|
||||
if (do_keep && pack_lockfiles && pack_lockfiles->nr && args->from_promisor)
|
||||
write_promisor_file(pack_lockfiles->items[0].string, sought, nr_sought);
|
||||
create_promisor_file(pack_lockfiles->items[0].string, sought, nr_sought);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
16
pack-write.c
16
pack-write.c
|
@ -1,6 +1,7 @@
|
|||
#include "cache.h"
|
||||
#include "pack.h"
|
||||
#include "csum-file.h"
|
||||
#include "remote.h"
|
||||
|
||||
void reset_pack_idx_option(struct pack_idx_option *opts)
|
||||
{
|
||||
|
@ -367,3 +368,18 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
|
|||
|
||||
free((void *)idx_tmp_name);
|
||||
}
|
||||
|
||||
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)
|
||||
{
|
||||
int i, err;
|
||||
FILE *output = xfopen(promisor_name, "w");
|
||||
|
||||
for (i = 0; i < nr_sought; i++)
|
||||
fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid),
|
||||
sought[i]->name);
|
||||
|
||||
err = ferror(output);
|
||||
err |= fclose(output);
|
||||
if (err)
|
||||
die(_("could not write '%s' promisor file"), promisor_name);
|
||||
}
|
||||
|
|
4
pack.h
4
pack.h
|
@ -87,6 +87,10 @@ off_t write_pack_header(struct hashfile *f, uint32_t);
|
|||
void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
|
||||
char *index_pack_lockfile(int fd);
|
||||
|
||||
struct ref;
|
||||
|
||||
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought);
|
||||
|
||||
/*
|
||||
* The "hdr" output buffer should be at least this big, which will handle sizes
|
||||
* up to 2^67.
|
||||
|
|
Loading…
Reference in a new issue