Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/builtin/get-tar-commit-id.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / builtin / get-tar-commit-id.c` 58 lines ยท 1436 bytes Raw Blame History 1 /* 2 * Copyright (c) 2005, 2006 Rene Scharfe 3 */ 4 #include "builtin.h" 5 #include "commit.h" 6 #include "tar.h" 7 8 static const char builtin_get_tar_commit_id_usage[] = 9 "git get-tar-commit-id"; 10 11 /* ustar header + extended global header content */ 12 #define RECORDSIZE (512) 13 #define HEADERSIZE (2 * RECORDSIZE) 14 15 int cmd_get_tar_commit_id(int argc, 16 const char **argv, 17 const char *prefix, 18 struct repository *repo UNUSED) 19 { 20 char buffer[HEADERSIZE]; 21 struct ustar_header *header = (struct ustar_header *)buffer; 22 char *content = buffer + RECORDSIZE; 23 const char *comment; 24 ssize_t n; 25 long len; 26 char *end; 27 28 BUG_ON_NON_EMPTY_PREFIX(prefix); 29 30 show_usage_if_asked(argc, argv, builtin_get_tar_commit_id_usage); 31 32 if (argc != 1) 33 usage(builtin_get_tar_commit_id_usage); 34 35 n = read_in_full(0, buffer, HEADERSIZE); 36 if (n < 0) 37 die_errno("git get-tar-commit-id: read error"); 38 if (n != HEADERSIZE) 39 die_errno("git get-tar-commit-id: EOF before reading tar header"); 40 if (header->typeflag[0] != TYPEFLAG_GLOBAL_HEADER) 41 return 1; 42 43 errno = 0; 44 len = strtol(content, &end, 10); 45 if (errno == ERANGE || end == content || len < 0) 46 return 1; 47 if (!skip_prefix(end, " comment=", &comment)) 48 return 1; 49 len -= comment - content; 50 if (len < 1 || !(len % 2) || 51 hash_algo_by_length((len - 1) / 2) == GIT_HASH_UNKNOWN) 52 return 1; 53 54 if (write_in_full(1, comment, len) < 0) 55 die_errno("git get-tar-commit-id: write error"); 56 57 return 0; 58 }