Skip to contentSkip to conversation

worktree_git_path(): move the declaration to path.h

PATCH In review Junio C Hamano 2 participants 3 messages Jun 8, 2024 – Jun 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 worktree_git_path(): move the declaration to path.h

The definition of this function is in path.c but its declaration is in worktree.h, which is something unexpected. The function is explained as "Similar to git_path()"; declaring it next to where git_path() is declared would make more sense.

---
 path.h     | 9 +++++++++
 revision.c | 1 +
 worktree.h | 8 --------
 3 files changed, 10 insertions(+), 8 deletions(-)
path.h +9 -0
index c3bc8617bd..a6f0b70692 100644
@@ -4,6 +4,7 @@
 struct repository;
 struct strbuf;
 struct string_list;
+struct worktree;
 
 /*
  * The result to all functions which return statically allocated memory may be
@@ -81,6 +82,14 @@ void strbuf_repo_git_path(struct strbuf *sb,
 const char *git_path(const char *fmt, ...)
 	__attribute__((format (printf, 1, 2)));
 
+/*
+ * Similar to git_path() but can produce paths for a specified
+ * worktree instead of current one
+ */
+const char *worktree_git_path(const struct worktree *wt,
+			      const char *fmt, ...)
+	__attribute__((format (printf, 2, 3)));
+
 /*
  * Return a path into the main repository's (the_repository) git directory.
  */
revision.c +1 -0
index 7ddf0f151a..09024cf4aa 100644
@@ -29,6 +29,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "path.h"
 #include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
worktree.h +0 -8
index 7cc6d90e66..11279d0c8f 100644
@@ -177,14 +177,6 @@ int other_head_refs(each_ref_fn fn, void *cb_data);
 int is_worktree_being_rebased(const struct worktree *wt, const char *target);
 int is_worktree_being_bisected(const struct worktree *wt, const char *target);
 
-/*
- * Similar to git_path() but can produce paths for a specified
- * worktree instead of current one
- */
-const char *worktree_git_path(const struct worktree *wt,
-			      const char *fmt, ...)
-	__attribute__((format (printf, 2, 3)));
-
 /*
  * Return a refname suitable for access from the current ref store.
  */
Signature · 1 line
2.45.2-445-g1b76f06508
#1 lore raw
Quoted 72 lines · Junio C Hamano

The definition of this function is in path.c but its declaration is in worktree.h, which is something unexpected. The function is explained as "Similar to git_path()"; declaring it next to where git_path() is declared would make more sense.

---
 path.h     | 9 +++++++++
 revision.c | 1 +
 worktree.h | 8 --------
 3 files changed, 10 insertions(+), 8 deletions(-)
path.h +9 -0
index c3bc8617bd..a6f0b70692 100644
@@ -4,6 +4,7 @@
 struct repository;
 struct strbuf;
 struct string_list;
+struct worktree;
 
 /*
  * The result to all functions which return statically allocated memory may be
@@ -81,6 +82,14 @@ void strbuf_repo_git_path(struct strbuf *sb,
 const char *git_path(const char *fmt, ...)
        __attribute__((format (printf, 1, 2)));
 
+/*
+ * Similar to git_path() but can produce paths for a specified
+ * worktree instead of current one
+ */
+const char *worktree_git_path(const struct worktree *wt,
+                             const char *fmt, ...)
+       __attribute__((format (printf, 2, 3)));
+
 /*
  * Return a path into the main repository's (the_repository) git directory.
  */
revision.c +1 -0
index 7ddf0f151a..09024cf4aa 100644
@@ -29,6 +29,7 @@
 #include "bisect.h"
 #include "packfile.h"
 #include "worktree.h"
+#include "path.h"
 #include "read-cache.h"
 #include "setup.h"
 #include "sparse-index.h"
worktree.h +0 -9
index 7cc6d90e66..11279d0c8f 100644
@@ -177,14 +177,6 @@ int other_head_refs(each_ref_fn fn, void *cb_data);
 int is_worktree_being_rebased(const struct worktree *wt, const char *target);
 int is_worktree_being_bisected(const struct worktree *wt, const char *target);
 
-/*
- * Similar to git_path() but can produce paths for a specified
- * worktree instead of current one
- */
-const char *worktree_git_path(const struct worktree *wt,
-                             const char *fmt, ...)
-       __attribute__((format (printf, 2, 3)));
-
 /*
  * Return a refname suitable for access from the current ref store.
  */
--
Quoted 1 line

2.45.2-445-g1b76f06508

Simple and straightforward, and the rationale makes sense to me.

#2 lore raw
Quoted 7 lines · Elijah Newren
Quoted 6 lines · Junio C Hamano

The definition of this function is in path.c but its declaration is in worktree.h, which is something unexpected. The function is explained as "Similar to git_path()"; declaring it next to where git_path() is declared would make more sense.

Quoted 8 lines
Quoted 6 lines
---
 path.h     | 9 +++++++++
 revision.c | 1 +
 worktree.h | 8 --------
 3 files changed, 10 insertions(+), 8 deletions(-)

Simple and straightforward, and the rationale makes sense to me.

Thanks. It helped that there was only one customer that needed adjustment. Will merge to 'next'.