Merge branch 'jk/diff-blob'
authorJunio C Hamano <gitster@pobox.com>
Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)
"git cat-file --textconv" started segfaulting recently, which
has been corrected.

* jk/diff-blob:
cat-file: handle NULL object_context.path

1  2 
builtin/cat-file.c
diff --combined builtin/cat-file.c
index 4ccbfaac3148287535aa8833d0d6cbdacb7c1d3d,b91b16745322cd7d2d69052b3098a3219e799ed6..1ea25331d38f4395f1c5079a1ca39263c69701b2
@@@ -4,15 -4,12 +4,15 @@@
   * Copyright (C) Linus Torvalds, 2005
   */
  #include "cache.h"
 +#include "config.h"
  #include "builtin.h"
 +#include "diff.h"
  #include "parse-options.h"
  #include "userdiff.h"
  #include "streaming.h"
  #include "tree-walk.h"
  #include "sha1-array.h"
 +#include "packfile.h"
  
  struct batch_options {
        int enabled;
@@@ -58,14 -55,14 +58,14 @@@ static int cat_one_file(int opt, const 
        struct object_context obj_context;
        struct object_info oi = OBJECT_INFO_INIT;
        struct strbuf sb = STRBUF_INIT;
 -      unsigned flags = LOOKUP_REPLACE_OBJECT;
 +      unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
        const char *path = force_path;
  
        if (unknown_type)
 -              flags |= LOOKUP_UNKNOWN_OBJECT;
 +              flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
  
 -      if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
 -                                oid.hash, &obj_context))
 +      if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
 +                               &oid, &obj_context))
                die("Not a valid object name %s", obj_name);
  
        if (!path)
@@@ -97,7 -94,7 +97,7 @@@
                return !has_object_file(&oid);
  
        case 'w':
-               if (!path[0])
+               if (!path)
                        die("git cat-file --filters %s: <object> must be "
                            "<sha1:path>", obj_name);
  
                break;
  
        case 'c':
-               if (!path[0])
+               if (!path)
                        die("git cat-file --textconv %s: <object> must be <sha1:path>",
                            obj_name);
  
                die("git cat-file %s: bad file", obj_name);
  
        write_or_die(1, buf, size);
 +      free(buf);
        free(obj_context.path);
        return 0;
  }
@@@ -339,8 -335,7 +339,8 @@@ static void batch_object_write(const ch
        struct strbuf buf = STRBUF_INIT;
  
        if (!data->skip_object_info &&
 -          sha1_object_info_extended(data->oid.hash, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
 +          sha1_object_info_extended(data->oid.hash, &data->info,
 +                                    OBJECT_INFO_LOOKUP_REPLACE) < 0) {
                printf("%s missing\n",
                       obj_name ? obj_name : oid_to_hex(&data->oid));
                fflush(stdout);
@@@ -362,10 -357,10 +362,10 @@@ static void batch_one_object(const cha
                             struct expand_data *data)
  {
        struct object_context ctx;
 -      int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
 +      int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
        enum follow_symlinks_result result;
  
 -      result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx);
 +      result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
        if (result != FOUND) {
                switch (result) {
                case MISSING_OBJECT: