From f8ba655ee4131e5c73c28a4ea854b24ce4058e1e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 7 May 2006 21:27:30 -0700 Subject: Fix repo-config set-multivar error return path. This hopefully fixes the problem an earlier commit 5d8ee9ceb attemted to fix. Signed-off-by: Junio C Hamano --- config.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index 11d65f8c70..adb5ce476a 100644 --- a/config.c +++ b/config.c @@ -420,7 +420,7 @@ int git_config_set_multivar(const char* key, const char* value, const char* value_regex, int multi_replace) { int i; - int fd, in_fd; + int fd = -1, in_fd; int ret; char* config_filename = strdup(git_path("config")); char* lock_file = strdup(git_path("config.lock")); @@ -478,15 +478,11 @@ int git_config_set_multivar(const char* key, const char* value, if ( ENOENT != errno ) { error("opening %s: %s", config_filename, strerror(errno)); - close(fd); - unlink(lock_file); ret = 3; /* same as "invalid config file" */ goto out_free; } /* if nothing to unset, error out */ if (value == NULL) { - close(fd); - unlink(lock_file); ret = 5; goto out_free; } @@ -514,8 +510,6 @@ int git_config_set_multivar(const char* key, const char* value, fprintf(stderr, "Invalid pattern: %s\n", value_regex); free(store.value_regex); - close(fd); - unlink(lock_file); ret = 6; goto out_free; } @@ -551,8 +545,6 @@ int git_config_set_multivar(const char* key, const char* value, /* if nothing to unset, or too many matches, error out */ if ((store.seen == 0 && value == NULL) || (store.seen > 1 && multi_replace == 0)) { - close(fd); - unlink(lock_file); ret = 5; goto out_free; } @@ -601,8 +593,6 @@ int git_config_set_multivar(const char* key, const char* value, unlink(config_filename); } - close(fd); - if (rename(lock_file, config_filename) < 0) { fprintf(stderr, "Could not rename the lock file?\n"); ret = 4; @@ -612,10 +602,14 @@ int git_config_set_multivar(const char* key, const char* value, ret = 0; out_free: + if (0 <= fd) + close(fd); if (config_filename) free(config_filename); - if (lock_file) + if (lock_file) { + unlink(lock_file); free(lock_file); + } return ret; } -- cgit v1.2.3 From 5d6a9f45e1ba78693cb0fbd5e9724b05d4e30e37 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 8 May 2006 09:46:53 -0700 Subject: Fix "git diff --stat" with long filenames When we cut off the front of a filename to make it fit on the line, we add a "..." in front. However, the way the "git diff" code was written, we will never reset the prefix back to the empty string, so every single filename afterwards will have the "..." prefix, whether appropriate or not. You can see this with "git diff v2.6.16.." on the current kernel tree, since there are filenames with long names that changed there: [ snip snip ] Documentation/filesystems/vfs.txt | 229 .../firmware_class/firmware_sample_driver.c | 3 .../firmware_sample_firmware_class.c | 1 ...Documentation/fujitsu/frv/kernel-ABI.txt | 192 ...Documentation/hwmon/w83627hf | 4 [ snip snip ] notice how the two Documentation/firmware** filenames caused the "..." to be added, but then the later filenames don't want it, and it also screws up the alignment of the line numbering afterwards. Trivially fixed by moving the declaration (and initial setting) of the "prefix" variable into the for-loop where it is used. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 903afa1689..afaa648dbb 100644 --- a/diff.c +++ b/diff.c @@ -239,7 +239,6 @@ static const char minuses[]= "-------------------------------------------------- static void show_stats(struct diffstat_t* data) { - char *prefix = ""; int i, len, add, del, total, adds = 0, dels = 0; int max, max_change = 0, max_len = 0; int total_files = data->nr; @@ -261,6 +260,7 @@ static void show_stats(struct diffstat_t* data) } for (i = 0; i < data->nr; i++) { + char *prefix = ""; char *name = data->files[i]->name; int added = data->files[i]->added; int deleted = data->files[i]->deleted; -- cgit v1.2.3 From afb4ff206967c6b3e481994cc6d0d86139792169 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 8 May 2006 13:46:53 -0700 Subject: Documentation: {caret} fixes (git-rev-list.txt) Signed-off-by: Junio C Hamano --- Documentation/git-rev-list.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt index 8255ae1bce..ad6d14c55a 100644 --- a/Documentation/git-rev-list.txt +++ b/Documentation/git-rev-list.txt @@ -68,9 +68,10 @@ OPTIONS --bisect:: Limit output to the one commit object which is roughly halfway between the included and excluded commits. Thus, if 'git-rev-list - --bisect foo ^bar ^baz' outputs 'midpoint', the output - of 'git-rev-list foo ^midpoint' and 'git-rev-list midpoint - ^bar ^baz' would be of roughly the same length. Finding the change + --bisect foo {caret}bar {caret}baz' outputs 'midpoint', the output + of 'git-rev-list foo {caret}midpoint' and 'git-rev-list midpoint + {caret}bar {caret}baz' would be of roughly the same length. + Finding the change which introduces a regression is thus reduced to a binary search: repeatedly generate and test new 'midpoint's until the commit chain is of length one. -- cgit v1.2.3 From 31fff305bcc6db3b8082eac7fc9e441b27964fea Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 9 May 2006 01:43:38 +0400 Subject: Separate object name errors from usage errors Separate object name errors from usage errors. Signed-off-by: Dmitry V. Levin Signed-off-by: Junio C Hamano --- cat-file.c | 7 ++++--- commit-tree.c | 8 ++++++-- convert-objects.c | 4 +++- describe.c | 6 +++--- ls-tree.c | 4 ++-- merge-base.c | 8 +++++--- merge-tree.c | 2 +- read-tree.c | 4 ++-- revision.c | 4 ++-- ssh-upload.c | 2 +- tar-tree.c | 4 ++-- unpack-file.c | 4 +++- update-ref.c | 4 ++-- 13 files changed, 36 insertions(+), 25 deletions(-) diff --git a/cat-file.c b/cat-file.c index 628f6cada8..7413feed78 100644 --- a/cat-file.c +++ b/cat-file.c @@ -103,8 +103,10 @@ int main(int argc, char **argv) setup_git_directory(); git_config(git_default_config); - if (argc != 3 || get_sha1(argv[2], sha1)) + if (argc != 3) usage("git-cat-file [-t|-s|-e|-p|] "); + if (get_sha1(argv[2], sha1)) + die("Not a valid object name %s", argv[2]); opt = 0; if ( argv[1][0] == '-' ) { @@ -133,8 +135,7 @@ int main(int argc, char **argv) return !has_sha1_file(sha1); case 'p': - if (get_sha1(argv[2], sha1) || - sha1_object_info(sha1, type, NULL)) + if (sha1_object_info(sha1, type, NULL)) die("Not a valid object name %s", argv[2]); /* custom pretty-print here */ diff --git a/commit-tree.c b/commit-tree.c index 2595850970..0320036e80 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -91,15 +91,19 @@ int main(int argc, char **argv) git_config(git_default_config); - if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0) + if (argc < 2) usage(commit_tree_usage); + if (get_sha1(argv[1], tree_sha1)) + die("Not a valid object name %s", argv[1]); check_valid(tree_sha1, tree_type); for (i = 2; i < argc; i += 2) { char *a, *b; a = argv[i]; b = argv[i+1]; - if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents])) + if (!b || strcmp(a, "-p")) usage(commit_tree_usage); + if (get_sha1(b, parent_sha1[parents])) + die("Not a valid object name %s", b); check_valid(parent_sha1[parents], commit_type); if (new_parent(parents)) parents++; diff --git a/convert-objects.c b/convert-objects.c index 12aacef5a9..a67d6b479e 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -321,8 +321,10 @@ int main(int argc, char **argv) setup_git_directory(); - if (argc != 2 || get_sha1(argv[1], sha1)) + if (argc != 2) usage("git-convert-objects "); + if (get_sha1(argv[1], sha1)) + die("Not a valid object name %s", argv[1]); entry = convert_entry(sha1); printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1)); diff --git a/describe.c b/describe.c index ff65742615..8a9cd5d52c 100644 --- a/describe.c +++ b/describe.c @@ -105,11 +105,11 @@ static void describe(char *arg, int last_one) static int initialized = 0; struct commit_name *n; - if (get_sha1(arg, sha1) < 0) - usage(describe_usage); + if (get_sha1(arg, sha1)) + die("Not a valid object name %s", arg); cmit = lookup_commit_reference(sha1); if (!cmit) - usage(describe_usage); + die("%s is not a valid '%s' object", arg, commit_type); if (!initialized) { initialized = 1; diff --git a/ls-tree.c b/ls-tree.c index e4ef200985..f2b3bc1231 100644 --- a/ls-tree.c +++ b/ls-tree.c @@ -142,8 +142,8 @@ int main(int argc, const char **argv) if (argc < 2) usage(ls_tree_usage); - if (get_sha1(argv[1], sha1) < 0) - usage(ls_tree_usage); + if (get_sha1(argv[1], sha1)) + die("Not a valid object name %s", argv[1]); pathspec = get_pathspec(prefix, argv + 2); tree = parse_tree_indirect(sha1); diff --git a/merge-base.c b/merge-base.c index 07f5ab4d1c..f0dc06ef55 100644 --- a/merge-base.c +++ b/merge-base.c @@ -247,10 +247,12 @@ int main(int argc, char **argv) usage(merge_base_usage); argc--; argv++; } - if (argc != 3 || - get_sha1(argv[1], rev1key) || - get_sha1(argv[2], rev2key)) + if (argc != 3) usage(merge_base_usage); + if (get_sha1(argv[1], rev1key)) + die("Not a valid object name %s", argv[1]); + if (get_sha1(argv[2], rev2key)) + die("Not a valid object name %s", argv[2]); rev1 = lookup_commit_reference(rev1key); rev2 = lookup_commit_reference(rev2key); if (!rev1 || !rev2) diff --git a/merge-tree.c b/merge-tree.c index 50528d5e43..47181d422c 100644 --- a/merge-tree.c +++ b/merge-tree.c @@ -151,7 +151,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev) unsigned char sha1[20]; void *buf; - if (get_sha1(rev, sha1) < 0) + if (get_sha1(rev, sha1)) die("unknown rev %s", rev); buf = fill_tree_descriptor(desc, sha1); if (!buf) diff --git a/read-tree.c b/read-tree.c index 26f4f7e323..e926e4c880 100644 --- a/read-tree.c +++ b/read-tree.c @@ -794,8 +794,8 @@ int main(int argc, char **argv) if (1 < index_only + update) usage(read_tree_usage); - if (get_sha1(arg, sha1) < 0) - usage(read_tree_usage); + if (get_sha1(arg, sha1)) + die("Not a valid object name %s", arg); if (list_tree(sha1) < 0) die("failed to unpack tree object %s", arg); stage++; diff --git a/revision.c b/revision.c index 5f2f0be382..d41e59b9cc 100644 --- a/revision.c +++ b/revision.c @@ -674,7 +674,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch local_flags = UNINTERESTING; arg++; } - if (get_sha1(arg, sha1) < 0) { + if (get_sha1(arg, sha1)) { int j; if (seen_dashdash || local_flags) @@ -693,7 +693,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch if (def && !revs->commits) { unsigned char sha1[20]; struct commit *commit; - if (get_sha1(def, sha1) < 0) + if (get_sha1(def, sha1)) die("bad default revision '%s'", def); commit = get_commit_reference(revs, def, sha1, 0); add_one_commit(commit, revs); diff --git a/ssh-upload.c b/ssh-upload.c index b675a0b1f1..2da66618fc 100644 --- a/ssh-upload.c +++ b/ssh-upload.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) commit_id = argv[arg]; url = argv[arg + 1]; if (get_sha1(commit_id, sha1)) - usage(ssh_push_usage); + die("Not a valid object name %s", commit_id); memcpy(hex, sha1_to_hex(sha1), sizeof(hex)); argv[arg] = hex; diff --git a/tar-tree.c b/tar-tree.c index fc60a90873..33087366c3 100644 --- a/tar-tree.c +++ b/tar-tree.c @@ -321,8 +321,8 @@ int main(int argc, char **argv) strbuf_append_string(¤t_path, "/"); /* FALLTHROUGH */ case 2: - if (get_sha1(argv[1], sha1) < 0) - usage(tar_tree_usage); + if (get_sha1(argv[1], sha1)) + die("Not a valid object name %s", argv[1]); break; default: usage(tar_tree_usage); diff --git a/unpack-file.c b/unpack-file.c index 23a8562301..ccddf1d4b0 100644 --- a/unpack-file.c +++ b/unpack-file.c @@ -27,8 +27,10 @@ int main(int argc, char **argv) { unsigned char sha1[20]; - if (argc != 2 || get_sha1(argv[1], sha1)) + if (argc != 2) usage("git-unpack-file "); + if (get_sha1(argv[1], sha1)) + die("Not a valid object name %s", argv[1]); setup_git_directory(); git_config(git_default_config); diff --git a/update-ref.c b/update-ref.c index ba4bf5153e..fd487421cd 100644 --- a/update-ref.c +++ b/update-ref.c @@ -32,10 +32,10 @@ int main(int argc, char **argv) refname = argv[1]; value = argv[2]; oldval = argv[3]; - if (get_sha1(value, sha1) < 0) + if (get_sha1(value, sha1)) die("%s: not a valid SHA1", value); memset(oldsha1, 0, 20); - if (oldval && get_sha1(oldval, oldsha1) < 0) + if (oldval && get_sha1(oldval, oldsha1)) die("%s: not a valid old SHA1", oldval); path = resolve_ref(git_path("%s", refname), currsha1, !!oldval); -- cgit v1.2.3