Skip to content

Commit 67dc598

Browse files
kbleesgitster
authored andcommitted
sha1_file: change GIT_TRACE_PACK_ACCESS logging to use trace API
This changes GIT_TRACE_PACK_ACCESS functionality as follows: * supports the same options as GIT_TRACE (e.g. printing to stderr) * no longer supports relative paths * appends to the trace file rather than overwriting Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb9250d commit 67dc598

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

Documentation/git.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,11 @@ Unsetting the variable, or setting it to empty, "0" or
925925
"false" (case insensitive) disables trace messages.
926926

927927
'GIT_TRACE_PACK_ACCESS'::
928-
If this variable is set to a path, a file will be created at
929-
the given path logging all accesses to any packs. For each
928+
Enables trace messages for all accesses to any packs. For each
930929
access, the pack file name and an offset in the pack is
931930
recorded. This may be helpful for troubleshooting some
932931
pack-related performance problems.
932+
See 'GIT_TRACE' for available trace output options.
933933

934934
'GIT_TRACE_PACKET'::
935935
Enables trace messages for all packets coming in or out of a

sha1_file.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
3636

3737
const unsigned char null_sha1[20];
3838

39-
static const char *no_log_pack_access = "no_log_pack_access";
40-
static const char *log_pack_access;
41-
4239
/*
4340
* This is meant to hold a *small* number of objects that you would
4441
* want read_sha1_file() to be able to return, but yet you do not want
@@ -2085,27 +2082,9 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
20852082

20862083
static void write_pack_access_log(struct packed_git *p, off_t obj_offset)
20872084
{
2088-
static FILE *log_file;
2089-
2090-
if (!log_pack_access)
2091-
log_pack_access = getenv("GIT_TRACE_PACK_ACCESS");
2092-
if (!log_pack_access)
2093-
log_pack_access = no_log_pack_access;
2094-
if (log_pack_access == no_log_pack_access)
2095-
return;
2096-
2097-
if (!log_file) {
2098-
log_file = fopen(log_pack_access, "w");
2099-
if (!log_file) {
2100-
error("cannot open pack access log '%s' for writing: %s",
2101-
log_pack_access, strerror(errno));
2102-
log_pack_access = no_log_pack_access;
2103-
return;
2104-
}
2105-
}
2106-
fprintf(log_file, "%s %"PRIuMAX"\n",
2107-
p->pack_name, (uintmax_t)obj_offset);
2108-
fflush(log_file);
2085+
static struct trace_key pack_access = TRACE_KEY_INIT(PACK_ACCESS);
2086+
trace_printf_key(&pack_access, "%s %"PRIuMAX"\n",
2087+
p->pack_name, (uintmax_t)obj_offset);
21092088
}
21102089

21112090
int do_check_packed_object_crc;
@@ -2130,8 +2109,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
21302109
int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
21312110
int base_from_cache = 0;
21322111

2133-
if (log_pack_access != no_log_pack_access)
2134-
write_pack_access_log(p, obj_offset);
2112+
write_pack_access_log(p, obj_offset);
21352113

21362114
/* PHASE 1: drill down to the innermost base object */
21372115
for (;;) {

0 commit comments

Comments
 (0)