]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'bc/object-id'
authorJunio C Hamano <gitster@pobox.com>
Fri, 17 Mar 2017 20:50:24 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Mar 2017 20:50:25 +0000 (13:50 -0700)
"uchar [40]" to "struct object_id" conversion continues.

* bc/object-id:
  wt-status: convert to struct object_id
  builtin/merge-base: convert to struct object_id
  Convert object iteration callbacks to struct object_id
  sha1_file: introduce an nth_packed_object_oid function
  refs: simplify parsing of reflog entries
  refs: convert each_reflog_ent_fn to struct object_id
  reflog-walk: convert struct reflog_info to struct object_id
  builtin/replace: convert to struct object_id
  Convert remaining callers of resolve_refdup to object_id
  builtin/merge: convert to struct object_id
  builtin/clone: convert to struct object_id
  builtin/branch: convert to struct object_id
  builtin/grep: convert to struct object_id
  builtin/fmt-merge-message: convert to struct object_id
  builtin/fast-export: convert to struct object_id
  builtin/describe: convert to struct object_id
  builtin/diff-tree: convert to struct object_id
  builtin/commit: convert to struct object_id
  hex: introduce parse_oid_hex

18 files changed:
1  2 
builtin/branch.c
builtin/describe.c
builtin/diff-tree.c
builtin/grep.c
builtin/merge.c
builtin/notes.c
builtin/pack-objects.c
builtin/receive-pack.c
builtin/replace.c
cache.h
ref-filter.c
refs.c
refs.h
refs/files-backend.c
revision.c
sha1_file.c
sha1_name.c
transport.c

index 5d44e36cba0e030cb77461784a65f77c44cb67cd,faf472ff8f091306ef3ee528662b45bb693393c4..52688f2e1be91024ba6cb170b4b38b393e8ab8ba
@@@ -255,7 -251,7 +255,7 @@@ static int delete_branches(int argc, co
                        goto next;
                }
  
-               if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1,
 -              if (delete_ref(name, is_null_oid(&oid) ? NULL : oid.hash,
++              if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
                               REF_NODEREF)) {
                        error(remote_branch
                              ? _("Error deleting remote-tracking branch '%s'")
Simple merge
Simple merge
diff --cc builtin/grep.c
index 9304c33e75051baa65ee02d1daa03c361e25339e,0393b0fdc47467ddf10acdd830b910b58a1accd7..837836fb3e3bf9cdeb25edf8789428aaf813f49d
@@@ -1150,69 -1149,26 +1150,69 @@@ int cmd_grep(int argc, const char **arg
  
        compile_grep_patterns(&opt);
  
 -      /* Check revs and then paths */
 +      /*
 +       * We have to find "--" in a separate pass, because its presence
 +       * influences how we will parse arguments that come before it.
 +       */
 +      for (i = 0; i < argc; i++) {
 +              if (!strcmp(argv[i], "--")) {
 +                      seen_dashdash = 1;
 +                      break;
 +              }
 +      }
 +
 +      /*
 +       * Resolve any rev arguments. If we have a dashdash, then everything up
 +       * to it must resolve as a rev. If not, then we stop at the first
 +       * non-rev and assume everything else is a path.
 +       */
 +      allow_revs = use_index && !untracked;
        for (i = 0; i < argc; i++) {
                const char *arg = argv[i];
-               unsigned char sha1[20];
+               struct object_id oid;
                struct object_context oc;
 -              /* Is it a rev? */
 -              if (!get_sha1_with_context(arg, 0, oid.hash, &oc)) {
 -                      struct object *object = parse_object_or_die(oid.hash, arg);
 -                      if (!seen_dashdash)
 -                              verify_non_filename(prefix, arg);
 -                      add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
 -                      continue;
 -              }
 +              struct object *object;
 +
                if (!strcmp(arg, "--")) {
                        i++;
 -                      seen_dashdash = 1;
 +                      break;
                }
 -              break;
 +
 +              if (!allow_revs) {
 +                      if (seen_dashdash)
 +                              die(_("--no-index or --untracked cannot be used with revs"));
 +                      break;
 +              }
 +
-               if (get_sha1_with_context(arg, 0, sha1, &oc)) {
++              if (get_sha1_with_context(arg, 0, oid.hash, &oc)) {
 +                      if (seen_dashdash)
 +                              die(_("unable to resolve revision: %s"), arg);
 +                      break;
 +              }
 +
-               object = parse_object_or_die(sha1, arg);
++              object = parse_object_or_die(oid.hash, arg);
 +              if (!seen_dashdash)
 +                      verify_non_filename(prefix, arg);
 +              add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
        }
  
 +      /*
 +       * Anything left over is presumed to be a path. But in the non-dashdash
 +       * "do what I mean" case, we verify and complain when that isn't true.
 +       */
 +      if (!seen_dashdash) {
 +              int j;
 +              for (j = i; j < argc; j++)
 +                      verify_filename(prefix, argv[j], j == i && allow_revs);
 +      }
 +
 +      parse_pathspec(&pathspec, 0,
 +                     PATHSPEC_PREFER_CWD |
 +                     (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0),
 +                     prefix, argv + i);
 +      pathspec.max_depth = opt.max_depth;
 +      pathspec.recursive = 1;
 +
  #ifndef NO_PTHREADS
        if (list.nr || cached || show_in_pager)
                num_threads = 0;
diff --cc builtin/merge.c
index 848a29855611d22bf19f3740a577a2b312294257,099cfab447672612892f3c2297d2667f6f79b7b1..7554b8d4127ada8261d1f913c6215e93ca42ef7d
@@@ -438,10 -438,10 +438,10 @@@ static void merge_name(const char *remo
        char *found_ref;
        int len, early;
  
 -      strbuf_branchname(&bname, remote);
 +      strbuf_branchname(&bname, remote, 0);
        remote = bname.buf;
  
-       memset(branch_head, 0, sizeof(branch_head));
+       oidclr(&branch_head);
        remote_head = get_merge_parent(remote);
        if (!remote_head)
                die(_("'%s' does not point to a commit"), remote);
diff --cc builtin/notes.c
Simple merge
Simple merge
Simple merge
index 226d0f95236f299a1506beefb5babf1cf52574f0,f7716a547293a58bfb96773acb60692ac86e0efb..f83e7b8fc1758aa837b4dd48708a3d6c31bcd226
@@@ -119,9 -119,9 +119,9 @@@ static int for_each_replace_name(const 
  }
  
  static int delete_replace_ref(const char *name, const char *ref,
-                             const unsigned char *sha1)
+                             const struct object_id *oid)
  {
-       if (delete_ref(NULL, ref, sha1, 0))
 -      if (delete_ref(ref, oid->hash, 0))
++      if (delete_ref(NULL, ref, oid->hash, 0))
                return 1;
        printf("Deleted replace ref '%s'\n", name);
        return 0;
diff --cc cache.h
index d3265cca1239099f342ffaca3d28fde3d735fdc2,724e905f7a4de5fd60a6698c2cea541d98af50b8..dc261f40dda7c6eb274463a64767671a6c1cae4a
+++ b/cache.h
@@@ -1363,37 -1319,16 +1363,46 @@@ extern char *oid_to_hex_r(char *out, co
  extern char *sha1_to_hex(const unsigned char *sha1);  /* static buffer result! */
  extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
  
 -extern int interpret_branch_name(const char *str, int len, struct strbuf *);
+ /*
+  * Parse a 40-character hexadecimal object ID starting from hex, updating the
+  * pointer specified by end when parsing stops.  The resulting object ID is
+  * stored in oid.  Returns 0 on success.  Parsing will stop on the first NUL or
+  * other invalid character.  end is only updated on success; otherwise, it is
+  * unmodified.
+  */
+ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
 +/*
 + * This reads short-hand syntax that not only evaluates to a commit
 + * object name, but also can act as if the end user spelled the name
 + * of the branch from the command line.
 + *
 + * - "@{-N}" finds the name of the Nth previous branch we were on, and
 + *   places the name of the branch in the given buf and returns the
 + *   number of characters parsed if successful.
 + *
 + * - "<branch>@{upstream}" finds the name of the other ref that
 + *   <branch> is configured to merge with (missing <branch> defaults
 + *   to the current branch), and places the name of the branch in the
 + *   given buf and returns the number of characters parsed if
 + *   successful.
 + *
 + * If the input is not of the accepted format, it returns a negative
 + * number to signal an error.
 + *
 + * If the input was ok but there are not N branch switches in the
 + * reflog, it returns 0.
 + *
 + * If "allowed" is non-zero, it is a treated as a bitfield of allowable
 + * expansions: local branches ("refs/heads/"), remote branches
 + * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
 + * allowed, even ones to refs outside of those namespaces.
 + */
 +#define INTERPRET_BRANCH_LOCAL (1<<0)
 +#define INTERPRET_BRANCH_REMOTE (1<<1)
 +#define INTERPRET_BRANCH_HEAD (1<<2)
 +extern int interpret_branch_name(const char *str, int len, struct strbuf *,
 +                               unsigned allowed);
  extern int get_oid_mb(const char *str, struct object_id *oid);
  
  extern int validate_headref(const char *ref);
diff --cc ref-filter.c
Simple merge
diff --cc refs.c
Simple merge
diff --cc refs.h
Simple merge
Simple merge
diff --cc revision.c
Simple merge
diff --cc sha1_file.c
Simple merge
diff --cc sha1_name.c
Simple merge
diff --cc transport.c
Simple merge