Add a repository argument to allow callers of add_to_alternates_file
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.

Signed-off-by: Jonathan Nieder <[email protected]>
Signed-off-by: Stefan Beller <[email protected]>
---
 alternates.h    | 3 ++-
 builtin/clone.c | 9 +++++----
 sha1_file.c     | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/alternates.h b/alternates.h
index df5dc67e2e..2d06b71e50 100644
--- a/alternates.h
+++ b/alternates.h
@@ -48,7 +48,8 @@ struct alternate_object_database *alloc_alt_odb(const char 
*dir);
  * Add the directory to the on-disk alternates file; the new entry will also
  * take effect in the current process.
  */
-extern void add_to_alternates_file(const char *dir);
+#define add_to_alternates_file(r, d) add_to_alternates_file_##r(d)
+extern void add_to_alternates_file_the_repository(const char *dir);
 
 /*
  * Add the directory to the in-memory list of alternates (along with any
diff --git a/builtin/clone.c b/builtin/clone.c
index 6efe189846..548255f955 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -11,6 +11,7 @@
 #include "builtin.h"
 #include "config.h"
 #include "lockfile.h"
+#include "repository.h"
 #include "alternates.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
@@ -330,7 +331,7 @@ static int add_one_reference(struct string_list_item *item, 
void *cb_data)
        } else {
                struct strbuf sb = STRBUF_INIT;
                strbuf_addf(&sb, "%s/objects", ref_git);
-               add_to_alternates_file(sb.buf);
+               add_to_alternates_file(the_repository, sb.buf);
                strbuf_release(&sb);
        }
 
@@ -372,12 +373,12 @@ static void copy_alternates(struct strbuf *src, struct 
strbuf *dst,
                if (!line.len || line.buf[0] == '#')
                        continue;
                if (is_absolute_path(line.buf)) {
-                       add_to_alternates_file(line.buf);
+                       add_to_alternates_file(the_repository, line.buf);
                        continue;
                }
                abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
                if (!normalize_path_copy(abs_path, abs_path))
-                       add_to_alternates_file(abs_path);
+                       add_to_alternates_file(the_repository, abs_path);
                else
                        warning("skipping invalid relative alternate: %s/%s",
                                src_repo, line.buf);
@@ -456,7 +457,7 @@ static void clone_local(const char *src_repo, const char 
*dest_repo)
                struct strbuf alt = STRBUF_INIT;
                get_common_dir(&alt, src_repo);
                strbuf_addstr(&alt, "/objects");
-               add_to_alternates_file(alt.buf);
+               add_to_alternates_file(the_repository, alt.buf);
                strbuf_release(&alt);
        } else {
                struct strbuf src = STRBUF_INIT;
diff --git a/sha1_file.c b/sha1_file.c
index 0c2e215ae5..066aa187a1 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -538,7 +538,7 @@ struct alternate_object_database *alloc_alt_odb(const char 
*dir)
        return ent;
 }
 
-void add_to_alternates_file(const char *reference)
+void add_to_alternates_file_the_repository(const char *reference)
 {
        struct lock_file lock = LOCK_INIT;
        char *alts = git_pathdup("objects/info/alternates");
-- 
2.15.1.433.g936d1b9894.dirty

Reply via email to