sha1_file: add repository argument to sha1_file_name
Add a repository argument to allow sha1_file_name callers to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. While at it, move the declaration to object-store.h, where it should be easier to find. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
13068bf0a0
commit
cf78ae4f3d
6
cache.h
6
cache.h
@ -961,12 +961,6 @@ extern void check_repository_format(void);
|
|||||||
#define DATA_CHANGED 0x0020
|
#define DATA_CHANGED 0x0020
|
||||||
#define TYPE_CHANGED 0x0040
|
#define TYPE_CHANGED 0x0040
|
||||||
|
|
||||||
/*
|
|
||||||
* Put in `buf` the name of the file in the local object database that
|
|
||||||
* would be used to store a loose object with the specified sha1.
|
|
||||||
*/
|
|
||||||
extern void sha1_file_name(struct strbuf *buf, const unsigned char *sha1);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return an abbreviated sha1 unique within this repository's object database.
|
* Return an abbreviated sha1 unique within this repository's object database.
|
||||||
* The result will be at least `len` characters long, and will be NUL
|
* The result will be at least `len` characters long, and will be NUL
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "repository.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "walker.h"
|
#include "walker.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
@ -546,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
|
|||||||
ret = error("File %s has bad hash", hex);
|
ret = error("File %s has bad hash", hex);
|
||||||
} else if (req->rename < 0) {
|
} else if (req->rename < 0) {
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
sha1_file_name(&buf, req->sha1);
|
sha1_file_name(the_repository, &buf, req->sha1);
|
||||||
ret = error("unable to write sha1 filename %s", buf.buf);
|
ret = error("unable to write sha1 filename %s", buf.buf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
|
5
http.c
5
http.c
@ -2247,7 +2247,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
|
|||||||
hashcpy(freq->sha1, sha1);
|
hashcpy(freq->sha1, sha1);
|
||||||
freq->localfile = -1;
|
freq->localfile = -1;
|
||||||
|
|
||||||
sha1_file_name(&filename, sha1);
|
sha1_file_name(the_repository, &filename, sha1);
|
||||||
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
|
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
|
||||||
"%s.temp", filename.buf);
|
"%s.temp", filename.buf);
|
||||||
|
|
||||||
@ -2396,8 +2396,7 @@ int finish_http_object_request(struct http_object_request *freq)
|
|||||||
unlink_or_warn(freq->tmpfile);
|
unlink_or_warn(freq->tmpfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
sha1_file_name(the_repository, &filename, freq->sha1);
|
||||||
sha1_file_name(&filename, freq->sha1);
|
|
||||||
freq->rename = finalize_object_file(freq->tmpfile, filename.buf);
|
freq->rename = finalize_object_file(freq->tmpfile, filename.buf);
|
||||||
strbuf_release(&filename);
|
strbuf_release(&filename);
|
||||||
|
|
||||||
|
@ -121,4 +121,11 @@ struct raw_object_store {
|
|||||||
struct raw_object_store *raw_object_store_new(void);
|
struct raw_object_store *raw_object_store_new(void);
|
||||||
void raw_object_store_clear(struct raw_object_store *o);
|
void raw_object_store_clear(struct raw_object_store *o);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Put in `buf` the name of the file in the local object database that
|
||||||
|
* would be used to store a loose object with the specified sha1.
|
||||||
|
*/
|
||||||
|
#define sha1_file_name(r, b, s) sha1_file_name_##r(b, s)
|
||||||
|
void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1);
|
||||||
|
|
||||||
#endif /* OBJECT_STORE_H */
|
#endif /* OBJECT_STORE_H */
|
||||||
|
10
sha1_file.c
10
sha1_file.c
@ -323,7 +323,7 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sha1_file_name(struct strbuf *buf, const unsigned char *sha1)
|
void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
strbuf_addstr(buf, get_object_directory());
|
strbuf_addstr(buf, get_object_directory());
|
||||||
strbuf_addch(buf, '/');
|
strbuf_addch(buf, '/');
|
||||||
@ -713,7 +713,7 @@ static int check_and_freshen_local(const unsigned char *sha1, int freshen)
|
|||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
sha1_file_name(&buf, sha1);
|
sha1_file_name(the_repository, &buf, sha1);
|
||||||
|
|
||||||
return check_and_freshen_file(buf.buf, freshen);
|
return check_and_freshen_file(buf.buf, freshen);
|
||||||
}
|
}
|
||||||
@ -874,7 +874,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
|
|||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
sha1_file_name(&buf, sha1);
|
sha1_file_name(the_repository, &buf, sha1);
|
||||||
*path = buf.buf;
|
*path = buf.buf;
|
||||||
|
|
||||||
if (!lstat(*path, st))
|
if (!lstat(*path, st))
|
||||||
@ -903,7 +903,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
|
|||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
sha1_file_name(&buf, sha1);
|
sha1_file_name(the_repository, &buf, sha1);
|
||||||
*path = buf.buf;
|
*path = buf.buf;
|
||||||
|
|
||||||
fd = git_open(*path);
|
fd = git_open(*path);
|
||||||
@ -1588,7 +1588,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
|
|||||||
static struct strbuf filename = STRBUF_INIT;
|
static struct strbuf filename = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&filename);
|
strbuf_reset(&filename);
|
||||||
sha1_file_name(&filename, sha1);
|
sha1_file_name(the_repository, &filename, sha1);
|
||||||
|
|
||||||
fd = create_tmpfile(&tmp_file, filename.buf);
|
fd = create_tmpfile(&tmp_file, filename.buf);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user