git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 2/2] cat-file: teach cat-file a '--literally' option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 25, 2015, 07:42 UTC
Message-ID
<CAPig+cSxYca7sQ+0PZLPq6n0PQzQ-1JDLSRkaqBLfDPXpC7pBA@mail.gmail.com>
In-Reply-To
<1427268126-16964-1-git-send-email-karthik.188@gmail.com>
On Wed, Mar 25, 2015 at 3:22 AM, Karthik Nayak <karthik.188@gmail.com> wrote:
Show 31 quoted lines
> Currently 'git cat-file' throws an error while trying to
> print the type or size of a broken/corrupt object which is
> created using 'git hash-object --literally'. This is
> because these objects are usually of unknown types.
>
> Teach git cat-file a '--literally' option where it prints
> the type or size of a broken/corrupt object without throwing
> an error.
>
> Modify '-t' and '-s' options to call sha1_object_info_extended()
> directly to support the '--literally' option.
>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Helped-by: Eric Sunshine <sunshine@sunshineco
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index df99df4..6fee461 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -405,5 +423,10 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
>         if (batch.enabled)
>                 return batch_objects(&batch);
>
> -       return cat_one_file(opt, exp_type, obj_name);
> +       if (literally && (opt == 't' || opt == 's'))
> +               return cat_one_file(opt, exp_type, obj_name, literally);
> +       else if (literally)
> +               die("git cat-file --literally: use with -s or -t");
> +
> +       return cat_one_file(opt, exp_type, obj_name, literally);

Although I haven't read the patch closely yet, this unnecessarily complex logic caught my eye as I was scanning the changes. If you check for the illegal option combination first, then you can coalesce the two identical cat_one_file() invocations, and this entire hunk reduces to the more readable:

    if (literally && opt != 't' && opt != 's')
        die("git cat-file --literally: use with -s or -t");
    return cat_one_file(opt, exp_type, obj_name, literally);
>  }
> --
> 2.3.1.170.g5319d60.dirty
Previous: Karthik NayakNext: karthik nayak
Message 9 of 10 in “cat-file: add a '--literally' option”
  1. 0/2 cat-file: add a '--literally' optionkarthik nayak, Mar 25, 2015
  2. 1/2 sha1_file.c: support reading from a loose object of unknown typeKarthik Nayak, Mar 25, 2015
  3. Junio C HamanoMar 25, 2015
  4. karthik nayakMar 25, 2015
  5. Junio C HamanoMar 25, 2015
  6. Junio C HamanoMar 25, 2015
  7. karthik nayakMar 25, 2015
  8. 2/2 cat-file: teach cat-file a '--literally' optionKarthik Nayak, Mar 25, 2015
  9. Eric SunshineMar 25, 2015
  10. karthik nayakMar 25, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.