Merge branch 'sb/misc-cleanups'
authorJunio C Hamano <gitster@pobox.com>
Wed, 13 Apr 2016 21:12:34 +0000 (14:12 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Apr 2016 21:12:34 +0000 (14:12 -0700)
Assorted minor clean-ups.

* sb/misc-cleanups:
credential-cache, send_request: close fd when done
bundle: don't leak an fd in case of early return
abbrev_sha1_in_line: don't leak memory
notes: don't leak memory in git_config_get_notes_strategy

1  2 
builtin/notes.c
wt-status.c
diff --combined builtin/notes.c
index ed6f2222f4bf9c54535a7a23971c7749ca8d05d5,afcfa8f52205ef841499489f7f103e7ce907b83e..6fd058de9272631a3d5135ccbbd79bf1b4ff135c
@@@ -286,11 -286,11 +286,11 @@@ static int notes_copy_from_stdin(int fo
                if (!c)
                        return 0;
        } else {
 -              init_notes(NULL, NULL, NULL, 0);
 +              init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
                t = &default_notes_tree;
        }
  
 -      while (strbuf_getline(&buf, stdin, '\n') != EOF) {
 +      while (strbuf_getline_lf(&buf, stdin) != EOF) {
                unsigned char from_obj[20], to_obj[20];
                struct strbuf **split;
                int err;
        return ret;
  }
  
 -static struct notes_tree *init_notes_check(const char *subcommand)
 +static struct notes_tree *init_notes_check(const char *subcommand,
 +                                         int flags)
  {
        struct notes_tree *t;
 -      init_notes(NULL, NULL, NULL, 0);
 +      const char *ref;
 +      init_notes(NULL, NULL, NULL, flags);
        t = &default_notes_tree;
  
 -      if (!starts_with(t->ref, "refs/notes/"))
 +      ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
 +      if (!starts_with(ref, "refs/notes/"))
                die("Refusing to %s notes in %s (outside of refs/notes/)",
 -                  subcommand, t->ref);
 +                  subcommand, ref);
        return t;
  }
  
@@@ -363,7 -360,7 +363,7 @@@ static int list(int argc, const char **
                usage_with_options(git_notes_list_usage, options);
        }
  
 -      t = init_notes_check("list");
 +      t = init_notes_check("list", 0);
        if (argc) {
                if (get_sha1(argv[0], object))
                        die(_("Failed to resolve '%s' as a valid ref."), argv[0]);
@@@ -423,7 -420,7 +423,7 @@@ static int add(int argc, const char **a
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
 -      t = init_notes_check("add");
 +      t = init_notes_check("add", NOTES_INIT_WRITABLE);
        note = get_note(t, object);
  
        if (note) {
@@@ -514,7 -511,7 +514,7 @@@ static int copy(int argc, const char **
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
 -      t = init_notes_check("copy");
 +      t = init_notes_check("copy", NOTES_INIT_WRITABLE);
        note = get_note(t, object);
  
        if (note) {
@@@ -592,7 -589,7 +592,7 @@@ static int append_edit(int argc, const 
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
 -      t = init_notes_check(argv[0]);
 +      t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
        note = get_note(t, object);
  
        prepare_note_data(object, &d, edit ? note : NULL);
@@@ -655,7 -652,7 +655,7 @@@ static int show(int argc, const char **
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
 -      t = init_notes_check("show");
 +      t = init_notes_check("show", 0);
        note = get_note(t, object);
  
        if (!note)
@@@ -744,13 -741,14 +744,14 @@@ static int merge_commit(struct notes_me
  static int git_config_get_notes_strategy(const char *key,
                                         enum notes_merge_strategy *strategy)
  {
-       const char *value;
+       char *value;
  
-       if (git_config_get_string_const(key, &value))
+       if (git_config_get_string(key, &value))
                return 1;
        if (parse_notes_merge_strategy(value, strategy))
                git_die_config(key, "unknown notes merge strategy %s", value);
  
+       free(value);
        return 0;
  }
  
@@@ -809,10 -807,10 +810,10 @@@ static int merge(int argc, const char *
  
        o.local_ref = default_notes_ref();
        strbuf_addstr(&remote_ref, argv[0]);
 -      expand_notes_ref(&remote_ref);
 +      expand_loose_notes_ref(&remote_ref);
        o.remote_ref = remote_ref.buf;
  
 -      t = init_notes_check("merge");
 +      t = init_notes_check("merge", NOTES_INIT_WRITABLE);
  
        if (strategy) {
                if (parse_notes_merge_strategy(strategy, &o.strategy)) {
@@@ -904,7 -902,7 +905,7 @@@ static int remove_cmd(int argc, const c
        argc = parse_options(argc, argv, prefix, options,
                             git_notes_remove_usage, 0);
  
 -      t = init_notes_check("remove");
 +      t = init_notes_check("remove", NOTES_INIT_WRITABLE);
  
        if (!argc && !from_stdin) {
                retval = remove_one_note(t, "HEAD", flag);
@@@ -946,7 -944,7 +947,7 @@@ static int prune(int argc, const char *
                usage_with_options(git_notes_prune_usage, options);
        }
  
 -      t = init_notes_check("prune");
 +      t = init_notes_check("prune", NOTES_INIT_WRITABLE);
  
        prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
                (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
diff --combined wt-status.c
index ef7486474a1eafb7d5d1344323cd6abf012c31db,9f4be333d451b01ea2d40d17e41f887a300afee2..1ea2ebe4c00d23885515ac48f43844fdb03f70b9
@@@ -988,7 -988,7 +988,7 @@@ static char *read_line_from_git_path(co
                strbuf_release(&buf);
                return NULL;
        }
 -      strbuf_getline(&buf, fp, '\n');
 +      strbuf_getline_lf(&buf, fp);
        if (!fclose(fp)) {
                return strbuf_detach(&buf, NULL);
        } else {
@@@ -1063,9 -1063,7 +1063,7 @@@ static void abbrev_sha1_in_line(struct 
                                strbuf_addf(line, "%s", split[i]->buf);
                }
        }
-       for (i = 0; split[i]; i++)
-               strbuf_release(split[i]);
+       strbuf_list_free(split);
  }
  
  static void read_rebase_todolist(const char *fname, struct string_list *lines)
        if (!f)
                die_errno("Could not open file %s for reading",
                          git_path("%s", fname));
 -      while (!strbuf_getline(&line, f, '\n')) {
 +      while (!strbuf_getline_lf(&line, f)) {
                if (line.len && line.buf[0] == comment_line_char)
                        continue;
                strbuf_trim(&line);
@@@ -1677,10 -1675,10 +1675,10 @@@ static void wt_shortstatus_print_tracki
                color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
        } else if (!num_theirs) {
 -              color_fprintf(s->fp, header_color, LABEL(N_(("ahead "))));
 +              color_fprintf(s->fp, header_color, LABEL(N_("ahead ")));
                color_fprintf(s->fp, branch_color_local, "%d", num_ours);
        } else {
 -              color_fprintf(s->fp, header_color, LABEL(N_(("ahead "))));
 +              color_fprintf(s->fp, header_color, LABEL(N_("ahead ")));
                color_fprintf(s->fp, branch_color_local, "%d", num_ours);
                color_fprintf(s->fp, header_color, ", %s", LABEL(N_("behind ")));
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);