85
static const char err_msg[] = "Could not trace into fd given by "
86
"GIT_TRACE environment variable";
87
88
-static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
88
+static int prepare_trace_line(const char *file, int line,
89
+ struct trace_key *key, struct strbuf *buf)
90
{
91
static struct trace_key trace_bare = TRACE_KEY_INIT(BARE);
92
struct timeval tv;
109
strbuf_addf(buf, "%02d:%02d:%02d.%06ld ", tm.tm_hour, tm.tm_min,
110
tm.tm_sec, (long) tv.tv_usec);
111
112
+#ifdef HAVE_VARIADIC_MACROS
113
+ /* print file:line */
114
+ strbuf_addf(buf, "%s:%d ", file, line);
115
+ /* align trace output (column 40 catches most files names in git) */
116
+ while (buf->len < 40)
117
+ strbuf_addch(buf, ' ');
118
+#endif
119
+
120
return 1;
121
}
122
130
strbuf_release(buf);
131
}
132
124
-static void trace_vprintf(struct trace_key *key, const char *format, va_list ap)
133
+static void trace_vprintf_fl(const char *file, int line, struct trace_key *key,
134
+ const char *format, va_list ap)
135
{
136
struct strbuf buf = STRBUF_INIT;
137
128
- if (!prepare_trace_line(key, &buf))
138
+ if (!prepare_trace_line(file, line, key, &buf))
139
return;
140
141
strbuf_vaddf(&buf, format, ap);
142
print_trace_line(key, &buf);
143
}
144
135
-void trace_argv_printf(const char **argv, const char *format, ...)
145
+static void trace_argv_vprintf_fl(const char *file, int line,
146
+ const char **argv, const char *format,
147
+ va_list ap)
148
{
149
struct strbuf buf = STRBUF_INIT;
138
- va_list ap;
150
140
- if (!prepare_trace_line(NULL, &buf))
151
+ if (!prepare_trace_line(file, line, NULL, &buf))
152
return;
153
143
- va_start(ap, format);
154
strbuf_vaddf(&buf, format, ap);
145
- va_end(ap);
155
156
sq_quote_argv(&buf, argv, 0);
157
print_trace_line(NULL, &buf);
158
}
159
151
-void trace_strbuf(struct trace_key *key, const struct strbuf *data)
160
+void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
161
+ const struct strbuf *data)
162
{
163
struct strbuf buf = STRBUF_INIT;
164
155
- if (!prepare_trace_line(key, &buf))
165
+ if (!prepare_trace_line(file, line, key, &buf))
166
return;
167
168
strbuf_addbuf(&buf, data);
169
print_trace_line(key, &buf);
170
}
171
172
+#ifndef HAVE_VARIADIC_MACROS
173
+
174
void trace_printf(const char *format, ...)
175
{
176
va_list ap;
177
va_start(ap, format);
166
- trace_vprintf(NULL, format, ap);
178
+ trace_vprintf_fl(NULL, 0, NULL, format, ap);
179
va_end(ap);
180
}
181
183
{
184
va_list ap;
185
va_start(ap, format);
174
- trace_vprintf(key, format, ap);
186
+ trace_vprintf_fl(NULL, 0, key, format, ap);
187
+ va_end(ap);
188
+}
189
+
190
+void trace_argv_printf(const char **argv, const char *format, ...)
191
+{
192
+ va_list ap;
193
+ va_start(ap, format);
194
+ trace_argv_vprintf_fl(NULL, 0, argv, format, ap);
195
va_end(ap);
196
}
197
198
+void trace_strbuf(const char *key, const struct strbuf *data)
199
+{
200
+ trace_strbuf_fl(NULL, 0, key, data);
201
+}
202
+
203
+#else
204
+
205
+void trace_printf_key_fl(const char *file, int line, struct trace_key *key,
206
+ const char *format, ...)
207
+{
208
+ va_list ap;
209
+ va_start(ap, format);
210
+ trace_vprintf_fl(file, line, key, format, ap);
211
+ va_end(ap);
212
+}
213
+
214
+void trace_argv_printf_fl(const char *file, int line, const char **argv,
215
+ const char *format, ...)
216
+{
217
+ va_list ap;
218
+ va_start(ap, format);
219
+ trace_argv_vprintf_fl(file, line, argv, format, ap);
220
+ va_end(ap);
221
+}
222
+
223
+#endif /* HAVE_VARIADIC_MACROS */
224
+
225
+
226
static const char *quote_crnl(const char *path)
227
{
228
static char new_path[PATH_MAX];