- const char *const diff_cmd = "diff -L%s -L%s";
- const char *const diff_arg = "-- %s %s||:"; /* "||:" is to return 0 */
- const char *input_name_sq[2];
- const char *label_path[2];
- char *cmd;
-
- /* diff_cmd and diff_arg have 4 %s in total which makes
- * the sum of these strings 8 bytes larger than required.
- * we use 2 spaces around diff-opts, and we need to count
- * terminating NUL; we used to subtract 5 here, but we do not
- * care about small leaks in this subprocess that is about
- * to exec "diff" anymore.
- */
- cmd_size = (strlen(diff_cmd) + strlen(diff_opts) + strlen(diff_arg)
- + 128);
-
- for (i = 0; i < 2; i++) {
- input_name_sq[i] = sq_quote(temp[i].name);
- if (!strcmp(temp[i].name, "/dev/null"))
- label_path[i] = "/dev/null";
- else if (!i)
- label_path[i] = sq_quote(quote_two("a/", name_a));
- else
- label_path[i] = sq_quote(quote_two("b/", name_b));
- cmd_size += (strlen(label_path[i]) + strlen(input_name_sq[i]));
- }
-
- cmd = xmalloc(cmd_size);
-
- next_at = 0;
- next_at += snprintf(cmd+next_at, cmd_size-next_at,
- diff_cmd, label_path[0], label_path[1]);
- next_at += snprintf(cmd+next_at, cmd_size-next_at,
- " %s ", diff_opts);
- next_at += snprintf(cmd+next_at, cmd_size-next_at,
- diff_arg, input_name_sq[0], input_name_sq[1]);
-
- printf("diff --git %s %s\n",
- quote_two("a/", name_a), quote_two("b/", name_b));
- if (label_path[0][0] == '/') {
- /* dev/null */
- printf("new file mode %s\n", temp[1].mode);
+ const char *lbl[2];
+ char *a_one, *b_two;
+
+ a_one = quote_two("a/", name_a);
+ b_two = quote_two("b/", name_b);
+ lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
+ lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
+ printf("diff --git %s %s\n", a_one, b_two);
+ if (lbl[0][0] == '/') {
+ /* /dev/null */
+ printf("new file mode %06o\n", two->mode);