summaryrefslogtreecommitdiffstats
path: root/src/diff.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-12-26 12:50:04 +0000
committerBram Moolenaar <Bram@vim.org>2022-12-26 12:50:04 +0000
commit465de3a57b815f1188c707e7c083950c81652536 (patch)
tree6a1e8783bb5f269282668c258f0b893bd961a888 /src/diff.c
parentb3d614369fceb891819badc941f80f08f57831f9 (diff)
patch 9.0.1098: code uses too much indentv9.0.1098
Problem: Code uses too much indent. Solution: Use an early return. (Yegappan Lakshmanan, closes #11747)
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c104
1 files changed, 50 insertions, 54 deletions
diff --git a/src/diff.c b/src/diff.c
index 88e3ec4533..41cfefe5e6 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1180,44 +1180,40 @@ diff_file(diffio_T *dio)
#endif
// Use xdiff for generating the diff.
if (dio->dio_internal)
- {
return diff_file_internal(dio);
- }
- else
- {
- len = STRLEN(tmp_orig) + STRLEN(tmp_new)
- + STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
- cmd = alloc(len);
- if (cmd == NULL)
- return FAIL;
- // We don't want $DIFF_OPTIONS to get in the way.
- if (getenv("DIFF_OPTIONS"))
- vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
+ len = STRLEN(tmp_orig) + STRLEN(tmp_new)
+ + STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
+ cmd = alloc(len);
+ if (cmd == NULL)
+ return FAIL;
+
+ // We don't want $DIFF_OPTIONS to get in the way.
+ if (getenv("DIFF_OPTIONS"))
+ vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
- // Build the diff command and execute it. Always use -a, binary
- // differences are of no use. Ignore errors, diff returns
- // non-zero when differences have been found.
- vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
- diff_a_works == FALSE ? "" : "-a ",
+ // Build the diff command and execute it. Always use -a, binary
+ // differences are of no use. Ignore errors, diff returns
+ // non-zero when differences have been found.
+ vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
+ diff_a_works == FALSE ? "" : "-a ",
#if defined(MSWIN)
- diff_bin_works == TRUE ? "--binary " : "",
+ diff_bin_works == TRUE ? "--binary " : "",
#else
- "",
+ "",
#endif
- (diff_flags & DIFF_IWHITE) ? "-b " : "",
- (diff_flags & DIFF_IWHITEALL) ? "-w " : "",
- (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
- (diff_flags & DIFF_IBLANK) ? "-B " : "",
- (diff_flags & DIFF_ICASE) ? "-i " : "",
- tmp_orig, tmp_new);
- append_redir(cmd, (int)len, p_srr, tmp_diff);
- block_autocmds(); // avoid ShellCmdPost stuff
- (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
- unblock_autocmds();
- vim_free(cmd);
- return OK;
- }
+ (diff_flags & DIFF_IWHITE) ? "-b " : "",
+ (diff_flags & DIFF_IWHITEALL) ? "-w " : "",
+ (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
+ (diff_flags & DIFF_IBLANK) ? "-B " : "",
+ (diff_flags & DIFF_ICASE) ? "-i " : "",
+ tmp_orig, tmp_new);
+ append_redir(cmd, (int)len, p_srr, tmp_diff);
+ block_autocmds(); // avoid ShellCmdPost stuff
+ (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
+ unblock_autocmds();
+ vim_free(cmd);
+ return OK;
}
/*
@@ -1432,31 +1428,31 @@ ex_diffsplit(exarg_T *eap)
// don't use a new tab page, each tab page has its own diffs
cmdmod.cmod_tab = 0;
- if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL)
- {
- // Pretend it was a ":split fname" command
- eap->cmdidx = CMD_split;
- curwin->w_p_diff = TRUE;
- do_exedit(eap, old_curwin);
+ if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL)
+ return;
- if (curwin != old_curwin) // split must have worked
- {
- // Set 'diff', 'scrollbind' on and 'wrap' off.
- diff_win_options(curwin, TRUE);
- if (win_valid(old_curwin))
- {
- diff_win_options(old_curwin, TRUE);
+ // Pretend it was a ":split fname" command
+ eap->cmdidx = CMD_split;
+ curwin->w_p_diff = TRUE;
+ do_exedit(eap, old_curwin);
- if (bufref_valid(&old_curbuf))
- // Move the cursor position to that of the old window.
- curwin->w_cursor.lnum = diff_get_corresponding_line(
- old_curbuf.br_buf, old_curwin->w_cursor.lnum);
- }
- // Now that lines are folded scroll to show the cursor at the same
- // relative position.
- scroll_to_fraction(curwin, curwin->w_height);
- }
+ if (curwin == old_curwin) // split didn't work
+ return;
+
+ // Set 'diff', 'scrollbind' on and 'wrap' off.
+ diff_win_options(curwin, TRUE);
+ if (win_valid(old_curwin))
+ {
+ diff_win_options(old_curwin, TRUE);
+
+ if (bufref_valid(&old_curbuf))
+ // Move the cursor position to that of the old window.
+ curwin->w_cursor.lnum = diff_get_corresponding_line(
+ old_curbuf.br_buf, old_curwin->w_cursor.lnum);
}
+ // Now that lines are folded scroll to show the cursor at the same
+ // relative position.
+ scroll_to_fraction(curwin, curwin->w_height);
}
/*