Skip to content

Commit aad90e8

Browse files
tgummerergitster
authored andcommitted
diff: avoid some nesting
Avoid some nesting in builtin/diff.c, to make the code easier to read. There are no functional changes. Helped-by: Jonathan Nieder <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a19dfa commit aad90e8

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

builtin/diff.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,27 +319,26 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
319319

320320
init_revisions(&rev, prefix);
321321

322-
if (no_index) {
323-
if (argc != i + 2) {
324-
if (no_index == DIFF_NO_INDEX_IMPLICIT) {
325-
/*
326-
* There was no --no-index and there were not two
327-
* paths. It is possible that the user intended
328-
* to do an inside-repository operation.
329-
*/
330-
fprintf(stderr, "Not a git repository\n");
331-
fprintf(stderr,
332-
"To compare two paths outside a working tree:\n");
333-
}
334-
/* Give the usage message for non-repository usage and exit. */
335-
usagef("git diff %s <path> <path>",
336-
no_index == DIFF_NO_INDEX_EXPLICIT ?
337-
"--no-index" : "[--no-index]");
338-
322+
if (no_index && argc != i + 2) {
323+
if (no_index == DIFF_NO_INDEX_IMPLICIT) {
324+
/*
325+
* There was no --no-index and there were not two
326+
* paths. It is possible that the user intended
327+
* to do an inside-repository operation.
328+
*/
329+
fprintf(stderr, "Not a git repository\n");
330+
fprintf(stderr,
331+
"To compare two paths outside a working tree:\n");
339332
}
333+
/* Give the usage message for non-repository usage and exit. */
334+
usagef("git diff %s <path> <path>",
335+
no_index == DIFF_NO_INDEX_EXPLICIT ?
336+
"--no-index" : "[--no-index]");
337+
338+
}
339+
if (no_index)
340340
/* If this is a no-index diff, just run it and exit there. */
341341
diff_no_index(&rev, argc, argv, prefix);
342-
}
343342

344343
/* Otherwise, we are doing the usual "git" diff */
345344
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;

0 commit comments

Comments
 (0)