Merge branch 'ar/unlink-err' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 26 May 2009 02:01:50 +0000 (19:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 May 2009 02:01:50 +0000 (19:01 -0700)
* 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

1  2 
builtin-fetch-pack.c
diff.c
fast-import.c
http-push.c
lockfile.c
refs.c
server-info.c
sha1_file.c
diff --combined builtin-fetch-pack.c
index 87f46c6d07ccb0f82449b92e33cd4cda76a99da3,bd97cfd9bfdbc6bd25e5364ba84dad44059d2ac4..6202462216f3b8c3cbe924d4cc002616e69d75ab
@@@ -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 charget_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 363dcb9613f5f57a2ae31ea6f803caf44954475a,6802f5ac12ae7e811b7ef5cb1214d0fd78b46d53..d24bff1e465d5b5e486ab461bd0548387736f109
--- 1/diff.c
--- 2/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_tdata, 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_tdata, struct diff_options *options)
 +static void show_numstat(struct diffstat_t *data, struct diff_options *options)
  {
        int i;
  
diff --combined fast-import.c
index e9d23ffb2fb3f6df141944dca7ddab0edbd1e5ee,6a618e9163a8a0f871e5aeada78502f73f2c896a..a2a24588a99957d5af759ca6d8858366430ab3a3
@@@ -212,7 -212,7 +212,7 @@@ struct tree_content
  struct tree_entry
  {
        struct tree_content *tree;
 -      struct atom_strname;
 +      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 charmark_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 branchb = 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 charsha1 = root->versions[1].sha1;
 +      unsigned char *sha1 = root->versions[1].sha1;
        struct object_entry *myoe;
        struct tree_content *t;
        unsigned long size;
                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 9da14201b158f9118c1ece8519672875d4bb96e2,29e8ebfebb8947cc76b5631ae143d0003e5b3d51..e16a0ad3f97ef49930a599d3a800a0c7fad317e0
@@@ -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);
                } 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)
                        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 828d19f452a8bfffe2ee224a630e8246f4a1edab,984eb320fc7b3c97537556f22bef8077d52b389d..eb931eded5a6ed20f1d80dadf08cbb8009d85767
@@@ -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 8679c17e0d2902e6264d0d0b1d6fd36bcb85fecb,2b1f0f0e6ed7978107e5b488f8d12f6276e482a4..90163bdc56868151e4fd45ff77aa3bd56db45573
--- 1/refs.c
--- 2/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] = '.';
        }
         */
        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 906ce5b27242ca1e415a5410135d58f1c000e8b0,d096dc7718b21eb7f5e88b7276983ca6cccc723e..4098ca2b5c166c32cfe4aea9d1bff2e6593e9a60
@@@ -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 bd5edd8e657536e60fcb68d427df134c84f816c5,dd474116a8856b429c9416de5c3a149e11a9f70b..e73cd4fc0ba2daac14f604f1973d1b0658212b26
@@@ -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 charuse_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());