sha1_file: allow open_sha1_file to handle arbitrary repositories
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
d2607fa053
commit
ec7283e586
11
sha1_file.c
11
sha1_file.c
@ -895,9 +895,8 @@ static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
|
|||||||
* Like stat_sha1_file(), but actually open the object and return the
|
* Like stat_sha1_file(), but actually open the object and return the
|
||||||
* descriptor. See the caveats on the "path" parameter above.
|
* descriptor. See the caveats on the "path" parameter above.
|
||||||
*/
|
*/
|
||||||
#define open_sha1_file(r, s, p) open_sha1_file_##r(s, p)
|
static int open_sha1_file(struct repository *r,
|
||||||
static int open_sha1_file_the_repository(const unsigned char *sha1,
|
const unsigned char *sha1, const char **path)
|
||||||
const char **path)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct alternate_object_database *alt;
|
struct alternate_object_database *alt;
|
||||||
@ -905,7 +904,7 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,
|
|||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
sha1_file_name(the_repository, &buf, sha1);
|
sha1_file_name(r, &buf, sha1);
|
||||||
*path = buf.buf;
|
*path = buf.buf;
|
||||||
|
|
||||||
fd = git_open(*path);
|
fd = git_open(*path);
|
||||||
@ -913,8 +912,8 @@ static int open_sha1_file_the_repository(const unsigned char *sha1,
|
|||||||
return fd;
|
return fd;
|
||||||
most_interesting_errno = errno;
|
most_interesting_errno = errno;
|
||||||
|
|
||||||
prepare_alt_odb(the_repository);
|
prepare_alt_odb(r);
|
||||||
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
|
for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
|
||||||
*path = alt_sha1_path(alt, sha1);
|
*path = alt_sha1_path(alt, sha1);
|
||||||
fd = git_open(*path);
|
fd = git_open(*path);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user