aboutsummaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2014-07-12 02:00:06 +0200
committerJunio C Hamano <gitster@pobox.com>2014-07-13 21:24:23 -0700
commit6aa3085702cc7a436c12f4c4396958281df1da44 (patch)
treea01c3df1a78b0db0334349156f1971b7eeb172b0 /shallow.c
parent0d0424272f85afb5262613829cf1f48f994cebc7 (diff)
downloadgit-6aa3085702cc7a436c12f4c4396958281df1da44.tar.gz
git-6aa3085702cc7a436c12f4c4396958281df1da44.tar.xz
trace: improve trace performance
The trace API currently rechecks the environment variable and reopens the trace file on every API call. This has the ugly side effect that errors (e.g. file cannot be opened, or the user specified a relative path) are also reported on every call. Performance can be improved by about factor three by remembering the environment state and keeping the file open. Replace the 'const char *key' parameter in the API with a pointer to a 'struct trace_key' that bundles the environment variable name with additional, trace-internal state. Change the call sites of these APIs to use a static 'struct trace_key' instead of a string constant. In trace.c::get_trace_fd(), save and reuse the file descriptor in 'struct trace_key'. Add a 'trace_disable()' API, so that packet_trace() can cleanly disable tracing when it encounters packed data (instead of using unsetenv()). Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/shallow.c b/shallow.c
index 0b267b641..de07709e3 100644
--- a/shallow.c
+++ b/shallow.c
@@ -325,7 +325,7 @@ void prune_shallow(int show_only)
strbuf_release(&sb);
}
-#define TRACE_KEY "GIT_TRACE_SHALLOW"
+struct trace_key trace_shallow = TRACE_KEY_INIT(SHALLOW);
/*
* Step 1, split sender shallow commits into "ours" and "theirs"
@@ -334,7 +334,7 @@ void prune_shallow(int show_only)
void prepare_shallow_info(struct shallow_info *info, struct sha1_array *sa)
{
int i;
- trace_printf_key(TRACE_KEY, "shallow: prepare_shallow_info\n");
+ trace_printf_key(&trace_shallow, "shallow: prepare_shallow_info\n");
memset(info, 0, sizeof(*info));
info->shallow = sa;
if (!sa)
@@ -365,7 +365,7 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
{
unsigned char (*sha1)[20] = info->shallow->sha1;
int i, dst;
- trace_printf_key(TRACE_KEY, "shallow: remove_nonexistent_theirs_shallow\n");
+ trace_printf_key(&trace_shallow, "shallow: remove_nonexistent_theirs_shallow\n");
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
@@ -516,7 +516,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
int *shallow, nr_shallow = 0;
struct paint_info pi;
- trace_printf_key(TRACE_KEY, "shallow: assign_shallow_commits_to_refs\n");
+ trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n");
shallow = xmalloc(sizeof(*shallow) * (info->nr_ours + info->nr_theirs));
for (i = 0; i < info->nr_ours; i++)
shallow[nr_shallow++] = info->ours[i];
@@ -622,7 +622,7 @@ static void post_assign_shallow(struct shallow_info *info,
int bitmap_nr = (info->ref->nr + 31) / 32;
struct commit_array ca;
- trace_printf_key(TRACE_KEY, "shallow: post_assign_shallow\n");
+ trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");
if (ref_status)
memset(ref_status, 0, sizeof(*ref_status) * info->ref->nr);