From: Junio C Hamano Date: Tue, 26 May 2009 02:01:50 +0000 (-0700) Subject: Merge branch 'ar/unlink-err' into maint X-Git-Tag: v1.6.3.2~19 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2c5942dbae01e5c23d2b68aced019702eb256ad9?ds=inline;hp=-c Merge branch 'ar/unlink-err' into maint * ar/unlink-err: print unlink(2) errno in copy_or_link_directory replace direct calls to unlink(2) with unlink_or_warn Introduce an unlink(2) wrapper which gives warning if unlink failed --- 2c5942dbae01e5c23d2b68aced019702eb256ad9 diff --combined builtin-fetch-pack.c index 87f46c6d07,bd97cfd9bf..6202462216 --- a/builtin-fetch-pack.c +++ b/builtin-fetch-pack.c @@@ -13,7 -13,6 +13,7 @@@ static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; static int unpack_limit = 100; +static int prefer_ofs_delta = 1; static struct fetch_pack_args args = { /* .uploadpack = */ "git-upload-pack", }; @@@ -112,7 -111,7 +112,7 @@@ static void mark_common(struct commit * Get the next rev to send, ignoring the common. */ -static const unsigned char* get_rev(void) +static const unsigned char *get_rev(void) { struct commit *commit = NULL; @@@ -201,7 -200,7 +201,7 @@@ static int find_common(int fd[2], unsig (args.use_thin_pack ? " thin-pack" : ""), (args.no_progress ? " no-progress" : ""), (args.include_tag ? " include-tag" : ""), - " ofs-delta"); + (prefer_ofs_delta ? " ofs-delta" : "")); else packet_write(fd[1], "want %s\n", sha1_to_hex(remote)); fetching++; @@@ -597,11 -596,6 +597,11 @@@ static struct ref *do_fetch_pack(int fd fprintf(stderr, "Server supports side-band\n"); use_sideband = 1; } + if (server_supports("ofs-delta")) { + if (args.verbose) + fprintf(stderr, "Server supports ofs-delta\n"); + } else + prefer_ofs_delta = 0; if (everything_local(&ref, nr_match, match)) { packet_flush(fd[1]); goto all_done; @@@ -654,11 -648,6 +654,11 @@@ static int fetch_pack_config(const cha return 0; } + if (strcmp(var, "repack.usedeltabaseoffset") == 0) { + prefer_ofs_delta = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } @@@ -825,7 -814,7 +825,7 @@@ struct ref *fetch_pack(struct fetch_pac fd = hold_lock_file_for_update(&lock, shallow, LOCK_DIE_ON_ERROR); if (!write_shallow_commits(fd, 0)) { - unlink(shallow); + unlink_or_warn(shallow); rollback_lock_file(&lock); } else { commit_lock_file(&lock); diff --combined diff.c index 363dcb9613,6802f5ac12..d24bff1e46 --- a/diff.c +++ b/diff.c @@@ -189,7 -189,7 +189,7 @@@ static void remove_tempfile(void int i; for (i = 0; i < ARRAY_SIZE(diff_temp); i++) { if (diff_temp[i].name == diff_temp[i].tmp_path) - unlink(diff_temp[i].name); + unlink_or_warn(diff_temp[i].name); diff_temp[i].name = NULL; } } @@@ -876,7 -876,7 +876,7 @@@ static void fill_print_name(struct diff file->print_name = pname; } -static void show_stats(struct diffstat_t* data, struct diff_options *options) +static void show_stats(struct diffstat_t *data, struct diff_options *options) { int i, len, add, del, adds = 0, dels = 0; int max_change = 0, max_len = 0; @@@ -1025,7 -1025,7 +1025,7 @@@ static void show_shortstats(struct diff total_files, adds, dels); } -static void show_numstat(struct diffstat_t* data, struct diff_options *options) +static void show_numstat(struct diffstat_t *data, struct diff_options *options) { int i; diff --combined fast-import.c index e9d23ffb2f,6a618e9163..a2a24588a9 --- a/fast-import.c +++ b/fast-import.c @@@ -212,7 -212,7 +212,7 @@@ struct tree_content struct tree_entry { struct tree_content *tree; - struct atom_str* name; + struct atom_str *name; struct tree_entry_ms { uint16_t mode; @@@ -313,7 -313,7 +313,7 @@@ static unsigned int object_entry_alloc static struct object_entry_pool *blocks; static struct object_entry *object_table[1 << 16]; static struct mark_set *marks; -static const char* mark_file; +static const char *mark_file; /* Our last blob */ static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 }; @@@ -672,7 -672,7 +672,7 @@@ static struct branch *lookup_branch(con static struct branch *new_branch(const char *name) { unsigned int hc = hc_str(name, strlen(name)) % branch_table_sz; - struct branch* b = lookup_branch(name); + struct branch *b = lookup_branch(name); if (b) die("Invalid attempt to create duplicate branch: %s", name); @@@ -931,7 -931,7 +931,7 @@@ static void unkeep_all_packs(void struct packed_git *p = all_packs[k]; snprintf(name, sizeof(name), "%s/pack/pack-%s.keep", get_object_directory(), sha1_to_hex(p->sha1)); - unlink(name); + unlink_or_warn(name); } } @@@ -981,7 -981,7 +981,7 @@@ static void end_packfile(void } else { close(old_p->pack_fd); - unlink(old_p->pack_name); + unlink_or_warn(old_p->pack_name); } free(old_p); @@@ -1035,7 -1035,7 +1035,7 @@@ static int store_object git_SHA_CTX c; z_stream s; - hdrlen = sprintf((char*)hdr,"%s %lu", typename(type), + hdrlen = sprintf((char *)hdr,"%s %lu", typename(type), (unsigned long)dat->len) + 1; git_SHA1_Init(&c); git_SHA1_Update(&c, hdr, hdrlen); @@@ -1217,7 -1217,7 +1217,7 @@@ static const char *get_mode(const char static void load_tree(struct tree_entry *root) { - unsigned char* sha1 = root->versions[1].sha1; + unsigned char *sha1 = root->versions[1].sha1; struct object_entry *myoe; struct tree_content *t; unsigned long size; @@@ -1258,8 -1258,8 +1258,8 @@@ e->versions[0].mode = e->versions[1].mode; e->name = to_atom(c, strlen(c)); c += e->name->str_len + 1; - hashcpy(e->versions[0].sha1, (unsigned char*)c); - hashcpy(e->versions[1].sha1, (unsigned char*)c); + hashcpy(e->versions[0].sha1, (unsigned char *)c); + hashcpy(e->versions[1].sha1, (unsigned char *)c); c += 20; } free(buf); diff --combined http-push.c index 9da14201b1,29e8ebfebb..e16a0ad3f9 --- a/http-push.c +++ b/http-push.c @@@ -315,9 -315,9 +315,9 @@@ static void start_fetch_loose(struct tr "%s.temp", filename); snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename); - unlink(prevfile); + unlink_or_warn(prevfile); rename(request->tmpfile, prevfile); - unlink(request->tmpfile); + unlink_or_warn(request->tmpfile); if (request->local_fileno != -1) error("fd leakage in start: %d", request->local_fileno); @@@ -372,7 -372,7 +372,7 @@@ } while (prev_read > 0); close(prevlocal); } - unlink(prevfile); + unlink_or_warn(prevfile); /* Reset inflate/SHA1 if there was an error reading the previous temp file; also rewind to the beginning of the local file. */ @@@ -784,7 -784,7 +784,7 @@@ static void finish_request(struct trans request->http_code != 416) { if (stat(request->tmpfile, &st) == 0) { if (st.st_size == 0) - unlink(request->tmpfile); + unlink_or_warn(request->tmpfile); } } else { if (request->http_code == 416) @@@ -793,9 -793,9 +793,9 @@@ git_inflate_end(&request->stream); git_SHA1_Final(request->real_sha1, &request->c); if (request->zret != Z_STREAM_END) { - unlink(request->tmpfile); + unlink_or_warn(request->tmpfile); } else if (hashcmp(request->obj->sha1, request->real_sha1)) { - unlink(request->tmpfile); + unlink_or_warn(request->tmpfile); } else { request->rename = move_temp_to_file( @@@ -1415,9 -1415,8 +1415,9 @@@ static void remove_locks(void fprintf(stderr, "Removing remote locks...\n"); while (lock) { + struct remote_lock *next = lock->next; unlock_remote(lock); - lock = lock->next; + lock = next; } } diff --combined lockfile.c index 828d19f452,984eb320fc..eb931eded5 --- a/lockfile.c +++ b/lockfile.c @@@ -16,7 -16,7 +16,7 @@@ static void remove_lock_file(void lock_file_list->filename[0]) { if (lock_file_list->fd >= 0) close(lock_file_list->fd); - unlink(lock_file_list->filename); + unlink_or_warn(lock_file_list->filename); } lock_file_list = lock_file_list->next; } @@@ -109,7 -109,7 +109,7 @@@ static char *resolve_symlink(char *p, s * link is a relative path, so I must replace the * last element of p with it. */ - char *r = (char*)last_path_elm(p); + char *r = (char *)last_path_elm(p); if (r - p + link_len < s) strcpy(r, link); else { @@@ -259,7 -259,7 +259,7 @@@ void rollback_lock_file(struct lock_fil if (lk->filename[0]) { if (lk->fd >= 0) close(lk->fd); - unlink(lk->filename); + unlink_or_warn(lk->filename); } lk->filename[0] = 0; } diff --combined refs.c index 8679c17e0d,2b1f0f0e6e..90163bdc56 --- a/refs.c +++ b/refs.c @@@ -893,10 -893,8 +893,10 @@@ static struct ref_lock *lock_ref_sha1_b * name is a proper prefix of our refname. */ if (missing && - !is_refname_available(ref, NULL, get_packed_refs(), 0)) + !is_refname_available(ref, NULL, get_packed_refs(), 0)) { + last_errno = ENOTDIR; goto error_return; + } lock->lk = xcalloc(1, sizeof(struct lock_file)); @@@ -1004,12 -1002,10 +1004,10 @@@ int delete_ref(const char *refname, con } else { path = git_path("%s", refname); } - err = unlink(path); - if (err && errno != ENOENT) { + err = unlink_or_warn(path); + if (err && errno != ENOENT) ret = 1; - error("unlink(%s) failed: %s", - path, strerror(errno)); - } + if (!(delopt & REF_NODEREF)) lock->lk->filename[i] = '.'; } @@@ -1019,10 -1015,7 +1017,7 @@@ */ ret |= repack_without_ref(refname); - err = unlink(git_path("logs/%s", lock->ref_name)); - if (err && errno != ENOENT) - warning("unlink(%s) failed: %s", - git_path("logs/%s", lock->ref_name), strerror(errno)); + unlink_or_warn(git_path("logs/%s", lock->ref_name)); invalidate_cached_refs(); unlock_ref(lock); return ret; @@@ -1383,7 -1376,7 +1378,7 @@@ int create_symref(const char *ref_targe if (adjust_shared_perm(git_HEAD)) { error("Unable to fix permissions on %s", lockpath); error_unlink_return: - unlink(lockpath); + unlink_or_warn(lockpath); error_free_return: free(git_HEAD); return -1; diff --combined server-info.c index 906ce5b272,d096dc7718..4098ca2b5c --- a/server-info.c +++ b/server-info.c @@@ -132,8 -132,8 +132,8 @@@ static int read_pack_info_file(const ch static int compare_info(const void *a_, const void *b_) { - struct pack_info * const* a = a_; - struct pack_info * const* b = b_; + struct pack_info *const *a = a_; + struct pack_info *const *b = b_; if (0 <= (*a)->old_num && 0 <= (*b)->old_num) /* Keep the order in the original */ @@@ -246,7 -246,7 +246,7 @@@ int update_server_info(int force errs = errs | update_info_packs(force); /* remove leftover rev-cache file if there is any */ - unlink(git_path("info/rev-cache")); + unlink_or_warn(git_path("info/rev-cache")); return errs; } diff --combined sha1_file.c index bd5edd8e65,dd474116a8..e73cd4fc0b --- a/sha1_file.c +++ b/sha1_file.c @@@ -720,8 -720,6 +720,8 @@@ static int open_packed_git_1(struct pac return error("packfile %s index unavailable", p->pack_name); p->pack_fd = open(p->pack_name, O_RDONLY); + while (p->pack_fd < 0 && errno == EMFILE && unuse_one_window(p, -1)) + p->pack_fd = open(p->pack_name, O_RDONLY); if (p->pack_fd < 0 || fstat(p->pack_fd, &st)) return -1; @@@ -793,7 -791,7 +793,7 @@@ static int in_window(struct pack_windo && (offset + 20) <= (win_off + win->len); } -unsigned char* use_pack(struct packed_git *p, +unsigned char *use_pack(struct packed_git *p, struct pack_window **w_cursor, off_t offset, unsigned int *left) @@@ -939,8 -937,6 +939,8 @@@ static void prepare_packed_git_one(cha sprintf(path, "%s/pack", objdir); len = strlen(path); dir = opendir(path); + while (!dir && errno == EMFILE && unuse_one_window(packed_git, -1)) + dir = opendir(path); if (!dir) { if (errno != ENOENT) error("unable to open object pack directory: %s: %s", @@@ -2251,7 -2247,7 +2251,7 @@@ int move_temp_to_file(const char *tmpfi goto out; ret = errno; } - unlink(tmpfile); + unlink_or_warn(tmpfile); if (ret) { if (ret != EEXIST) { return error("unable to write sha1 filename %s: %s\n", filename, strerror(ret)); @@@ -2343,8 -2339,6 +2343,8 @@@ static int write_loose_object(const uns filename = sha1_file_name(sha1); fd = create_tmpfile(tmpfile, sizeof(tmpfile), filename); + while (fd < 0 && errno == EMFILE && unuse_one_window(packed_git, -1)) + fd = create_tmpfile(tmpfile, sizeof(tmpfile), filename); if (fd < 0) { if (errno == EACCES) return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());