Skip to content

Commit 45f75a0

Browse files
author
Junio C Hamano
committed
Merge branch 'fix'
* fix: Separate object name errors from usage errors Documentation: {caret} fixes (git-rev-list.txt) Fix "git diff --stat" with long filenames Fix repo-config set-multivar error return path.
2 parents fd60aca + 31fff30 commit 45f75a0

File tree

16 files changed

+47
-41
lines changed

16 files changed

+47
-41
lines changed

Documentation/git-rev-list.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ OPTIONS
6868
--bisect::
6969
Limit output to the one commit object which is roughly halfway
7070
between the included and excluded commits. Thus, if 'git-rev-list
71-
--bisect foo ^bar ^baz' outputs 'midpoint', the output
72-
of 'git-rev-list foo ^midpoint' and 'git-rev-list midpoint
73-
^bar ^baz' would be of roughly the same length. Finding the change
71+
--bisect foo {caret}bar {caret}baz' outputs 'midpoint', the output
72+
of 'git-rev-list foo {caret}midpoint' and 'git-rev-list midpoint
73+
{caret}bar {caret}baz' would be of roughly the same length.
74+
Finding the change
7475
which introduces a regression is thus reduced to a binary search:
7576
repeatedly generate and test new 'midpoint's until the commit chain
7677
is of length one.

cat-file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ int main(int argc, char **argv)
103103

104104
setup_git_directory();
105105
git_config(git_default_config);
106-
if (argc != 3 || get_sha1(argv[2], sha1))
106+
if (argc != 3)
107107
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
108+
if (get_sha1(argv[2], sha1))
109+
die("Not a valid object name %s", argv[2]);
108110

109111
opt = 0;
110112
if ( argv[1][0] == '-' ) {
@@ -133,8 +135,7 @@ int main(int argc, char **argv)
133135
return !has_sha1_file(sha1);
134136

135137
case 'p':
136-
if (get_sha1(argv[2], sha1) ||
137-
sha1_object_info(sha1, type, NULL))
138+
if (sha1_object_info(sha1, type, NULL))
138139
die("Not a valid object name %s", argv[2]);
139140

140141
/* custom pretty-print here */

commit-tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,19 @@ int main(int argc, char **argv)
9191

9292
git_config(git_default_config);
9393

94-
if (argc < 2 || get_sha1(argv[1], tree_sha1) < 0)
94+
if (argc < 2)
9595
usage(commit_tree_usage);
96+
if (get_sha1(argv[1], tree_sha1))
97+
die("Not a valid object name %s", argv[1]);
9698

9799
check_valid(tree_sha1, tree_type);
98100
for (i = 2; i < argc; i += 2) {
99101
char *a, *b;
100102
a = argv[i]; b = argv[i+1];
101-
if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
103+
if (!b || strcmp(a, "-p"))
102104
usage(commit_tree_usage);
105+
if (get_sha1(b, parent_sha1[parents]))
106+
die("Not a valid object name %s", b);
103107
check_valid(parent_sha1[parents], commit_type);
104108
if (new_parent(parents))
105109
parents++;

config.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ int git_config_set_multivar(const char* key, const char* value,
422422
const char* value_regex, int multi_replace)
423423
{
424424
int i;
425-
int fd, in_fd;
425+
int fd = -1, in_fd;
426426
int ret;
427427
char* config_filename = strdup(git_path("config"));
428428
char* lock_file = strdup(git_path("config.lock"));
@@ -480,15 +480,11 @@ int git_config_set_multivar(const char* key, const char* value,
480480
if ( ENOENT != errno ) {
481481
error("opening %s: %s", config_filename,
482482
strerror(errno));
483-
close(fd);
484-
unlink(lock_file);
485483
ret = 3; /* same as "invalid config file" */
486484
goto out_free;
487485
}
488486
/* if nothing to unset, error out */
489487
if (value == NULL) {
490-
close(fd);
491-
unlink(lock_file);
492488
ret = 5;
493489
goto out_free;
494490
}
@@ -516,8 +512,6 @@ int git_config_set_multivar(const char* key, const char* value,
516512
fprintf(stderr, "Invalid pattern: %s\n",
517513
value_regex);
518514
free(store.value_regex);
519-
close(fd);
520-
unlink(lock_file);
521515
ret = 6;
522516
goto out_free;
523517
}
@@ -553,8 +547,6 @@ int git_config_set_multivar(const char* key, const char* value,
553547
/* if nothing to unset, or too many matches, error out */
554548
if ((store.seen == 0 && value == NULL) ||
555549
(store.seen > 1 && multi_replace == 0)) {
556-
close(fd);
557-
unlink(lock_file);
558550
ret = 5;
559551
goto out_free;
560552
}
@@ -603,8 +595,6 @@ int git_config_set_multivar(const char* key, const char* value,
603595
unlink(config_filename);
604596
}
605597

606-
close(fd);
607-
608598
if (rename(lock_file, config_filename) < 0) {
609599
fprintf(stderr, "Could not rename the lock file?\n");
610600
ret = 4;
@@ -614,10 +604,14 @@ int git_config_set_multivar(const char* key, const char* value,
614604
ret = 0;
615605

616606
out_free:
607+
if (0 <= fd)
608+
close(fd);
617609
if (config_filename)
618610
free(config_filename);
619-
if (lock_file)
611+
if (lock_file) {
612+
unlink(lock_file);
620613
free(lock_file);
614+
}
621615
return ret;
622616
}
623617

convert-objects.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ int main(int argc, char **argv)
321321

322322
setup_git_directory();
323323

324-
if (argc != 2 || get_sha1(argv[1], sha1))
324+
if (argc != 2)
325325
usage("git-convert-objects <sha1>");
326+
if (get_sha1(argv[1], sha1))
327+
die("Not a valid object name %s", argv[1]);
326328

327329
entry = convert_entry(sha1);
328330
printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));

describe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ static void describe(char *arg, int last_one)
105105
static int initialized = 0;
106106
struct commit_name *n;
107107

108-
if (get_sha1(arg, sha1) < 0)
109-
usage(describe_usage);
108+
if (get_sha1(arg, sha1))
109+
die("Not a valid object name %s", arg);
110110
cmit = lookup_commit_reference(sha1);
111111
if (!cmit)
112-
usage(describe_usage);
112+
die("%s is not a valid '%s' object", arg, commit_type);
113113

114114
if (!initialized) {
115115
initialized = 1;

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ static const char minuses[]= "--------------------------------------------------
296296

297297
static void show_stats(struct diffstat_t* data)
298298
{
299-
char *prefix = "";
300299
int i, len, add, del, total, adds = 0, dels = 0;
301300
int max, max_change = 0, max_len = 0;
302301
int total_files = data->nr;
@@ -318,6 +317,7 @@ static void show_stats(struct diffstat_t* data)
318317
}
319318

320319
for (i = 0; i < data->nr; i++) {
320+
char *prefix = "";
321321
char *name = data->files[i]->name;
322322
int added = data->files[i]->added;
323323
int deleted = data->files[i]->deleted;

ls-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ int main(int argc, const char **argv)
142142

143143
if (argc < 2)
144144
usage(ls_tree_usage);
145-
if (get_sha1(argv[1], sha1) < 0)
146-
usage(ls_tree_usage);
145+
if (get_sha1(argv[1], sha1))
146+
die("Not a valid object name %s", argv[1]);
147147

148148
pathspec = get_pathspec(prefix, argv + 2);
149149
tree = parse_tree_indirect(sha1);

merge-base.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ int main(int argc, char **argv)
247247
usage(merge_base_usage);
248248
argc--; argv++;
249249
}
250-
if (argc != 3 ||
251-
get_sha1(argv[1], rev1key) ||
252-
get_sha1(argv[2], rev2key))
250+
if (argc != 3)
253251
usage(merge_base_usage);
252+
if (get_sha1(argv[1], rev1key))
253+
die("Not a valid object name %s", argv[1]);
254+
if (get_sha1(argv[2], rev2key))
255+
die("Not a valid object name %s", argv[2]);
254256
rev1 = lookup_commit_reference(rev1key);
255257
rev2 = lookup_commit_reference(rev2key);
256258
if (!rev1 || !rev2)

merge-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
149149
unsigned char sha1[20];
150150
void *buf;
151151

152-
if (get_sha1(rev, sha1) < 0)
152+
if (get_sha1(rev, sha1))
153153
die("unknown rev %s", rev);
154154
buf = fill_tree_descriptor(desc, sha1);
155155
if (!buf)

0 commit comments

Comments
 (0)