Thread (103 messages) 103 messages, 6 authors, 2018-02-28
STALE3134d

Revision v2 of 2 in this series.

Revisions (2)
  1. v2 current
  2. v3 [diff vs current]

[PATCH v2 4/5] diff.c: initialize hash algo when running in --no-index mode

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2018-02-24 03:35:07
Subsystem: the rest · Maintainer: Linus Torvalds

Our "git diff" command supports running as a standalone tool. In this
code path, we try to hash the file content but after
18e2588e11 (sha1_file: switch uses of SHA-1 to the_hash_algo -
2018-02-01), there is a chance that the_hash_algo (required by
index_path) may still be uninitialized if no repository is found.

Executing index_path() when the_hash_algo is NULL (or points to unknown
algo) either crashes or dies. Let's make it a bit safer by explicitly
falling back to SHA-1 (so that the diff output remains the same as
before, compared to the alternative that we simply do not hash).

dòng được

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 diff.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/diff.c b/diff.c
index 21c3838b25..f5755425b6 100644
--- a/diff.c
+++ b/diff.c
@@ -3995,6 +3995,18 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
 		return;
 	}
 
+	/*
+	 * NEEDSWORK: When running in no-index mode (and no repo is
+	 * found, thus no hash algo conifugred), fall back to SHA-1
+	 * hashing (which is used by diff_fill_oid_info below) to
+	 * avoid regression in diff output.
+	 *
+	 * In future, perhaps we can allow the user to specify their
+	 * hash algorithm from command line in this mode.
+	 */
+	if (o->flags.no_index && !the_hash_algo)
+		the_hash_algo = &hash_algos[GIT_HASH_SHA1];
+
 	diff_fill_oid_info(one);
 	diff_fill_oid_info(two);
 
-- 
2.16.1.435.g8f24da2e1a
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help