]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-name: move related functions to object-name
authorCalvin Wan <calvinwan@google.com>
Tue, 6 Jun 2023 19:48:41 +0000 (19:48 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jun 2023 20:49:36 +0000 (13:49 -0700)
Move object-name-related functions from strbuf.[ch] to object-name.[ch]
so that strbuf is focused on string manipulation routines with minimal
dependencies.

dir.h relied on the forward declration of the repository struct in
strbuf.h. Since that is removed in this patch, add the forward
declaration to dir.h.

Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.h
object-name.c
object-name.h
pretty.c
strbuf.c
strbuf.h

diff --git a/dir.h b/dir.h
index 79b85a01ee40b551268c8ad7bc675fffa66c7f51..4d83febe9e72b96839e58e405b66c9e4eacc31d7 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -40,6 +40,8 @@
  *
  */
 
+struct repository;
+
 struct dir_entry {
        unsigned int len;
        char name[FLEX_ARRAY]; /* more */
index 6fc3fa595b87d348dbab071b0d60db02ad4e75fe..34e0f567037d309cd6d12dc2b1249e751264e803 100644 (file)
@@ -768,6 +768,21 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
                find_abbrev_len_for_pack(p, mad);
 }
 
+void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
+                                  const struct object_id *oid, int abbrev_len)
+{
+       int r;
+       strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
+       r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
+       strbuf_setlen(sb, sb->len + r);
+}
+
+void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
+                             int abbrev_len)
+{
+       strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
+}
+
 int repo_find_unique_abbrev_r(struct repository *r, char *hex,
                              const struct object_id *oid, int len)
 {
index 1d63698f42b7b5f247381ea2dd1bb8448cfc44d3..9ae52230714876b719dd3d48755ad3885030d07a 100644 (file)
@@ -40,6 +40,15 @@ struct object_context {
 const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 
+/**
+ * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
+ * the strbuf `sb`.
+ */
+void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
+                                  const struct object_id *oid, int abbrev_len);
+void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
+                             int abbrev_len);
+
 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
 __attribute__((format (printf, 2, 3)))
 int get_oidf(struct object_id *oid, const char *fmt, ...);
index 0bb938021ba593df826b91d39a2ec7a059e84b61..78bac2d8189c3038cc70cf085ca454777b9299a7 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -18,6 +18,7 @@
 #include "gpg-interface.h"
 #include "trailer.h"
 #include "run-command.h"
+#include "object-name.h"
 
 /*
  * The limit for formatting directives, which enable the caller to append
index 5244029d91335372343f279f64d2d2ba4b91987d..80b7e051cd9051b4aa89bf0f633dd258441879c4 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -3,7 +3,6 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
-#include "object-name.h"
 #include "repository.h"
 #include "strbuf.h"
 #include "string-list.h"
@@ -1024,21 +1023,6 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
        strbuf_setlen(sb, sb->len + len);
 }
 
-void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
-                                  const struct object_id *oid, int abbrev_len)
-{
-       int r;
-       strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
-       r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
-       strbuf_setlen(sb, sb->len + r);
-}
-
-void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
-                             int abbrev_len)
-{
-       strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
-}
-
 /*
  * Returns the length of a line, without trailing spaces.
  *
index 114ad0c02445767a01d2978880f1135afe89bf21..5d97e27b991683b48bfd6a74ad139ef4b726b72f 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -616,16 +616,6 @@ void strbuf_add_separated_string_list(struct strbuf *str,
  */
 void strbuf_list_free(struct strbuf **list);
 
-/**
- * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
- * the strbuf `sb`.
- */
-struct repository;
-void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
-                                  const struct object_id *oid, int abbrev_len);
-void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
-                             int abbrev_len);
-
 /*
  * Remove the filename from the provided path string. If the path
  * contains a trailing separator, then the path is considered a directory