Merge branch 'bc/object-id'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2016 21:45:44 +0000 (14:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2016 21:45:44 +0000 (14:45 -0700)
Move from unsigned char[20] to struct object_id continues.

* bc/object-id:
match-trees: convert several leaf functions to use struct object_id
tree-walk: convert tree_entry_extract() to use struct object_id
struct name_entry: use struct object_id instead of unsigned char sha1[20]
match-trees: convert shift_tree() and shift_tree_by() to use object_id
test-match-trees: convert to use struct object_id
sha1-name: introduce a get_oid() function

1  2 
builtin/grep.c
cache.h
http-push.c
merge-recursive.c
revision.c
sha1_name.c
t/helper/test-match-trees.c
diff --combined builtin/grep.c
index 111b6f6cf1a61b0fb481101fcdc5a9f3f48c4650,b15020067b3a48e62e7b27fe66793ff584a453a3..462e60790165a333d58d81ec65ae4ae6da8d4f79
@@@ -438,7 -438,7 +438,7 @@@ static int grep_tree(struct grep_opt *o
                strbuf_add(base, entry.path, te_len);
  
                if (S_ISREG(entry.mode)) {
-                       hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,
+                       hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,
                                         check_attr ? base->buf + tn_len : NULL);
                }
                else if (S_ISDIR(entry.mode)) {
                        void *data;
                        unsigned long size;
  
-                       data = lock_and_read_sha1_file(entry.sha1, &type, &size);
+                       data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
                        if (!data)
                                die(_("unable to read tree (%s)"),
-                                   sha1_to_hex(entry.sha1));
+                                   oid_to_hex(entry.oid));
  
                        strbuf_addch(base, '/');
                        init_tree_desc(&sub, data, size);
@@@ -522,14 -522,12 +522,14 @@@ static int grep_objects(struct grep_op
  }
  
  static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
 -                        int exc_std)
 +                        int exc_std, int use_index)
  {
        struct dir_struct dir;
        int i, hit = 0;
  
        memset(&dir, 0, sizeof(dir));
 +      if (!use_index)
 +              dir.flags |= DIR_NO_GITLINKS;
        if (exc_std)
                setup_standard_excludes(&dir);
  
@@@ -904,7 -902,7 +904,7 @@@ int cmd_grep(int argc, const char **arg
                int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
                if (list.nr)
                        die(_("--no-index or --untracked cannot be used with revs."));
 -              hit = grep_directory(&opt, &pathspec, use_exclude);
 +              hit = grep_directory(&opt, &pathspec, use_exclude, use_index);
        } else if (0 <= opt_exclude) {
                die(_("--[no-]exclude-standard cannot be used for tracked contents."));
        } else if (!list.nr) {
diff --combined cache.h
index fd728f079320cb05bb01bb9a5764fcb0943a1f19,33584119049c91b5e739979004855c39e2cf5fc8..160f8e32e31a4ebd832f96fcdc55a6063aa30dab
+++ b/cache.h
@@@ -651,6 -651,7 +651,6 @@@ extern int prefer_symlink_refs
  extern int log_all_ref_updates;
  extern int warn_ambiguous_refs;
  extern int warn_on_object_refname_ambiguity;
 -extern int shared_repository;
  extern const char *apply_default_whitespace;
  extern const char *apply_default_ignorewhitespace;
  extern const char *git_attributes_file;
@@@ -663,9 -664,6 +663,9 @@@ extern size_t delta_base_cache_limit
  extern unsigned long big_file_threshold;
  extern unsigned long pack_size_limit_cfg;
  
 +void set_shared_repository(int value);
 +int get_shared_repository(void);
 +
  /*
   * Do replace refs need to be checked this run?  This variable is
   * initialized to true unless --no-replace-object is used or
@@@ -747,39 -745,9 +747,39 @@@ extern int grafts_replace_parents
   */
  #define GIT_REPO_VERSION 0
  #define GIT_REPO_VERSION_READ 1
 -extern int repository_format_version;
  extern int repository_format_precious_objects;
 -extern int check_repository_format(void);
 +
 +struct repository_format {
 +      int version;
 +      int precious_objects;
 +      int is_bare;
 +      char *work_tree;
 +      struct string_list unknown_extensions;
 +};
 +
 +/*
 + * Read the repository format characteristics from the config file "path" into
 + * "format" struct. Returns the numeric version. On error, -1 is returned,
 + * format->version is set to -1, and all other fields in the struct are
 + * undefined.
 + */
 +int read_repository_format(struct repository_format *format, const char *path);
 +
 +/*
 + * Verify that the repository described by repository_format is something we
 + * can read. If it is, return 0. Otherwise, return -1, and "err" will describe
 + * any errors encountered.
 + */
 +int verify_repository_format(const struct repository_format *format,
 +                           struct strbuf *err);
 +
 +/*
 + * Check the repository format version in the path found in get_git_dir(),
 + * and die if it is a version we don't understand. Generally one would
 + * set_git_dir() before calling this, and use it only for "are we in a valid
 + * repo?".
 + */
 +extern void check_repository_format(void);
  
  #define MTIME_CHANGED 0x0001
  #define CTIME_CHANGED 0x0002
@@@ -958,6 -926,8 +958,6 @@@ static inline int is_empty_blob_sha1(co
  
  int git_mkstemp(char *path, size_t n, const char *template);
  
 -int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
 -
  /* set default permissions by passing mode arguments to open(2) */
  int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
  int git_mkstemp_mode(char *pattern, int mode);
@@@ -1154,6 -1124,8 +1154,8 @@@ extern int get_sha1_blob(const char *st
  extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
  extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);
  
+ extern int get_oid(const char *str, struct object_id *oid);
  typedef int each_abbrev_fn(const unsigned char *sha1, void *);
  extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
  
@@@ -1556,6 -1528,7 +1558,6 @@@ extern void git_config(config_fn_t fn, 
  extern int git_config_with_options(config_fn_t fn, void *,
                                   struct git_config_source *config_source,
                                   int respect_includes);
 -extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
  extern int git_parse_ulong(const char *, unsigned long *);
  extern int git_parse_maybe_bool(const char *);
  extern int git_config_int(const char *, const char *);
@@@ -1579,6 -1552,7 +1581,6 @@@ extern void git_config_set_multivar_in_
  extern int git_config_rename_section(const char *, const char *);
  extern int git_config_rename_section_in_file(const char *, const char *, const char *);
  extern const char *git_etc_gitconfig(void);
 -extern int check_repository_format_version(const char *var, const char *value, void *cb);
  extern int git_env_bool(const char *, int);
  extern unsigned long git_env_ulong(const char *, unsigned long);
  extern int git_config_system(void);
@@@ -1764,8 -1738,8 +1766,8 @@@ int add_files_to_cache(const char *pref
  extern int diff_auto_refresh_index;
  
  /* match-trees.c */
- void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
- void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);
+ void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
+ void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
  
  /*
   * whitespace rules.
@@@ -1799,7 -1773,7 +1801,7 @@@ int split_cmdline(char *cmdline, const 
  /* Takes a negative value returned by split_cmdline */
  const char *split_cmdline_strerror(int cmdline_errno);
  
 -/* git.c */
 +/* setup.c */
  struct startup_info {
        int have_repository;
        const char *prefix;
diff --combined http-push.c
index ae2b7f19d2499d9043e3c73b74bc9aa274fc2653,ded0b742adffe3b3038f900e2b9e9f6b819cc0e9..a092f0288bd6944be036a1a051a0954216c382e6
@@@ -211,7 -211,7 +211,7 @@@ static void curl_setup_http(CURL *curl
  static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)
  {
        struct strbuf buf = STRBUF_INIT;
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers = http_copy_default_headers();
  
        if (options & DAV_HEADER_IF) {
                strbuf_addf(&buf, "If: (<%s>)", lock->token);
@@@ -417,7 -417,7 +417,7 @@@ static void start_put(struct transfer_r
  static void start_move(struct transfer_request *request)
  {
        struct active_request_slot *slot;
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers = http_copy_default_headers();
  
        slot = get_active_slot();
        slot->callback_func = process_response;
@@@ -845,7 -845,7 +845,7 @@@ static struct remote_lock *lock_remote(
        char *ep;
        char timeout_header[25];
        struct remote_lock *lock = NULL;
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        char *escaped;
  
@@@ -1126,7 -1126,7 +1126,7 @@@ static void remote_ls(const char *path
        struct slot_results results;
        struct strbuf in_buffer = STRBUF_INIT;
        struct buffer out_buffer = { STRBUF_INIT, 0 };
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        struct remote_ls_ctx ls;
  
@@@ -1204,7 -1204,7 +1204,7 @@@ static int locking_available(void
        struct slot_results results;
        struct strbuf in_buffer = STRBUF_INIT;
        struct buffer out_buffer = { STRBUF_INIT, 0 };
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        int lock_flags = 0;
        char *escaped;
@@@ -1312,10 -1312,10 +1312,10 @@@ static struct object_list **process_tre
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(entry.sha1), p);
+                       p = process_tree(lookup_tree(entry.oid->hash), p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(entry.sha1), p);
+                       p = process_blob(lookup_blob(entry.oid->hash), p);
                        break;
                default:
                        /* Subproject commit - not in this repository */
diff --combined merge-recursive.c
index 06d31ed8734cab9e2641779e7135c0576d222b4a,a47c80f87596b9b20afb644a5a238e4ebf2f2a3c..65cb5d6c1f59d635e44a0fea648e39a976c0eaf0
@@@ -29,9 -29,9 +29,9 @@@ static struct tree *shift_tree_object(s
        struct object_id shifted;
  
        if (!*subtree_shift) {
-               shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);
+               shift_tree(&one->object.oid, &two->object.oid, &shifted, 0);
        } else {
-               shift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,
+               shift_tree_by(&one->object.oid, &two->object.oid, &shifted,
                              subtree_shift);
        }
        if (!oidcmp(&two->object.oid, &shifted))
@@@ -622,7 -622,7 +622,7 @@@ static char *unique_path(struct merge_o
        base_len = newpath.len;
        while (string_list_has_string(&o->current_file_set, newpath.buf) ||
               string_list_has_string(&o->current_directory_set, newpath.buf) ||
 -             file_exists(newpath.buf)) {
 +             (!o->call_depth && file_exists(newpath.buf))) {
                strbuf_setlen(&newpath, base_len);
                strbuf_addf(&newpath, "_%d", suffix++);
        }
@@@ -1234,8 -1234,8 +1234,8 @@@ static void conflict_rename_rename_2to1
               a->path, c1->path, ci->branch1,
               b->path, c2->path, ci->branch2);
  
 -      remove_file(o, 1, a->path, would_lose_untracked(a->path));
 -      remove_file(o, 1, b->path, would_lose_untracked(b->path));
 +      remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
 +      remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
  
        mfi_c1 = merge_file_special_markers(o, a, c1, &ci->ren1_other,
                                            o->branch1, c1->path,
@@@ -1773,6 -1773,8 +1773,6 @@@ static int process_entry(struct merge_o
                        output(o, 1, _("CONFLICT (%s): There is a directory with name %s in %s. "
                               "Adding %s as %s"),
                               conf, path, other_branch, path, new_path);
 -                      if (o->call_depth)
 -                              remove_file_from_cache(path);
                        update_file(o, 0, sha, mode, new_path);
                        if (o->call_depth)
                                remove_file_from_cache(path);
diff --combined revision.c
index b683476b9c44b90a6dc2acd5cf1f725f741fbaa3,a356dde09efc749b2bc4173e7fb129a6ccee5519..d30d1c4f802c77a47df0078f49247457bf22c1a3
@@@ -59,10 -59,10 +59,10 @@@ static void mark_tree_contents_unintere
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       mark_tree_uninteresting(lookup_tree(entry.sha1));
+                       mark_tree_uninteresting(lookup_tree(entry.oid->hash));
                        break;
                case OBJ_BLOB:
-                       mark_blob_uninteresting(lookup_blob(entry.sha1));
+                       mark_blob_uninteresting(lookup_blob(entry.oid->hash));
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@@ -1356,10 -1356,8 +1356,10 @@@ void init_revisions(struct rev_info *re
        revs->skip_count = -1;
        revs->max_count = -1;
        revs->max_parents = -1;
 +      revs->expand_tabs_in_log = -1;
  
        revs->commit_format = CMIT_FMT_DEFAULT;
 +      revs->expand_tabs_in_log_default = 8;
  
        init_grep_defaults();
        grep_init(&revs->grep_filter, prefix);
@@@ -1856,15 -1854,6 +1856,15 @@@ static int handle_revision_opt(struct r
                revs->verbose_header = 1;
                revs->pretty_given = 1;
                get_commit_format(arg+9, revs);
 +      } else if (!strcmp(arg, "--expand-tabs")) {
 +              revs->expand_tabs_in_log = 8;
 +      } else if (!strcmp(arg, "--no-expand-tabs")) {
 +              revs->expand_tabs_in_log = 0;
 +      } else if (skip_prefix(arg, "--expand-tabs=", &arg)) {
 +              int val;
 +              if (strtol_i(arg, 10, &val) < 0 || val < 0)
 +                      die("'%s': not a non-negative integer", arg);
 +              revs->expand_tabs_in_log = val;
        } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
                revs->show_notes = 1;
                revs->show_notes_given = 1;
@@@ -2338,9 -2327,6 +2338,9 @@@ int setup_revisions(int argc, const cha
        if (revs->first_parent_only && revs->bisect)
                die(_("--first-parent is incompatible with --bisect"));
  
 +      if (revs->expand_tabs_in_log < 0)
 +              revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
 +
        return left;
  }
  
diff --combined sha1_name.c
index 776101e8d709b924033a141efa38e3f734837c79,1ae20fec15bed85e5e09a76cf5376ed436977313..ca7ddd6f2cf7074a1d74e011c2bd260c2ae6ffe6
@@@ -1214,6 -1214,15 +1214,15 @@@ int get_sha1(const char *name, unsigne
        return get_sha1_with_context(name, 0, sha1, &unused);
  }
  
+ /*
+  * This is like "get_sha1()", but for struct object_id.
+  */
+ int get_oid(const char *name, struct object_id *oid)
+ {
+       return get_sha1(name, oid->hash);
+ }
  /*
   * Many callers know that the user meant to name a commit-ish by
   * syntactical positions where the object name appears.  Calling this
@@@ -1353,6 -1362,9 +1362,6 @@@ static char *resolve_relative_path(cons
        if (!starts_with(rel, "./") && !starts_with(rel, "../"))
                return NULL;
  
 -      if (!startup_info)
 -              die("BUG: startup_info struct is not initialized.");
 -
        if (!is_inside_work_tree())
                die("relative path syntax can't be used outside working tree.");
  
index 4dad7095f10bb324f043ff8132678488b65d4537,0000000000000000000000000000000000000000..d446b8eaca727dfa9c1b0928f2b8c9af286f2702
mode 100644,000000..100644
--- /dev/null
@@@ -1,26 -1,0 +1,26 @@@
-       unsigned char hash1[20], hash2[20], shifted[20];
 +#include "cache.h"
 +#include "tree.h"
 +
 +int main(int ac, char **av)
 +{
-       if (get_sha1(av[1], hash1))
++      struct object_id hash1, hash2, shifted;
 +      struct tree *one, *two;
 +
 +      setup_git_directory();
 +
-       if (get_sha1(av[2], hash2))
++      if (get_oid(av[1], &hash1))
 +              die("cannot parse %s as an object name", av[1]);
-       one = parse_tree_indirect(hash1);
++      if (get_oid(av[2], &hash2))
 +              die("cannot parse %s as an object name", av[2]);
-       two = parse_tree_indirect(hash2);
++      one = parse_tree_indirect(hash1.hash);
 +      if (!one)
 +              die("not a tree-ish %s", av[1]);
-       shift_tree(one->object.oid.hash, two->object.oid.hash, shifted, -1);
-       printf("shifted: %s\n", sha1_to_hex(shifted));
++      two = parse_tree_indirect(hash2.hash);
 +      if (!two)
 +              die("not a tree-ish %s", av[2]);
 +
++      shift_tree(&one->object.oid, &two->object.oid, &shifted, -1);
++      printf("shifted: %s\n", oid_to_hex(&shifted));
 +
 +      exit(0);
 +}