Code

Merge branch 'ar/unlink-err'
authorJunio C Hamano <gitster@pobox.com>
Mon, 18 May 2009 16:01:06 +0000 (09:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 May 2009 16:01:06 +0000 (09: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-clone.c
builtin-fetch-pack.c
diff.c
fast-import.c
lockfile.c
server-info.c
sha1_file.c
transport.c

diff --combined builtin-clone.c
index d068b7e0d89399ac54c2cf56f128d8884e20b665,ba286e0160c494244810334e3a0b43a59756e84a..c935833c6ce176caf47a14b5ad1f2848f0d1ab22
@@@ -104,12 -104,11 +104,12 @@@ static char *get_repo_path(const char *
  static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
  {
        const char *end = repo + strlen(repo), *start;
 +      char *dir;
  
        /*
 -       * Strip trailing slashes and /.git
 +       * Strip trailing spaces, slashes and /.git
         */
 -      while (repo < end && is_dir_sep(end[-1]))
 +      while (repo < end && (is_dir_sep(end[-1]) || isspace(end[-1])))
                end--;
        if (end - repo > 5 && is_dir_sep(end[-5]) &&
            !strncmp(end - 4, ".git", 4)) {
        if (is_bare) {
                struct strbuf result = STRBUF_INIT;
                strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
 -              return strbuf_detach(&result, 0);
 +              dir = strbuf_detach(&result, 0);
 +      } else
 +              dir = xstrndup(start, end - start);
 +      /*
 +       * Replace sequences of 'control' characters and whitespace
 +       * with one ascii space, remove leading and trailing spaces.
 +       */
 +      if (*dir) {
 +              char *out = dir;
 +              int prev_space = 1 /* strip leading whitespace */;
 +              for (end = dir; *end; ++end) {
 +                      char ch = *end;
 +                      if ((unsigned char)ch < '\x20')
 +                              ch = '\x20';
 +                      if (isspace(ch)) {
 +                              if (prev_space)
 +                                      continue;
 +                              prev_space = 1;
 +                      } else
 +                              prev_space = 0;
 +                      *out++ = ch;
 +              }
 +              *out = '\0';
 +              if (out > dir && prev_space)
 +                      out[-1] = '\0';
        }
 -
 -      return xstrndup(start, end - start);
 +      return dir;
  }
  
  static void strip_trailing_slashes(char *dir)
@@@ -252,7 -228,8 +252,8 @@@ static void copy_or_link_directory(stru
                }
  
                if (unlink(dest->buf) && errno != ENOENT)
-                       die("failed to unlink %s", dest->buf);
+                       die("failed to unlink %s: %s",
+                           dest->buf, strerror(errno));
                if (!option_no_hardlinks) {
                        if (!link(src->buf, dest->buf))
                                continue;
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 c67ef63c55a80c6e466c1545e7eb7ffbb58ba1d4,6802f5ac12ae7e811b7ef5cb1214d0fd78b46d53..f06876be67245ab559b57168553cfd71b9d23feb
--- 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;
        }
  }
@@@ -839,9 -839,10 +839,9 @@@ static int scale_linear(int it, int wid
  }
  
  static void show_name(FILE *file,
 -                    const char *prefix, const char *name, int len,
 -                    const char *reset, const char *set)
 +                    const char *prefix, const char *name, int len)
  {
 -      fprintf(file, " %s%s%-*s%s |", set, prefix, len, name, reset);
 +      fprintf(file, " %s%-*s |", prefix, len, name);
  }
  
  static void show_graph(FILE *file, char ch, int cnt, const char *set, const char *reset)
@@@ -875,7 -876,7 +875,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;
                }
  
                if (data->files[i]->is_binary) {
 -                      show_name(options->file, prefix, name, len, reset, set);
 +                      show_name(options->file, prefix, name, len);
                        fprintf(options->file, "  Bin ");
                        fprintf(options->file, "%s%d%s", del_c, deleted, reset);
                        fprintf(options->file, " -> ");
                        continue;
                }
                else if (data->files[i]->is_unmerged) {
 -                      show_name(options->file, prefix, name, len, reset, set);
 +                      show_name(options->file, prefix, name, len);
                        fprintf(options->file, "  Unmerged\n");
                        continue;
                }
                        add = scale_linear(add, width, max_change);
                        del = scale_linear(del, width, max_change);
                }
 -              show_name(options->file, prefix, name, len, reset, set);
 +              show_name(options->file, prefix, name, len);
                fprintf(options->file, "%5d%s", added + deleted,
                                added + deleted ? " " : "");
                show_graph(options->file, '+', add, add_c, reset);
                fprintf(options->file, "\n");
        }
        fprintf(options->file,
 -             "%s %d files changed, %d insertions(+), %d deletions(-)%s\n",
 -             set, total_files, adds, dels, reset);
 +             " %d files changed, %d insertions(+), %d deletions(-)\n",
 +             total_files, adds, dels);
  }
  
  static void show_shortstats(struct diffstat_t* data, struct diff_options *options)
               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 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 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 28bd9082fc9f4b79519f6bef8204600072c07027,dd474116a8856b429c9416de5c3a149e11a9f70b..e5dec8d3c8d783a8f90b700e633fe07e818df1f7
@@@ -791,7 -791,7 +791,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)
@@@ -2247,7 -2247,7 +2247,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));
diff --combined transport.c
index 8ad317bf32cf14ee1dee7c084d88a9ea57209da8,efecb65258ba95ee743f0e3ca178e74e2756e7d1..89d846e5c3d936739a13983728eaf97a1eb15932
@@@ -1069,7 -1069,7 +1069,7 @@@ int transport_fetch_refs(struct transpo
  void transport_unlock_pack(struct transport *transport)
  {
        if (transport->pack_lockfile) {
-               unlink(transport->pack_lockfile);
+               unlink_or_warn(transport->pack_lockfile);
                free(transport->pack_lockfile);
                transport->pack_lockfile = NULL;
        }
@@@ -1083,51 -1083,3 +1083,51 @@@ int transport_disconnect(struct transpo
        free(transport);
        return ret;
  }
 +
 +/*
 + * Strip username (and password) from an url and return
 + * it in a newly allocated string.
 + */
 +char *transport_anonymize_url(const char *url)
 +{
 +      char *anon_url, *scheme_prefix, *anon_part;
 +      size_t anon_len, prefix_len = 0;
 +
 +      anon_part = strchr(url, '@');
 +      if (is_local(url) || !anon_part)
 +              goto literal_copy;
 +
 +      anon_len = strlen(++anon_part);
 +      scheme_prefix = strstr(url, "://");
 +      if (!scheme_prefix) {
 +              if (!strchr(anon_part, ':'))
 +                      /* cannot be "me@there:/path/name" */
 +                      goto literal_copy;
 +      } else {
 +              const char *cp;
 +              /* make sure scheme is reasonable */
 +              for (cp = url; cp < scheme_prefix; cp++) {
 +                      switch (*cp) {
 +                              /* RFC 1738 2.1 */
 +                      case '+': case '.': case '-':
 +                              break; /* ok */
 +                      default:
 +                              if (isalnum(*cp))
 +                                      break;
 +                              /* it isn't */
 +                              goto literal_copy;
 +                      }
 +              }
 +              /* @ past the first slash does not count */
 +              cp = strchr(scheme_prefix + 3, '/');
 +              if (cp && cp < anon_part)
 +                      goto literal_copy;
 +              prefix_len = scheme_prefix - url + 3;
 +      }
 +      anon_url = xcalloc(1, 1 + prefix_len + anon_len);
 +      memcpy(anon_url, url, prefix_len);
 +      memcpy(anon_url + prefix_len, anon_part, anon_len);
 +      return anon_url;
 +literal_copy:
 +      return xstrdup(url);
 +}