git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: Re: [PATCH v2 00/42] object_id part 13
Date: Wed, 2 May 2018 17:32:24 +0200	[thread overview]
Message-ID: <20180502153224.GA8237@duynguyen.home> (raw)
In-Reply-To: <20180502002610.915892-1-sandals@crustytoothpaste.net>

On Wed, May 02, 2018 at 12:25:28AM +0000, brian m. carlson wrote:
> Changes from v1:
> * Add missing sign-off.
> * Removed unneeded braces from init_pack_info.
> * Express 51 in terms of the_hash_algo->hexsz.
> * Fix comments referring to SHA-1.
> * Update commit messages as suggested.
> * Add and use empty_tree_oid_hex and empty_blob_oid_hex.

Interdiff for people who don't have time to read 42 patches yet

diff --git a/builtin/merge.c b/builtin/merge.c
index 8d75ebe64b..7084bcfdea 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -290,7 +290,7 @@ static void read_empty(const struct object_id *oid, int verbose)
 		args[i++] = "-v";
 	args[i++] = "-m";
 	args[i++] = "-u";
-	args[i++] = oid_to_hex(the_hash_algo->empty_tree);
+	args[i++] = empty_tree_oid_hex();
 	args[i++] = oid_to_hex(oid);
 	args[i] = NULL;
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c31ceb30c2..dca523f50f 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,
 		return "Working directory has unstaged changes";
 
 	/* diff-index with either HEAD or an empty tree */
-	diff_index[4] = head_has_history() ? "HEAD" : oid_to_hex(the_hash_algo->empty_tree);
+	diff_index[4] = head_has_history() ? "HEAD" : empty_tree_oid_hex();
 
 	child_process_init(&child);
 	child.argv = diff_index;
diff --git a/cache.h b/cache.h
index c5b041019b..71b3c1b15b 100644
--- a/cache.h
+++ b/cache.h
@@ -1033,6 +1033,9 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
 	return !oidcmp(oid, the_hash_algo->empty_tree);
 }
 
+const char *empty_tree_oid_hex(void);
+const char *empty_blob_oid_hex(void);
+
 /* 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);
diff --git a/http.c b/http.c
index ec70676748..312a5e1833 100644
--- a/http.c
+++ b/http.c
@@ -2070,7 +2070,7 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
 				get_sha1_hex(data + i + 6, hash);
 				fetch_and_setup_pack_index(packs_head, hash,
 						      base_url);
-				i += 51;
+				i += hexsz + 11;
 				break;
 			}
 		default:
diff --git a/sequencer.c b/sequencer.c
index 12c1e1cdbb..94b6513402 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1480,8 +1480,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 		unborn = get_oid("HEAD", &head);
 		if (unborn)
 			oidcpy(&head, the_hash_algo->empty_tree);
-		if (index_differs_from(unborn ?
-				       oid_to_hex(the_hash_algo->empty_tree) : "HEAD",
+		if (index_differs_from(unborn ? empty_tree_oid_hex() : "HEAD",
 				       NULL, 0))
 			return error_dirty_index(opts);
 	}
diff --git a/server-info.c b/server-info.c
index 828ec5e538..7ce6dcd67b 100644
--- a/server-info.c
+++ b/server-info.c
@@ -223,11 +223,9 @@ static void init_pack_info(const char *infofile, int force)
 	else
 		stale = 1;
 
-	for (i = 0; i < num_pack; i++) {
-		if (stale) {
+	for (i = 0; i < num_pack; i++)
+		if (stale)
 			info[i]->old_num = -1;
-		}
-	}
 
 	/* renumber them */
 	QSORT(info, num_pack, compare_info);
diff --git a/sha1_file.c b/sha1_file.c
index 794753bd54..bf6c8da3ff 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -109,6 +109,18 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
 	},
 };
 
+const char *empty_tree_oid_hex(void)
+{
+	static char buf[GIT_MAX_HEXSZ + 1];
+	return oid_to_hex_r(buf, the_hash_algo->empty_tree);
+}
+
+const char *empty_blob_oid_hex(void)
+{
+	static char buf[GIT_MAX_HEXSZ + 1];
+	return oid_to_hex_r(buf, the_hash_algo->empty_blob);
+}
+
 /*
  * This is meant to hold a *small* number of objects that you would
  * want read_sha1_file() to be able to return, but yet you do not want
diff --git a/submodule.c b/submodule.c
index 22a96b7af0..ee7eea4877 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1567,7 +1567,7 @@ static void submodule_reset_index(const char *path)
 				   get_super_prefix_or_empty(), path);
 	argv_array_pushl(&cp.args, "read-tree", "-u", "--reset", NULL);
 
-	argv_array_push(&cp.args, oid_to_hex(the_hash_algo->empty_tree));
+	argv_array_push(&cp.args, empty_tree_oid_hex());
 
 	if (run_command(&cp))
 		die("could not reset submodule index");
@@ -1659,9 +1659,9 @@ int submodule_move_head(const char *path,
 		argv_array_push(&cp.args, "-m");
 
 	if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
-		argv_array_push(&cp.args, old_head ? old_head : oid_to_hex(the_hash_algo->empty_tree));
+		argv_array_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
 
-	argv_array_push(&cp.args, new_head ? new_head : oid_to_hex(the_hash_algo->empty_tree));
+	argv_array_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
 
 	if (run_command(&cp)) {
 		ret = -1;
diff --git a/upload-pack.c b/upload-pack.c
index 0858527c5b..1fb4942235 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
 		"rev-list", "--stdin", NULL,
 	};
 	struct object *o;
-	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + SHA-1 + LF */
+	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
 	int i;
 
 	cmd->argv = argv;
@@ -561,7 +561,7 @@ static int get_reachable_list(struct object_array *src,
 	struct child_process cmd = CHILD_PROCESS_INIT;
 	int i;
 	struct object *o;
-	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + SHA-1 + LF */
+	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
 	const unsigned hexsz = the_hash_algo->hexsz;
 
 	if (do_reachable_revlist(&cmd, src, reachable) < 0)
diff --git a/wt-status.c b/wt-status.c
index 857724bd60..e44115b3be 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -600,11 +600,10 @@ static void wt_status_collect_changes_index(struct wt_status *s)
 {
 	struct rev_info rev;
 	struct setup_revision_opt opt;
-	char hex[GIT_MAX_HEXSZ + 1];
 
 	init_revisions(&rev, NULL);
 	memset(&opt, 0, sizeof(opt));
-	opt.def = s->is_initial ? oid_to_hex_r(hex, the_hash_algo->empty_tree) : s->reference;
+	opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
 	setup_revisions(0, NULL, &rev, &opt);
 
 	rev.diffopt.flags.override_submodule_config = 1;
@@ -976,14 +975,13 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
 	struct setup_revision_opt opt;
 	int dirty_submodules;
 	const char *c = color(WT_STATUS_HEADER, s);
-	char hex[GIT_MAX_HEXSZ + 1];
 
 	init_revisions(&rev, NULL);
 	rev.diffopt.flags.allow_textconv = 1;
 	rev.diffopt.ita_invisible_in_index = 1;
 
 	memset(&opt, 0, sizeof(opt));
-	opt.def = s->is_initial ? oid_to_hex_r(hex, the_hash_algo->empty_tree) : s->reference;
+	opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
 	setup_revisions(0, NULL, &rev, &opt);
 
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;


--
Duy

  parent reply	other threads:[~2018-05-02 15:32 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02  0:25 [PATCH v2 00/42] object_id part 13 brian m. carlson
2018-05-02  0:25 ` [PATCH v2 01/42] cache: add a function to read an object ID from a buffer brian m. carlson
2018-05-02  0:25 ` [PATCH v2 02/42] server-info: remove unused members from struct pack_info brian m. carlson
2018-05-02  0:25 ` [PATCH v2 03/42] Remove unused member in struct object_context brian m. carlson
2018-05-02  0:25 ` [PATCH v2 04/42] packfile: remove unused member from struct pack_entry brian m. carlson
2018-05-02  0:25 ` [PATCH v2 05/42] packfile: convert has_sha1_pack to object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 06/42] sha1-file: convert freshen functions " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 07/42] packfile: convert find_pack_entry " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 08/42] packfile: abstract away hash constant values brian m. carlson
2018-05-02  0:25 ` [PATCH v2 09/42] pack-objects: abstract away hash algorithm brian m. carlson
2018-05-02  0:25 ` [PATCH v2 10/42] pack-redundant: " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 11/42] tree-walk: avoid hard-coded 20 constant brian m. carlson
2018-05-02  0:25 ` [PATCH v2 12/42] tree-walk: convert get_tree_entry_follow_symlinks to object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 13/42] fsck: convert static functions to struct object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 14/42] submodule-config: convert structures to object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 15/42] split-index: convert struct split_index " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 16/42] Update struct index_state to use struct object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 17/42] pack-redundant: convert linked lists " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 18/42] index-pack: abstract away hash function constant brian m. carlson
2018-05-02  0:25 ` [PATCH v2 19/42] commit: convert uses of get_sha1_hex to get_oid_hex brian m. carlson
2018-05-02  0:25 ` [PATCH v2 20/42] dir: convert struct untracked_cache_dir to object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 21/42] http: eliminate hard-coded constants brian m. carlson
2018-05-02  0:25 ` [PATCH v2 22/42] revision: replace use of " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 23/42] upload-pack: replace use of several " brian m. carlson
2018-05-02  0:25 ` [PATCH v2 24/42] diff: specify abbreviation size in terms of the_hash_algo brian m. carlson
2018-05-02  0:25 ` [PATCH v2 25/42] builtin/receive-pack: avoid hard-coded constants for push certs brian m. carlson
2018-05-02  0:25 ` [PATCH v2 26/42] sha1-file: add functions for hex empty tree and blob OIDs brian m. carlson
2018-05-02  0:25 ` [PATCH v2 27/42] builtin/am: convert uses of EMPTY_TREE_SHA1_BIN to the_hash_algo brian m. carlson
2018-05-02  0:25 ` [PATCH v2 28/42] builtin/merge: switch tree functions to use object_id brian m. carlson
2018-05-02  0:25 ` [PATCH v2 29/42] merge: convert empty tree constant to the_hash_algo brian m. carlson
2018-05-02  0:25 ` [PATCH v2 30/42] sequencer: convert one use of EMPTY_TREE_SHA1_HEX brian m. carlson
2018-05-02  0:25 ` [PATCH v2 31/42] submodule: convert several uses " brian m. carlson
2018-05-02  0:26 ` [PATCH v2 32/42] wt-status: convert two " brian m. carlson
2018-05-02  0:26 ` [PATCH v2 33/42] builtin/receive-pack: convert one use " brian m. carlson
2018-05-02  0:26 ` [PATCH v2 34/42] builtin/reset: convert use of EMPTY_TREE_SHA1_BIN brian m. carlson
2018-05-02  0:26 ` [PATCH v2 35/42] sha1_file: convert cached object code to struct object_id brian m. carlson
2018-05-02  0:26 ` [PATCH v2 36/42] cache-tree: use is_empty_tree_oid brian m. carlson
2018-05-02  0:26 ` [PATCH v2 37/42] sequencer: use the_hash_algo for empty tree object ID brian m. carlson
2018-05-02  0:26 ` [PATCH v2 38/42] dir: use the_hash_algo for empty blob " brian m. carlson
2018-05-02  0:26 ` [PATCH v2 39/42] sha1_file: only expose empty object constants through git_hash_algo brian m. carlson
2018-05-02  0:26 ` [PATCH v2 40/42] Update shell scripts to compute empty tree object ID brian m. carlson
2018-05-02  0:26 ` [PATCH v2 41/42] add--interactive: compute the empty tree value brian m. carlson
2018-05-02  0:26 ` [PATCH v2 42/42] merge-one-file: compute empty blob object ID brian m. carlson
2018-05-02 15:32 ` Duy Nguyen [this message]
2018-05-02 23:42   ` [PATCH v2 00/42] object_id part 13 brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180502153224.GA8237@duynguyen.home \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).