Skip to content

Commit 2438294

Browse files
committed
patch-id: make get_one_patchid() more extensible
We pass two independent Boolean flags (i.e. do we want the stable variant of patch-id? do we want to hash the stuff verbatim?) into the function as two separate parameters. Before adding the third one and make the interface even wider, let's consolidate them into a single flag word. No changes in behaviour. Just a trivial interface change. Signed-off-by: Junio C Hamano <[email protected]>
1 parent c92f319 commit 2438294

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

builtin/patch-id.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
5858
return 1;
5959
}
6060

61+
/*
62+
* flag bits to control get_one_patchid()'s behaviour.
63+
*/
64+
enum {
65+
GOPID_STABLE = (1<<0), /* --stable */
66+
GOPID_VERBATIM = (1<<1), /* --verbatim */
67+
};
68+
6169
static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
62-
struct strbuf *line_buf, int stable, int verbatim)
70+
struct strbuf *line_buf, unsigned flags)
6371
{
72+
int stable = flags & GOPID_STABLE;
73+
int verbatim = flags & GOPID_VERBATIM;
6474
int patchlen = 0, found_next = 0;
6575
int before = -1, after = -1;
6676
int diff_is_binary = 0;
@@ -171,15 +181,15 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
171181
return patchlen;
172182
}
173183

174-
static void generate_id_list(int stable, int verbatim)
184+
static void generate_id_list(unsigned flags)
175185
{
176186
struct object_id oid, n, result;
177187
int patchlen;
178188
struct strbuf line_buf = STRBUF_INIT;
179189

180190
oidclr(&oid);
181191
while (!feof(stdin)) {
182-
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
192+
patchlen = get_one_patchid(&n, &result, &line_buf, flags);
183193
if (patchlen)
184194
flush_current_id(&oid, &result);
185195
oidcpy(&oid, &n);
@@ -218,6 +228,7 @@ int cmd_patch_id(int argc, const char **argv, const char *prefix)
218228
/* if nothing is set, default to unstable */
219229
struct patch_id_opts config = {0, 0};
220230
int opts = 0;
231+
unsigned flags = 0;
221232
struct option builtin_patch_id_options[] = {
222233
OPT_CMDMODE(0, "unstable", &opts,
223234
N_("use the unstable patch-id algorithm"), 1),
@@ -237,7 +248,11 @@ int cmd_patch_id(int argc, const char **argv, const char *prefix)
237248
argc = parse_options(argc, argv, prefix, builtin_patch_id_options,
238249
patch_id_usage, 0);
239250

240-
generate_id_list(opts ? opts > 1 : config.stable,
241-
opts ? opts == 3 : config.verbatim);
251+
if (opts ? opts > 1 : config.stable)
252+
flags |= GOPID_STABLE;
253+
if (opts ? opts == 3 : config.verbatim)
254+
flags |= GOPID_VERBATIM;
255+
generate_id_list(flags);
256+
242257
return 0;
243258
}

0 commit comments

Comments
 (0)