Merge branch 'fc/decorate-tag'
authorJunio C Hamano <gitster@pobox.com>
Sat, 23 May 2009 08:43:50 +0000 (01:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 May 2009 08:43:50 +0000 (01:43 -0700)
* fc/decorate-tag:
Prettify log decorations even more
Change prettify_ref to prettify_refname

1  2 
builtin-fetch.c
builtin-send-pack.c
refs.c
transport.c
diff --combined builtin-fetch.c
index b944cac6e6546164ca41d66662e395de60ee4337,ebd0c0878835c0664d59e62d0b269db313d5a422..77acabfcc71aaee02ea99d2cd10e51dd0feaea6e
@@@ -197,7 -197,7 +197,7 @@@ static int update_local_ref(struct ref 
        struct commit *current = NULL, *updated;
        enum object_type type;
        struct branch *current_branch = branch_get(NULL);
-       const char *pretty_ref = prettify_ref(ref);
+       const char *pretty_ref = prettify_refname(ref->name);
  
        *display = 0;
        type = sha1_object_info(ref->new_sha1, NULL);
        }
  }
  
 -static int store_updated_refs(const char *url, const char *remote_name,
 +static int store_updated_refs(const char *raw_url, const char *remote_name,
                struct ref *ref_map)
  {
        FILE *fp;
        char note[1024];
        const char *what, *kind;
        struct ref *rm;
 -      char *filename = git_path("FETCH_HEAD");
 +      char *url, *filename = git_path("FETCH_HEAD");
  
        fp = fopen(filename, "a");
        if (!fp)
                return error("cannot open %s: %s\n", filename, strerror(errno));
 +
 +      url = transport_anonymize_url(raw_url);
        for (rm = ref_map; rm; rm = rm->next) {
                struct ref *ref = NULL;
  
                                                    kind);
                        note_len += sprintf(note + note_len, "'%s' of ", what);
                }
 -              note_len += sprintf(note + note_len, "%.*s", url_len, url);
 -              fprintf(fp, "%s\t%s\t%s\n",
 +              note[note_len] = '\0';
 +              fprintf(fp, "%s\t%s\t%s",
                        sha1_to_hex(commit ? commit->object.sha1 :
                                    rm->old_sha1),
                        rm->merge ? "" : "not-for-merge",
                        note);
 +              for (i = 0; i < url_len; ++i)
 +                      if ('\n' == url[i])
 +                              fputs("\\n", fp);
 +                      else
 +                              fputc(url[i], fp);
 +              fputc('\n', fp);
  
                if (ref)
                        rc |= update_local_ref(ref, what, note);
                                fprintf(stderr, " %s\n", note);
                }
        }
 +      free(url);
        fclose(fp);
        if (rc & 2)
                error("some local refs could not be updated; try running\n"
diff --combined builtin-send-pack.c
index 473a3de40c4cc9aab5c1355d0602646234e7bc1c,b2279b0d297a41692c7901f2113f0e220a0cd5e4..be3b0926deeb38f34b75c08bedf29fd80bac9b3c
@@@ -43,16 -43,12 +43,16 @@@ static int pack_objects(int fd, struct 
                "--stdout",
                NULL,
                NULL,
 +              NULL,
        };
        struct child_process po;
        int i;
  
 +      i = 4;
        if (args->use_thin_pack)
 -              argv[4] = "--thin";
 +              argv[i++] = "--thin";
 +      if (args->use_ofs_delta)
 +              argv[i++] = "--delta-base-offset";
        memset(&po, 0, sizeof(po));
        po.argv = argv;
        po.in = -1;
@@@ -178,9 -174,9 +178,9 @@@ static void print_ref_status(char flag
  {
        fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary);
        if (from)
-               fprintf(stderr, "%s -> %s", prettify_ref(from), prettify_ref(to));
+               fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
        else
-               fputs(prettify_ref(to), stderr);
+               fputs(prettify_refname(to->name), stderr);
        if (msg) {
                fputs(" (", stderr);
                fputs(msg, stderr);
@@@ -319,8 -315,6 +319,8 @@@ int send_pack(struct send_pack_args *ar
                ask_for_status_report = 1;
        if (server_supports("delete-refs"))
                allow_deleting_refs = 1;
 +      if (server_supports("ofs-delta"))
 +              args->use_ofs_delta = 1;
  
        if (!remote_refs) {
                fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
diff --combined refs.c
index bb4bdc9eac9a3cb5a122437f14a0f175511b1493,e74461eaafb1b745be4f3fcda4ee8752ef580af9..45ad55693dbaff8e85687a1ed48f1cc901332b3a
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -682,13 -682,12 +682,13 @@@ int for_each_rawref(each_ref_fn fn, voi
   * - it has ASCII control character, "~", "^", ":" or SP, anywhere, or
   * - it ends with a "/".
   * - it ends with ".lock"
 + * - it contains a "\" (backslash)
   */
  
  static inline int bad_ref_char(int ch)
  {
        if (((unsigned) ch) <= ' ' ||
 -          ch == '~' || ch == '^' || ch == ':')
 +          ch == '~' || ch == '^' || ch == ':' || ch == '\\')
                return 1;
        /* 2.13 Pattern Matching Notation */
        if (ch == '?' || ch == '[') /* Unsupported */
@@@ -751,9 -750,8 +751,8 @@@ int check_ref_format(const char *ref
        }
  }
  
- const char *prettify_ref(const struct ref *ref)
+ const char *prettify_refname(const char *name)
  {
-       const char *name = ref->name;
        return name + (
                !prefixcmp(name, "refs/heads/") ? 11 :
                !prefixcmp(name, "refs/tags/") ? 10 :
@@@ -1003,10 -1001,12 +1002,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;
@@@ -1377,7 -1380,7 +1376,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 transport.c
index 89d846e5c3d936739a13983728eaf97a1eb15932,38c7f578e58c21d61f825ea6a47446f08b2a030e..17891d5149aab99ce0ec5538a0e11b8e9c2398ec
@@@ -732,9 -732,9 +732,9 @@@ static void print_ref_status(char flag
  {
        fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary);
        if (from)
-               fprintf(stderr, "%s -> %s", prettify_ref(from), prettify_ref(to));
+               fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
        else
-               fputs(prettify_ref(to), stderr);
+               fputs(prettify_refname(to->name), stderr);
        if (msg) {
                fputs(" (", stderr);
                fputs(msg, stderr);
@@@ -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);
 +}