Skip to content

Commit 7c37c97

Browse files
committed
quote: turn 'nodq' parameter into a set of flags
quote_c_style() and its friend quote_two_c_style() both take an optional "please omit the double quotes around the quoted body" parameter. Turn it into a flag word, assign one bit out of it, and call it CQUOTE_NODQ bit. No behaviour change intended. Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfc7f65 commit 7c37c97

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

diff.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
482482

483483
static char *quote_two(const char *one, const char *two)
484484
{
485-
int need_one = quote_c_style(one, NULL, NULL, 1);
486-
int need_two = quote_c_style(two, NULL, NULL, 1);
485+
int need_one = quote_c_style(one, NULL, NULL, CQUOTE_NODQ);
486+
int need_two = quote_c_style(two, NULL, NULL, CQUOTE_NODQ);
487487
struct strbuf res = STRBUF_INIT;
488488

489489
if (need_one + need_two) {
490490
strbuf_addch(&res, '"');
491-
quote_c_style(one, &res, NULL, 1);
492-
quote_c_style(two, &res, NULL, 1);
491+
quote_c_style(one, &res, NULL, CQUOTE_NODQ);
492+
quote_c_style(two, &res, NULL, CQUOTE_NODQ);
493493
strbuf_addch(&res, '"');
494494
} else {
495495
strbuf_addstr(&res, one);

quote.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static size_t next_quote_pos(const char *s, ssize_t maxlen)
256256
* Return value is the same as in (1).
257257
*/
258258
static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
259-
struct strbuf *sb, FILE *fp, int no_dq)
259+
struct strbuf *sb, FILE *fp, unsigned flags)
260260
{
261261
#undef EMIT
262262
#define EMIT(c) \
@@ -272,6 +272,7 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
272272
count += (l); \
273273
} while (0)
274274

275+
int no_dq = !!(flags & CQUOTE_NODQ);
275276
size_t len, count = 0;
276277
const char *p = name;
277278

@@ -309,19 +310,21 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
309310
return count;
310311
}
311312

312-
size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq)
313+
size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, unsigned flags)
313314
{
314-
return quote_c_style_counted(name, -1, sb, fp, nodq);
315+
return quote_c_style_counted(name, -1, sb, fp, flags);
315316
}
316317

317-
void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq)
318+
void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path,
319+
unsigned flags)
318320
{
321+
int nodq = !!(flags & CQUOTE_NODQ);
319322
if (quote_c_style(prefix, NULL, NULL, 0) ||
320323
quote_c_style(path, NULL, NULL, 0)) {
321324
if (!nodq)
322325
strbuf_addch(sb, '"');
323-
quote_c_style(prefix, sb, NULL, 1);
324-
quote_c_style(path, sb, NULL, 1);
326+
quote_c_style(prefix, sb, NULL, CQUOTE_NODQ);
327+
quote_c_style(path, sb, NULL, CQUOTE_NODQ);
325328
if (!nodq)
326329
strbuf_addch(sb, '"');
327330
} else {
@@ -367,7 +370,8 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne
367370
*/
368371
if (force_dq)
369372
strbuf_addch(out, '"');
370-
quote_c_style_counted(rel, strlen(rel), out, NULL, force_dq);
373+
quote_c_style_counted(rel, strlen(rel), out, NULL,
374+
force_dq ? CQUOTE_NODQ : 0);
371375
if (force_dq)
372376
strbuf_addch(out, '"');
373377
strbuf_release(&sb);

quote.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ struct strvec;
6464
int sq_dequote_to_strvec(char *arg, struct strvec *);
6565

6666
int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
67-
size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);
68-
void quote_two_c_style(struct strbuf *, const char *, const char *, int);
67+
68+
/* Bits in the flags parameter to quote_c_style() */
69+
#define CQUOTE_NODQ 01
70+
size_t quote_c_style(const char *name, struct strbuf *, FILE *, unsigned);
71+
void quote_two_c_style(struct strbuf *, const char *, const char *, unsigned);
6972

7073
void write_name_quoted(const char *name, FILE *, int terminator);
7174
void write_name_quoted_relative(const char *name, const char *prefix,

0 commit comments

Comments
 (0)