Skip to content

Commit f940185

Browse files
calvin-wan-googlegitster
authored andcommitted
object-name: move related functions to object-name
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f898543 commit f940185

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

dir.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*
4141
*/
4242

43+
struct repository;
44+
4345
struct dir_entry {
4446
unsigned int len;
4547
char name[FLEX_ARRAY]; /* more */

object-name.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,21 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
768768
find_abbrev_len_for_pack(p, mad);
769769
}
770770

771+
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
772+
const struct object_id *oid, int abbrev_len)
773+
{
774+
int r;
775+
strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
776+
r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
777+
strbuf_setlen(sb, sb->len + r);
778+
}
779+
780+
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
781+
int abbrev_len)
782+
{
783+
strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
784+
}
785+
771786
int repo_find_unique_abbrev_r(struct repository *r, char *hex,
772787
const struct object_id *oid, int len)
773788
{

object-name.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ struct object_context {
4040
const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
4141
int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
4242

43+
/**
44+
* Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
45+
* the strbuf `sb`.
46+
*/
47+
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
48+
const struct object_id *oid, int abbrev_len);
49+
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
50+
int abbrev_len);
51+
4352
int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
4453
__attribute__((format (printf, 2, 3)))
4554
int get_oidf(struct object_id *oid, const char *fmt, ...);

pretty.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "gpg-interface.h"
1919
#include "trailer.h"
2020
#include "run-command.h"
21+
#include "object-name.h"
2122

2223
/*
2324
* The limit for formatting directives, which enable the caller to append

strbuf.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "environment.h"
44
#include "gettext.h"
55
#include "hex.h"
6-
#include "object-name.h"
76
#include "repository.h"
87
#include "strbuf.h"
98
#include "string-list.h"
@@ -1024,21 +1023,6 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
10241023
strbuf_setlen(sb, sb->len + len);
10251024
}
10261025

1027-
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
1028-
const struct object_id *oid, int abbrev_len)
1029-
{
1030-
int r;
1031-
strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
1032-
r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
1033-
strbuf_setlen(sb, sb->len + r);
1034-
}
1035-
1036-
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
1037-
int abbrev_len)
1038-
{
1039-
strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
1040-
}
1041-
10421026
/*
10431027
* Returns the length of a line, without trailing spaces.
10441028
*

strbuf.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,6 @@ void strbuf_add_separated_string_list(struct strbuf *str,
616616
*/
617617
void strbuf_list_free(struct strbuf **list);
618618

619-
/**
620-
* Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
621-
* the strbuf `sb`.
622-
*/
623-
struct repository;
624-
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
625-
const struct object_id *oid, int abbrev_len);
626-
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
627-
int abbrev_len);
628-
629619
/*
630620
* Remove the filename from the provided path string. If the path
631621
* contains a trailing separator, then the path is considered a directory

0 commit comments

Comments
 (0)