From f4a11066cfb70c49fddbca7f95aa0fedcee53cca Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 21 Dec 2005 18:47:09 -0500 Subject: sanity check in add_packed_git() add_packed_git() tries to get the pack SHA1 by parsing its name. It may access uninitialized memory for packs with short names. Signed-off-by: Pavel Roskin Signed-off-by: Junio C Hamano --- sha1_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sha1_file.c b/sha1_file.c index fa22e9c71a..d83d8240d0 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -464,7 +464,7 @@ struct packed_git *add_packed_git(char *path, int path_len, int local) p->pack_last_used = 0; p->pack_use_cnt = 0; p->pack_local = local; - if (!get_sha1_hex(path + path_len - 40 - 4, sha1)) + if ((path_len > 44) && !get_sha1_hex(path + path_len - 44, sha1)) memcpy(p->sha1, sha1, 20); return p; } -- cgit v1.2.3 From 7246ed438c541650c2cd50e4e98b43226f60da0c Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 15 Dec 2005 08:47:30 +0100 Subject: \n usage in stderr output fprintf and die sometimes have missing/excessive "\n" in their arguments, correct the strings where I think it would be appropriate. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- config.c | 2 +- git.c | 2 +- receive-pack.c | 2 +- sha1_file.c | 8 ++++---- show-branch.c | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 5b5a9a2e4c..992e988407 100644 --- a/config.c +++ b/config.c @@ -487,7 +487,7 @@ int git_config_set_multivar(const char* key, const char* value, store.value_regex = (regex_t*)malloc(sizeof(regex_t)); if (regcomp(store.value_regex, value_regex, REG_EXTENDED)) { - fprintf(stderr, "Invalid pattern: %s", + fprintf(stderr, "Invalid pattern: %s\n", value_regex); free(store.value_regex); return 6; diff --git a/git.c b/git.c index 0fd95bf751..e795ddb810 100644 --- a/git.c +++ b/git.c @@ -278,7 +278,7 @@ int main(int argc, char **argv, char **envp) if (*exec_path != '/') { if (!getcwd(git_command, sizeof(git_command))) { fprintf(stderr, - "git: cannot determine current directory"); + "git: cannot determine current directory\n"); exit(1); } len = strlen(git_command); diff --git a/receive-pack.c b/receive-pack.c index cbe37e7239..92878ecac3 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -79,7 +79,7 @@ static int run_update_hook(const char *refname, case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: die("waitpid is confused"); case -ERR_RUN_COMMAND_WAITPID_SIGNAL: - fprintf(stderr, "%s died of signal", update_hook); + fprintf(stderr, "%s died of signal\n", update_hook); return -1; case -ERR_RUN_COMMAND_WAITPID_NOEXIT: die("%s died strangely", update_hook); diff --git a/sha1_file.c b/sha1_file.c index d83d8240d0..601147351d 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1274,7 +1274,7 @@ int move_temp_to_file(const char *tmpfile, char *filename) unlink(tmpfile); if (ret) { if (ret != EEXIST) { - fprintf(stderr, "unable to write sha1 filename %s: %s", filename, strerror(ret)); + fprintf(stderr, "unable to write sha1 filename %s: %s\n", filename, strerror(ret)); return -1; } /* FIXME!!! Collision check here ? */ @@ -1313,7 +1313,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha } if (errno != ENOENT) { - fprintf(stderr, "sha1 file %s: %s", filename, strerror(errno)); + fprintf(stderr, "sha1 file %s: %s\n", filename, strerror(errno)); return -1; } @@ -1321,7 +1321,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha fd = mkstemp(tmpfile); if (fd < 0) { - fprintf(stderr, "unable to create temporary sha1 filename %s: %s", tmpfile, strerror(errno)); + fprintf(stderr, "unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno)); return -1; } @@ -1410,7 +1410,7 @@ int write_sha1_to_fd(int fd, const unsigned char *sha1) size = write(fd, buf + posn, objsize - posn); if (size <= 0) { if (!size) { - fprintf(stderr, "write closed"); + fprintf(stderr, "write closed\n"); } else { perror("write "); } diff --git a/show-branch.c b/show-branch.c index c7422460be..3fe62b7177 100644 --- a/show-branch.c +++ b/show-branch.c @@ -303,7 +303,7 @@ static int append_ref(const char *refname, const unsigned char *sha1) return 0; if (MAX_REVS <= ref_name_cnt) { fprintf(stderr, "warning: ignoring %s; " - "cannot handle more than %d refs", + "cannot handle more than %d refs\n", refname, MAX_REVS); return 0; } @@ -537,7 +537,7 @@ int main(int ac, char **av) if (MAX_REVS <= num_rev) die("cannot handle more than %d revs.", MAX_REVS); if (get_sha1(ref_name[num_rev], revkey)) - die("'%s' is not a valid ref.\n", ref_name[num_rev]); + die("'%s' is not a valid ref.", ref_name[num_rev]); commit = lookup_commit_reference(revkey); if (!commit) die("cannot find commit %s (%s)", -- cgit v1.2.3 From 69310a34cb6dcca32b08cf3ea9e91ab19354a874 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 22 Dec 2005 12:39:39 -0800 Subject: send-pack: reword non-fast-forward error message. Wnen refusing to push a head, we said cryptic "remote 'branch' object X does not exist on local" or "remote ref 'branch' is not a strict subset of local ref 'branch'". That was gittish. Since the most likely reason this happens is because the pushed head was not up-to-date, clarify the error message to say that straight, and suggest pulling first. First noticed by Johannes and seconded by Andreas. Signed-off-by: Junio C Hamano --- send-pack.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/send-pack.c b/send-pack.c index 5bc2f017bc..0d41f9a178 100644 --- a/send-pack.c +++ b/send-pack.c @@ -231,23 +231,21 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec) if (!force_update && !is_zero_sha1(ref->old_sha1) && !ref->force) { - if (!has_sha1_file(ref->old_sha1)) { - error("remote '%s' object %s does not " - "exist on local", - ref->name, sha1_to_hex(ref->old_sha1)); - ret = -2; - continue; - } - - /* We assume that local is fsck-clean. Otherwise - * you _could_ have an old tag which points at - * something you do not have, which may or may not - * be a commit. - */ - if (!ref_newer(ref->peer_ref->new_sha1, + if (!has_sha1_file(ref->old_sha1) || + !ref_newer(ref->peer_ref->new_sha1, ref->old_sha1)) { - error("remote ref '%s' is not a strict " - "subset of local ref '%s'.", ref->name, + /* We do not have the remote ref, or + * we know that the remote ref is not + * an ancestor of what we are trying to + * push. Either way this can be losing + * commits at the remote end and likely + * we were not up to date to begin with. + */ + error("remote '%s' is not a strict " + "subset of local ref '%s'. " + "maybe you are not up-to-date and " + "need to pull first?", + ref->name, ref->peer_ref->name); ret = -2; continue; -- cgit v1.2.3 From e99fcf96deab45ca81b22948328deb2d8586aa8d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 22 Dec 2005 20:38:23 +0100 Subject: git-format-patch should show the correct version We want to record the version of the tools the patch was generated with. While these tools could be rebuilt, git-format-patch stayed the same and report the wrong version. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index e9bf860f6d..dde8f331d6 100644 --- a/Makefile +++ b/Makefile @@ -397,6 +397,9 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py git-cherry-pick: git-revert cp $< $@ +# format-patch records GIT_VERSION +git-format-patch: Makefile + %.o: %.c $(CC) -o $*.o -c $(ALL_CFLAGS) $< %.o: %.S -- cgit v1.2.3 From a14c225661fa2fc271d9e0fbf262e369dc7254fc Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Thu, 22 Dec 2005 09:09:05 -0800 Subject: Fix for http-fetch from file:// URLs Recognize missing files when using http-fetch with file:// URLs Signed-off-by: Nick Hengeveld Signed-off-by: Junio C Hamano --- http-fetch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/http-fetch.c b/http-fetch.c index 3cd6ef91af..61b2188adb 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -267,7 +267,8 @@ static void process_object_response(void *callback_data) obj_req->state = COMPLETE; /* Use alternates if necessary */ - if (obj_req->http_code == 404) { + if (obj_req->http_code == 404 || + obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE) { fetch_alternates(alt->base); if (obj_req->repo->next != NULL) { obj_req->repo = @@ -475,7 +476,8 @@ static void process_alternates_response(void *callback_data) } } } else if (slot->curl_result != CURLE_OK) { - if (slot->http_code != 404) { + if (slot->http_code != 404 && + slot->curl_result != CURLE_FILE_COULDNT_READ_FILE) { got_alternates = -1; return; } @@ -637,7 +639,8 @@ static int fetch_indices(struct alt_base *repo) if (start_active_slot(slot)) { run_active_slot(slot); if (slot->curl_result != CURLE_OK) { - if (slot->http_code == 404) { + if (slot->http_code == 404 || + slot->curl_result == CURLE_FILE_COULDNT_READ_FILE) { repo->got_indices = 1; free(buffer.buffer); return 0; @@ -802,7 +805,8 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1) ret = error("Request for %s aborted", hex); } else if (obj_req->curl_result != CURLE_OK && obj_req->http_code != 416) { - if (obj_req->http_code == 404) + if (obj_req->http_code == 404 || + obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE) ret = -1; /* Be silent, it is probably in a pack. */ else ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)", -- cgit v1.2.3 From 1e80e0449248edb77b0fb9853f4a3404a599e207 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 22 Dec 2005 18:55:59 +0100 Subject: sha1_to_hex: properly terminate the SHA1 sha1_to_hex() returns a pointer to a static buffer. Some of its users modify that buffer by appending a newline character. Other users rely on the fact that you can call printf("%s", sha1_to_hex(sha1)); Just to be on the safe side, terminate the SHA1 in sha1_to_hex(). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- sha1_file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sha1_file.c b/sha1_file.c index 601147351d..d451a94efe 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -81,6 +81,8 @@ char * sha1_to_hex(const unsigned char *sha1) *buf++ = hex[val >> 4]; *buf++ = hex[val & 0xf]; } + *buf = '\0'; + return buffer; } -- cgit v1.2.3