Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Tue, 9 Jun 2009 07:29:36 +0000 (00:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Jun 2009 07:29:36 +0000 (00:29 -0700)
* maint:
diff.c: plug a memory leak in an error path
fetch-pack: close output channel after sideband demultiplexer terminates
builtin-remote: Make "remote show" display all urls

1  2 
builtin-remote.c
diff.c
diff --combined builtin-remote.c
index f7d66189ccefe903588c7bbf044c2bc909c50b5a,d436412d9b1c38084438ee17773986c970252d56..d7ab6b2d5ff872c7872648bae4c97d7e1aa3ebba
@@@ -79,8 -79,7 +79,8 @@@ static int add(int argc, const char **a
                OPT_END()
        };
  
 -      argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 +      argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
 +                           0);
  
        if (argc < 2)
                usage_with_options(builtin_remote_usage, options);
@@@ -987,8 -986,7 +987,8 @@@ static int show(int argc, const char **
        struct string_list info_list = { NULL, 0, 0, 0 };
        struct show_info info;
  
 -      argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 +      argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
 +                           0);
  
        if (argc < 1)
                return show_all();
  
                get_remote_ref_states(*argv, &states, query_flag);
  
-               printf("* remote %s\n  URL: %s\n", *argv,
-                       states.remote->url_nr > 0 ?
-                               states.remote->url[0] : "(no URL)");
+               printf("* remote %s\n", *argv);
+               if (states.remote->url_nr) {
+                       for (i=0; i < states.remote->url_nr; i++)
+                               printf("  URL: %s\n", states.remote->url[i]);
+               } else
+                       printf("  URL: %s\n", "(no URL)");
                if (no_query)
                        printf("  HEAD branch: (not queried)\n");
                else if (!states.heads.nr)
@@@ -1078,8 -1079,7 +1081,8 @@@ static int set_head(int argc, const cha
                            "delete refs/remotes/<name>/HEAD"),
                OPT_END()
        };
 -      argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 +      argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
 +                           0);
        if (argc)
                strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
  
@@@ -1133,8 -1133,7 +1136,8 @@@ static int prune(int argc, const char *
                OPT_END()
        };
  
 -      argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
 +      argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
 +                           0);
  
        if (argc < 1)
                usage_with_options(builtin_remote_usage, options);
@@@ -1224,7 -1223,7 +1227,7 @@@ static int update(int argc, const char 
                OPT_END()
        };
  
 -      argc = parse_options(argc, argv, options, builtin_remote_usage,
 +      argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
                             PARSE_OPT_KEEP_ARGV0);
        if (argc < 2) {
                argc = 2;
@@@ -1310,7 -1309,7 +1313,7 @@@ int cmd_remote(int argc, const char **a
        };
        int result;
  
 -      argc = parse_options(argc, argv, options, builtin_remote_usage,
 +      argc = parse_options(argc, argv, prefix, options, builtin_remote_usage,
                PARSE_OPT_STOP_AT_NON_OPTION);
  
        if (argc < 1)
diff --combined diff.c
index 4d0a5b9ae6f2b5d921a2aae2a03e9a7f1616dc4d,f0b580c1503147d093d928915ead2c5f88a0042b..43835d756c2c2c7ec579e1c38804fe33a706944f
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -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)
@@@ -955,7 -956,7 +955,7 @@@ static void show_stats(struct diffstat_
                }
  
                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)
@@@ -1964,16 -1965,8 +1964,16 @@@ static void prep_temp_blob(const char *
  {
        int fd;
        struct strbuf buf = STRBUF_INIT;
 +      struct strbuf template = STRBUF_INIT;
 +      char *path_dup = xstrdup(path);
 +      const char *base = basename(path_dup);
 +
 +      /* Generate "XXXXXX_basename.ext" */
 +      strbuf_addstr(&template, "XXXXXX_");
 +      strbuf_addstr(&template, base);
  
 -      fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
 +      fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,
 +                      strlen(base) + 1);
        if (fd < 0)
                die("unable to create temp-file: %s", strerror(errno));
        if (convert_to_working_tree(path,
        temp->hex[40] = 0;
        sprintf(temp->mode, "%06o", mode);
        strbuf_release(&buf);
 +      strbuf_release(&template);
 +      free(path_dup);
  }
  
  static struct diff_tempfile *prepare_temp_file(const char *name,
                        die("stat(%s): %s", name, strerror(errno));
                }
                if (S_ISLNK(st.st_mode)) {
 -                      int ret;
 -                      char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */
 -                      ret = readlink(name, buf, sizeof(buf));
 -                      if (ret < 0)
 +                      struct strbuf sb = STRBUF_INIT;
 +                      if (strbuf_readlink(&sb, name, st.st_size) < 0)
                                die("readlink(%s)", name);
 -                      if (ret == sizeof(buf))
 -                              die("symlink too long: %s", name);
 -                      prep_temp_blob(name, temp, buf, ret,
 +                      prep_temp_blob(name, temp, sb.buf, sb.len,
                                       (one->sha1_valid ?
                                        one->sha1 : null_sha1),
                                       (one->sha1_valid ?
                                        one->mode : S_IFLNK));
 +                      strbuf_release(&sb);
                }
                else {
                        /* we can borrow from the file in the work tree */
@@@ -3596,6 -3590,7 +3596,7 @@@ static char *run_textconv(const char *p
        if (start_command(&child) != 0 ||
            strbuf_read(&buf, child.out, 0) < 0 ||
            finish_command(&child) != 0) {
+               strbuf_release(&buf);
                remove_tempfile();
                error("error running textconv command '%s'", pgm);
                return NULL;