Skip to content

Commit 65acfea

Browse files
committed
abbrev: add FALLBACK_DEFAULT_ABBREV to prepare for auto sizing
We'll be introducing a new way to decide the default abbreviation length by initialising DEFAULT_ABBREV to -1 to signal the first call to "find unique abbreviation" codepath to compute a reasonable value based on the number of objects we have to avoid collisions. We have long relied on DEFAULT_ABBREV being a positive concrete value that is used as the abbreviation length when no extra configuration or command line option has overridden it. Some codepaths wants to use such a positive concrete default value even before making their first request to actually trigger the computation for the auto sized default. Introduce FALLBACK_DEFAULT_ABBREV and use it to the code that attempts to align the report from "git fetch". For now, this macro is also used to initialize the default_abbrev variable, but the auto-sizing code will use -1 and then use the value of FALLBACK_DEFAULT_ABBREV as the starting point of auto-sizing. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b33cb1 commit 65acfea

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

builtin/fetch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "argv-array.h"
1818
#include "utf8.h"
1919

20+
#define TRANSPORT_SUMMARY(x) \
21+
(int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
22+
2023
static const char * const builtin_fetch_usage[] = {
2124
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
2225
N_("git fetch [<options>] <group>"),

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,9 @@ static inline int hex2chr(const char *s)
11831183
#define MINIMUM_ABBREV minimum_abbrev
11841184
#define DEFAULT_ABBREV default_abbrev
11851185

1186+
/* used when the code does not know or care what the default abbrev is */
1187+
#define FALLBACK_DEFAULT_ABBREV 7
1188+
11861189
struct object_context {
11871190
unsigned char tree[20];
11881191
char path[PATH_MAX];

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int trust_executable_bit = 1;
1616
int trust_ctime = 1;
1717
int check_stat = 1;
1818
int has_symlinks = 1;
19-
int minimum_abbrev = 4, default_abbrev = 7;
19+
int minimum_abbrev = 4, default_abbrev = FALLBACK_DEFAULT_ABBREV;
2020
int ignore_case;
2121
int assume_unchanged;
2222
int prefer_symlink_refs;

transport.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ struct transport {
142142
#define TRANSPORT_PUSH_ATOMIC 8192
143143
#define TRANSPORT_PUSH_OPTIONS 16384
144144

145-
#define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
146-
#define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
145+
#define TRANSPORT_SUMMARY_WIDTH (2 * FALLBACK_DEFAULT_ABBREV + 3)
147146

148147
/* Returns a transport suitable for the url */
149148
struct transport *transport_get(struct remote *, const char *);

0 commit comments

Comments
 (0)