Merge branch 'ta/string-list-init'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Jul 2014 18:35:54 +0000 (11:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jul 2014 18:35:54 +0000 (11:35 -0700)
* ta/string-list-init:
replace memset with string-list initializers
string-list: add string_list initializer helper function

1  2 
builtin/commit.c
merge-recursive.c
submodule.c
transport.c
diff --combined builtin/commit.c
index f2d7979deb9438ab388e2cefff613b1f8d6d3c56,023df406f836b5709cbd85396a6c9bd70cbcdefb..5ed60364ce5eb1f458e1f5155d76abd7341d24ea
@@@ -305,6 -305,7 +305,6 @@@ static void refresh_cache_or_die(int re
  static char *prepare_index(int argc, const char **argv, const char *prefix,
                           const struct commit *current_head, int is_status)
  {
 -      int fd;
        struct string_list partial;
        struct pathspec pathspec;
        int refresh_flags = REFRESH_QUIET;
  
        if (interactive) {
                char *old_index_env = NULL;
 -              fd = hold_locked_index(&index_lock, 1);
 +              hold_locked_index(&index_lock, 1);
  
                refresh_cache_or_die(refresh_flags);
  
 -              if (write_cache(fd, active_cache, active_nr) ||
 -                  close_lock_file(&index_lock))
 +              if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to create temporary index"));
  
                old_index_env = getenv(INDEX_ENVIRONMENT);
         * (B) on failure, rollback the real index.
         */
        if (all || (also && pathspec.nr)) {
 -              fd = hold_locked_index(&index_lock, 1);
 +              hold_locked_index(&index_lock, 1);
                add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
                refresh_cache_or_die(refresh_flags);
                update_main_cache_tree(WRITE_TREE_SILENT);
 -              if (write_cache(fd, active_cache, active_nr) ||
 -                  close_lock_file(&index_lock))
 +              if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                        die(_("unable to write new_index file"));
                commit_style = COMMIT_NORMAL;
                return index_lock.filename;
         * We still need to refresh the index here.
         */
        if (!only && !pathspec.nr) {
 -              fd = hold_locked_index(&index_lock, 1);
 +              hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
                if (active_cache_changed) {
                        update_main_cache_tree(WRITE_TREE_SILENT);
 -                      if (write_cache(fd, active_cache, active_nr) ||
 -                          commit_locked_index(&index_lock))
 +                      if (write_locked_index(&the_index, &index_lock,
 +                                             COMMIT_LOCK))
                                die(_("unable to write new_index file"));
                } else {
                        rollback_lock_file(&index_lock);
                        die(_("cannot do a partial commit during a cherry-pick."));
        }
  
-       memset(&partial, 0, sizeof(partial));
-       partial.strdup_strings = 1;
+       string_list_init(&partial, 1);
        if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
                exit(1);
  
        if (read_cache() < 0)
                die(_("cannot read the index"));
  
 -      fd = hold_locked_index(&index_lock, 1);
 +      hold_locked_index(&index_lock, 1);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
 -      if (write_cache(fd, active_cache, active_nr) ||
 -          close_lock_file(&index_lock))
 +      if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                die(_("unable to write new_index file"));
  
 -      fd = hold_lock_file_for_update(&false_lock,
 -                                     git_path("next-index-%"PRIuMAX,
 -                                              (uintmax_t) getpid()),
 -                                     LOCK_DIE_ON_ERROR);
 +      hold_lock_file_for_update(&false_lock,
 +                                git_path("next-index-%"PRIuMAX,
 +                                         (uintmax_t) getpid()),
 +                                LOCK_DIE_ON_ERROR);
  
        create_base_index(current_head);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
  
 -      if (write_cache(fd, active_cache, active_nr) ||
 -          close_lock_file(&false_lock))
 +      if (write_locked_index(&the_index, &false_lock, CLOSE_LOCK))
                die(_("unable to write temporary index file"));
  
        discard_cache();
@@@ -702,7 -706,7 +701,7 @@@ static int prepare_to_commit(const cha
                char *buffer;
                buffer = strstr(use_message_buffer, "\n\n");
                if (buffer)
 -                      strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
 +                      strbuf_addstr(&sb, buffer + 2);
                hook_arg1 = "commit";
                hook_arg2 = use_message;
        } else if (fixup_message) {
diff --combined merge-recursive.c
index 5814d056ff9fdfad6de5a748806cf307b1e5d388,4b648d9afb97c2837c066603bc9dd9f4c1e8839e..1d332b8bbbf076b819e2052c84874fb0728dae02
@@@ -171,7 -171,7 +171,7 @@@ static void output(struct merge_option
        strbuf_vaddf(&o->obuf, fmt, ap);
        va_end(ap);
  
 -      strbuf_add(&o->obuf, "\n", 1);
 +      strbuf_addch(&o->obuf, '\n');
        if (!o->buffer_output)
                flush_output(o);
  }
@@@ -267,7 -267,9 +267,7 @@@ struct tree *write_tree_from_memory(str
                active_cache_tree = cache_tree();
  
        if (!cache_tree_fully_valid(active_cache_tree) &&
 -          cache_tree_update(active_cache_tree,
 -                            (const struct cache_entry * const *)active_cache,
 -                            active_nr, 0) < 0)
 +          cache_tree_update(&the_index, 0) < 0)
                die(_("error building trees"));
  
        result = lookup_tree(active_cache_tree->sha1);
@@@ -1999,7 -2001,7 +1999,7 @@@ int merge_recursive_generic(struct merg
                            const unsigned char **base_list,
                            struct commit **result)
  {
 -      int clean, index_fd;
 +      int clean;
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
        struct commit *head_commit = get_ref(head, o->branch1);
        struct commit *next_commit = get_ref(merge, o->branch2);
                }
        }
  
 -      index_fd = hold_locked_index(lock, 1);
 +      hold_locked_index(lock, 1);
        clean = merge_recursive(o, head_commit, next_commit, ca,
                        result);
        if (active_cache_changed &&
 -                      (write_cache(index_fd, active_cache, active_nr) ||
 -                       commit_locked_index(lock)))
 +          write_locked_index(&the_index, lock, COMMIT_LOCK))
                return error(_("Unable to write index."));
  
        return clean ? 0 : 1;
@@@ -2059,12 -2062,9 +2059,9 @@@ void init_merge_options(struct merge_op
        if (o->verbosity >= 5)
                o->buffer_output = 0;
        strbuf_init(&o->obuf, 0);
-       memset(&o->current_file_set, 0, sizeof(struct string_list));
-       o->current_file_set.strdup_strings = 1;
-       memset(&o->current_directory_set, 0, sizeof(struct string_list));
-       o->current_directory_set.strdup_strings = 1;
-       memset(&o->df_conflict_file_set, 0, sizeof(struct string_list));
-       o->df_conflict_file_set.strdup_strings = 1;
+       string_list_init(&o->current_file_set, 1);
+       string_list_init(&o->current_directory_set, 1);
+       string_list_init(&o->df_conflict_file_set, 1);
  }
  
  int parse_merge_opt(struct merge_options *o, const char *s)
diff --combined submodule.c
index 48e3b44e219dffec6f435f0f25f1b74409fa29a9,2fe2ad8ee41aefa3108f7a51861df0a389a56b68..c3a61e70f9f72eced2530d425717972881b947c8
@@@ -544,10 -544,7 +544,7 @@@ static int push_submodule(const char *p
  int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name)
  {
        int i, ret = 1;
-       struct string_list needs_pushing;
-       memset(&needs_pushing, 0, sizeof(struct string_list));
-       needs_pushing.strdup_strings = 1;
+       struct string_list needs_pushing = STRING_LIST_INIT_DUP;
  
        if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing))
                return 1;
@@@ -965,7 -962,7 +962,7 @@@ static int find_first_merges(struct obj
                        sha1_to_hex(a->object.sha1));
        init_revisions(&revs, NULL);
        rev_opts.submodule = path;
 -      setup_revisions(sizeof(rev_args)/sizeof(char *)-1, rev_args, &revs, &rev_opts);
 +      setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
  
        /* save all revisions from the above list that contain b */
        if (prepare_revision_walk(&revs))
diff --combined transport.c
index 3e425709fded6e384add10aeff7f19455259ff46,d32aaf201cb092be71585ca048f44891041ed7b7..80ed1262c29e8e3ec1443e06383c4ee9b7d14173
@@@ -263,20 -263,32 +263,20 @@@ static struct ref *get_refs_via_rsync(s
  static int fetch_objs_via_rsync(struct transport *transport,
                                int nr_objs, struct ref **to_fetch)
  {
 -      struct strbuf buf = STRBUF_INIT;
        struct child_process rsync;
 -      const char *args[8];
 -      int result;
 -
 -      strbuf_addstr(&buf, rsync_url(transport->url));
 -      strbuf_addstr(&buf, "/objects/");
  
        memset(&rsync, 0, sizeof(rsync));
 -      rsync.argv = args;
        rsync.stdout_to_stderr = 1;
 -      args[0] = "rsync";
 -      args[1] = (transport->verbose > 1) ? "-rv" : "-r";
 -      args[2] = "--ignore-existing";
 -      args[3] = "--exclude";
 -      args[4] = "info";
 -      args[5] = buf.buf;
 -      args[6] = get_object_directory();
 -      args[7] = NULL;
 +      argv_array_push(&rsync.args, "rsync");
 +      argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r");
 +      argv_array_push(&rsync.args, "--ignore-existing");
 +      argv_array_push(&rsync.args, "--exclude");
 +      argv_array_push(&rsync.args, "info");
 +      argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url));
 +      argv_array_push(&rsync.args, get_object_directory());
  
        /* NEEDSWORK: handle one level of alternates */
 -      result = run_command(&rsync);
 -
 -      strbuf_release(&buf);
 -
 -      return result;
 +      return run_command(&rsync);
  }
  
  static int write_one_ref(const char *name, const unsigned char *sha1,
@@@ -1176,10 -1188,8 +1176,8 @@@ int transport_push(struct transport *tr
                if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
                              TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
                        struct ref *ref = remote_refs;
-                       struct string_list needs_pushing;
+                       struct string_list needs_pushing = STRING_LIST_INIT_DUP;
  
-                       memset(&needs_pushing, 0, sizeof(struct string_list));
-                       needs_pushing.strdup_strings = 1;
                        for (; ref; ref = ref->next)
                                if (!is_null_sha1(ref->new_sha1) &&
                                    find_unpushed_submodules(ref->new_sha1,