Skip to content

Commit 22ddc4b

Browse files
committed
Merge branch 'jc/no-cmd-as-subroutine'
Calling cmd_foo() as if it is a general purpose helper function is a no-no. Correct two instances of such to set an example. * jc/no-cmd-as-subroutine: merge-ours: do not use cmd_*() as a subroutine describe: do not use cmd_*() as a subroutine
2 parents 0b646bc + a92b109 commit 22ddc4b

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

builtin/describe.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "builtin.h"
88
#include "exec_cmd.h"
99
#include "parse-options.h"
10+
#include "revision.h"
1011
#include "diff.h"
1112
#include "hashmap.h"
1213
#include "argv-array.h"
1314
#include "run-command.h"
1415

15-
#define SEEN (1u << 0)
1616
#define MAX_TAGS (FLAG_BITS - 1)
1717

1818
static const char * const describe_usage[] = {
@@ -543,7 +543,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
543543
}
544544
} else if (dirty) {
545545
static struct lock_file index_lock;
546-
int fd;
546+
struct rev_info revs;
547+
struct argv_array args = ARGV_ARRAY_INIT;
548+
int fd, result;
547549

548550
read_cache_preload(NULL);
549551
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
@@ -552,8 +554,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
552554
if (0 <= fd)
553555
update_index_if_able(&the_index, &index_lock);
554556

555-
if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
556-
diff_index_args, prefix))
557+
init_revisions(&revs, prefix);
558+
argv_array_pushv(&args, diff_index_args);
559+
if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1)
560+
BUG("malformed internal diff-index command line");
561+
result = run_diff_index(&revs, 0);
562+
563+
if (!diff_result_code(&revs.diffopt, result))
557564
suffix = NULL;
558565
else
559566
suffix = dirty;

builtin/merge-ours.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@
99
*/
1010
#include "git-compat-util.h"
1111
#include "builtin.h"
12+
#include "diff.h"
1213

1314
static const char builtin_merge_ours_usage[] =
1415
"git merge-ours <base>... -- HEAD <remote>...";
1516

16-
static const char *diff_index_args[] = {
17-
"diff-index", "--quiet", "--cached", "HEAD", "--", NULL
18-
};
19-
#define NARGS (ARRAY_SIZE(diff_index_args) - 1)
20-
2117
int cmd_merge_ours(int argc, const char **argv, const char *prefix)
2218
{
2319
if (argc == 2 && !strcmp(argv[1], "-h"))
2420
usage(builtin_merge_ours_usage);
2521

2622
/*
27-
* We need to exit with 2 if the index does not match our HEAD tree,
28-
* because the current index is what we will be committing as the
29-
* merge result.
23+
* The contents of the current index becomes the tree we
24+
* commit. The index must match HEAD, or this merge cannot go
25+
* through.
3026
*/
31-
if (cmd_diff_index(NARGS, diff_index_args, prefix))
27+
if (read_cache() < 0)
28+
die_errno("read_cache failed");
29+
if (index_differs_from("HEAD", 0, 0))
3230
exit(2);
3331
exit(0);
3432
}

0 commit comments

Comments
 (0)