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>
Stefan Beller committed
Mar 23, 2018 at 18:21 UTC
cf78ae4f3dcd1cf509a053023cc048f34f72140e
5 files changed
+16
-15
cache.h
-6
@@ -961,12 +961,6 @@ extern void check_repository_format(void);
961
#define DATA_CHANGED 0x0020
962
#define TYPE_CHANGED 0x0040
963
964
-/*
965
- * Put in `buf` the name of the file in the local object database that
966
- * would be used to store a loose object with the specified sha1.
967
- */
968
-extern void sha1_file_name(struct strbuf *buf, const unsigned char *sha1);
969
-
964
/*
965
* Return an abbreviated sha1 unique within this repository's object database.
966
* The result will be at least `len` characters long, and will be NUL
http-walker.c
+2
-1
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "repository.h"
3
#include "commit.h"
4
#include "walker.h"
5
#include "http.h"
@@ -546,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
547
ret = error("File %s has bad hash", hex);
548
} else if (req->rename < 0) {
549
struct strbuf buf = STRBUF_INIT;
549
- sha1_file_name(&buf, req->sha1);
550
+ sha1_file_name(the_repository, &buf, req->sha1);
551
ret = error("unable to write sha1 filename %s", buf.buf);
552
strbuf_release(&buf);
553
}
http.c
+2
-3
@@ -2247,7 +2247,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2247
hashcpy(freq->sha1, sha1);
2248
freq->localfile = -1;
2249
2250
- sha1_file_name(&filename, sha1);
2250
+ sha1_file_name(the_repository, &filename, sha1);
2251
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
2252
"%s.temp", filename.buf);
2253
@@ -2396,8 +2396,7 @@ int finish_http_object_request(struct http_object_request *freq)
2396
unlink_or_warn(freq->tmpfile);
2397
return -1;
2398
}
2399
-
2400
- sha1_file_name(&filename, freq->sha1);
2399
+ sha1_file_name(the_repository, &filename, freq->sha1);
2400
freq->rename = finalize_object_file(freq->tmpfile, filename.buf);
2401
strbuf_release(&filename);
2402
object-store.h
+7
@@ -121,4 +121,11 @@ struct raw_object_store {
121
struct raw_object_store *raw_object_store_new(void);
122
void raw_object_store_clear(struct raw_object_store *o);
123
124
+/*
125
+ * Put in `buf` the name of the file in the local object database that
126
+ * would be used to store a loose object with the specified sha1.
127
+ */
128
+#define sha1_file_name(r, b, s) sha1_file_name_##r(b, s)
129
+void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1);
130
+
131
#endif /* OBJECT_STORE_H */
sha1_file.c
+5
-5
@@ -323,7 +323,7 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
323
}
324
}
325
326
-void sha1_file_name(struct strbuf *buf, const unsigned char *sha1)
326
+void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1)
327
{
328
strbuf_addstr(buf, get_object_directory());
329
strbuf_addch(buf, '/');
@@ -713,7 +713,7 @@ static int check_and_freshen_local(const unsigned char *sha1, int freshen)
713
static struct strbuf buf = STRBUF_INIT;
714
715
strbuf_reset(&buf);
716
- sha1_file_name(&buf, sha1);
716
+ sha1_file_name(the_repository, &buf, sha1);
717
718
return check_and_freshen_file(buf.buf, freshen);
719
}
@@ -874,7 +874,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
874
static struct strbuf buf = STRBUF_INIT;
875
876
strbuf_reset(&buf);
877
- sha1_file_name(&buf, sha1);
877
+ sha1_file_name(the_repository, &buf, sha1);
878
*path = buf.buf;
879
880
if (!lstat(*path, st))
@@ -903,7 +903,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
903
static struct strbuf buf = STRBUF_INIT;
904
905
strbuf_reset(&buf);
906
- sha1_file_name(&buf, sha1);
906
+ sha1_file_name(the_repository, &buf, sha1);
907
*path = buf.buf;
908
909
fd = git_open(*path);
@@ -1588,7 +1588,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
1588
static struct strbuf filename = STRBUF_INIT;
1589
1590
strbuf_reset(&filename);
1591
- sha1_file_name(&filename, sha1);
1591
+ sha1_file_name(the_repository, &filename, sha1);
1592
1593
fd = create_tmpfile(&tmp_file, filename.buf);
1594
if (fd < 0) {