Skip to content

Commit dca48cf

Browse files
martinvonzgitster
authored andcommitted
reset.c: remove unnecessary variable 'i'
Throughout most of parse_args(), the variable 'i' remains at 0. Many references are still made to the variable even when it could only have the value 0. This made at least me, who has relatively little experience with C programming styles, think that parts of the function was meant to be part of a loop. To avoid such confusion, remove the variable and also the 'argc' parameter and check for NULL trailing argv instead. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39ea722 commit dca48cf

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

builtin/reset.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ static void die_if_unmerged_cache(int reset_type)
198198

199199
}
200200

201-
static const char **parse_args(int argc, const char **argv, const char *prefix, const char **rev_ret)
201+
static const char **parse_args(const char **argv, const char *prefix, const char **rev_ret)
202202
{
203-
int i = 0;
204203
const char *rev = "HEAD";
205204
unsigned char unused[20];
206205
/*
@@ -211,34 +210,34 @@ static const char **parse_args(int argc, const char **argv, const char *prefix,
211210
* git reset [-opts] -- <paths>...
212211
* git reset [-opts] <paths>...
213212
*
214-
* At this point, argv[i] points immediately after [-opts].
213+
* At this point, argv points immediately after [-opts].
215214
*/
216215

217-
if (i < argc) {
218-
if (!strcmp(argv[i], "--")) {
219-
i++; /* reset to HEAD, possibly with paths */
220-
} else if (i + 1 < argc && !strcmp(argv[i+1], "--")) {
221-
rev = argv[i];
222-
i += 2;
216+
if (argv[0]) {
217+
if (!strcmp(argv[0], "--")) {
218+
argv++; /* reset to HEAD, possibly with paths */
219+
} else if (argv[1] && !strcmp(argv[1], "--")) {
220+
rev = argv[0];
221+
argv += 2;
223222
}
224223
/*
225-
* Otherwise, argv[i] could be either <rev> or <paths> and
224+
* Otherwise, argv[0] could be either <rev> or <paths> and
226225
* has to be unambiguous.
227226
*/
228-
else if (!get_sha1_committish(argv[i], unused)) {
227+
else if (!get_sha1_committish(argv[0], unused)) {
229228
/*
230-
* Ok, argv[i] looks like a rev; it should not
229+
* Ok, argv[0] looks like a rev; it should not
231230
* be a filename.
232231
*/
233-
verify_non_filename(prefix, argv[i]);
234-
rev = argv[i++];
232+
verify_non_filename(prefix, argv[0]);
233+
rev = *argv++;
235234
} else {
236235
/* Otherwise we treat this as a filename */
237-
verify_filename(prefix, argv[i], 1);
236+
verify_filename(prefix, argv[0], 1);
238237
}
239238
}
240239
*rev_ret = rev;
241-
return i < argc ? get_pathspec(prefix, argv + i) : NULL;
240+
return argv[0] ? get_pathspec(prefix, argv) : NULL;
242241
}
243242

244243
int cmd_reset(int argc, const char **argv, const char *prefix)
@@ -270,7 +269,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
270269

271270
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
272271
PARSE_OPT_KEEP_DASHDASH);
273-
pathspec = parse_args(argc, argv, prefix, &rev);
272+
pathspec = parse_args(argv, prefix, &rev);
274273

275274
if (get_sha1_committish(rev, sha1))
276275
die(_("Failed to resolve '%s' as a valid ref."), rev);

0 commit comments

Comments
 (0)