Skip to content

Commit 3b75314

Browse files
committed
Merge branch 'jk/maint-null-in-trees'
We do not want a link to 0{40} object stored anywhere in our objects. * jk/maint-null-in-trees: fsck: detect null sha1 in tree entries do not write null sha1s to on-disk index diff: do not use null sha1 as a sentinel value
2 parents b9148c3 + c479d14 commit 3b75314

18 files changed

+188
-32
lines changed

builtin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern int check_pager_config(const char *cmd);
4343
struct diff_options;
4444
extern void setup_diff_pager(struct diff_options *);
4545

46-
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, char **buf, unsigned long *buf_size);
46+
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
4747

4848
extern int cmd_add(int argc, const char **argv, const char *prefix);
4949
extern int cmd_annotate(int argc, const char **argv, const char *prefix);

builtin/blame.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,
110110
int textconv_object(const char *path,
111111
unsigned mode,
112112
const unsigned char *sha1,
113+
int sha1_valid,
113114
char **buf,
114115
unsigned long *buf_size)
115116
{
116117
struct diff_filespec *df;
117118
struct userdiff_driver *textconv;
118119

119120
df = alloc_filespec(path);
120-
fill_filespec(df, sha1, mode);
121+
fill_filespec(df, sha1, sha1_valid, mode);
121122
textconv = get_textconv(df);
122123
if (!textconv) {
123124
free_filespec(df);
@@ -142,7 +143,7 @@ static void fill_origin_blob(struct diff_options *opt,
142143

143144
num_read_blob++;
144145
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
145-
textconv_object(o->path, o->mode, o->blob_sha1, &file->ptr, &file_size))
146+
textconv_object(o->path, o->mode, o->blob_sha1, 1, &file->ptr, &file_size))
146147
;
147148
else
148149
file->ptr = read_sha1_file(o->blob_sha1, &type, &file_size);
@@ -2120,7 +2121,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
21202121
switch (st.st_mode & S_IFMT) {
21212122
case S_IFREG:
21222123
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
2123-
textconv_object(read_from, mode, null_sha1, &buf_ptr, &buf_len))
2124+
textconv_object(read_from, mode, null_sha1, 0, &buf_ptr, &buf_len))
21242125
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
21252126
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
21262127
die_errno("cannot open or read '%s'", read_from);
@@ -2513,7 +2514,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25132514
die("no such path %s in %s", path, final_commit_name);
25142515

25152516
if (DIFF_OPT_TST(&sb.revs->diffopt, ALLOW_TEXTCONV) &&
2516-
textconv_object(path, o->mode, o->blob_sha1, (char **) &sb.final_buf,
2517+
textconv_object(path, o->mode, o->blob_sha1, 1, (char **) &sb.final_buf,
25172518
&sb.final_buf_size))
25182519
;
25192520
else

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
146146
die("git cat-file --textconv %s: <object> must be <sha1:path>",
147147
obj_name);
148148

149-
if (!textconv_object(obj_context.path, obj_context.mode, sha1, &buf, &size))
149+
if (!textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))
150150
die("git cat-file --textconv: unable to run textconv on %s",
151151
obj_name);
152152
break;

builtin/diff.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ static void stuff_change(struct diff_options *opt,
2929
unsigned old_mode, unsigned new_mode,
3030
const unsigned char *old_sha1,
3131
const unsigned char *new_sha1,
32+
int old_sha1_valid,
33+
int new_sha1_valid,
3234
const char *old_name,
3335
const char *new_name)
3436
{
@@ -54,8 +56,8 @@ static void stuff_change(struct diff_options *opt,
5456

5557
one = alloc_filespec(old_name);
5658
two = alloc_filespec(new_name);
57-
fill_filespec(one, old_sha1, old_mode);
58-
fill_filespec(two, new_sha1, new_mode);
59+
fill_filespec(one, old_sha1, old_sha1_valid, old_mode);
60+
fill_filespec(two, new_sha1, new_sha1_valid, new_mode);
5961

6062
diff_queue(&diff_queued_diff, one, two);
6163
}
@@ -84,6 +86,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
8486
stuff_change(&revs->diffopt,
8587
blob[0].mode, canon_mode(st.st_mode),
8688
blob[0].sha1, null_sha1,
89+
1, 0,
8790
path, path);
8891
diffcore_std(&revs->diffopt);
8992
diff_flush(&revs->diffopt);
@@ -108,6 +111,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
108111
stuff_change(&revs->diffopt,
109112
blob[0].mode, blob[1].mode,
110113
blob[0].sha1, blob[1].sha1,
114+
1, 1,
111115
blob[0].name, blob[1].name);
112116
diffcore_std(&revs->diffopt);
113117
diff_flush(&revs->diffopt);

combine-diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
111111
return xcalloc(1, 1);
112112
} else if (textconv) {
113113
struct diff_filespec *df = alloc_filespec(path);
114-
fill_filespec(df, sha1, mode);
114+
fill_filespec(df, sha1, 1, mode);
115115
*size = fill_textconv(textconv, df, &blob);
116116
free_filespec(df);
117117
} else {
@@ -823,7 +823,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
823823
&result_size, NULL, NULL);
824824
} else if (textconv) {
825825
struct diff_filespec *df = alloc_filespec(elem->path);
826-
fill_filespec(df, null_sha1, st.st_mode);
826+
fill_filespec(df, null_sha1, 0, st.st_mode);
827827
result_size = fill_textconv(textconv, df, &result);
828828
free_filespec(df);
829829
} else if (0 <= (fd = open(elem->path, O_RDONLY))) {

diff-lib.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
206206
if (silent_on_removed)
207207
continue;
208208
diff_addremove(&revs->diffopt, '-', ce->ce_mode,
209-
ce->sha1, ce->name, 0);
209+
ce->sha1, !is_null_sha1(ce->sha1),
210+
ce->name, 0);
210211
continue;
211212
}
212213
changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
@@ -220,6 +221,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
220221
newmode = ce_mode_from_stat(ce, st.st_mode);
221222
diff_change(&revs->diffopt, oldmode, newmode,
222223
ce->sha1, (changed ? null_sha1 : ce->sha1),
224+
!is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)),
223225
ce->name, 0, dirty_submodule);
224226

225227
}
@@ -236,11 +238,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
236238
static void diff_index_show_file(struct rev_info *revs,
237239
const char *prefix,
238240
struct cache_entry *ce,
239-
const unsigned char *sha1, unsigned int mode,
241+
const unsigned char *sha1, int sha1_valid,
242+
unsigned int mode,
240243
unsigned dirty_submodule)
241244
{
242245
diff_addremove(&revs->diffopt, prefix[0], mode,
243-
sha1, ce->name, dirty_submodule);
246+
sha1, sha1_valid, ce->name, dirty_submodule);
244247
}
245248

246249
static int get_stat_data(struct cache_entry *ce,
@@ -295,7 +298,7 @@ static void show_new_file(struct rev_info *revs,
295298
&dirty_submodule, &revs->diffopt) < 0)
296299
return;
297300

298-
diff_index_show_file(revs, "+", new, sha1, mode, dirty_submodule);
301+
diff_index_show_file(revs, "+", new, sha1, !is_null_sha1(sha1), mode, dirty_submodule);
299302
}
300303

301304
static int show_modified(struct rev_info *revs,
@@ -312,7 +315,7 @@ static int show_modified(struct rev_info *revs,
312315
&dirty_submodule, &revs->diffopt) < 0) {
313316
if (report_missing)
314317
diff_index_show_file(revs, "-", old,
315-
old->sha1, old->ce_mode, 0);
318+
old->sha1, 1, old->ce_mode, 0);
316319
return -1;
317320
}
318321

@@ -347,7 +350,8 @@ static int show_modified(struct rev_info *revs,
347350
return 0;
348351

349352
diff_change(&revs->diffopt, oldmode, mode,
350-
old->sha1, sha1, old->name, 0, dirty_submodule);
353+
old->sha1, sha1, 1, !is_null_sha1(sha1),
354+
old->name, 0, dirty_submodule);
351355
return 0;
352356
}
353357

@@ -380,7 +384,7 @@ static void do_oneway_diff(struct unpack_trees_options *o,
380384
struct diff_filepair *pair;
381385
pair = diff_unmerge(&revs->diffopt, idx->name);
382386
if (tree)
383-
fill_filespec(pair->one, tree->sha1, tree->ce_mode);
387+
fill_filespec(pair->one, tree->sha1, 1, tree->ce_mode);
384388
return;
385389
}
386390

@@ -396,7 +400,7 @@ static void do_oneway_diff(struct unpack_trees_options *o,
396400
* Something removed from the tree?
397401
*/
398402
if (!idx) {
399-
diff_index_show_file(revs, "-", tree, tree->sha1, tree->ce_mode, 0);
403+
diff_index_show_file(revs, "-", tree, tree->sha1, 1, tree->ce_mode, 0);
400404
return;
401405
}
402406

diff-no-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode)
8282
if (!name)
8383
name = "/dev/null";
8484
s = alloc_filespec(name);
85-
fill_filespec(s, null_sha1, mode);
85+
fill_filespec(s, null_sha1, 0, mode);
8686
if (name == file_from_standard_input)
8787
populate_from_stdin(s);
8888
return s;

diff.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,12 +2541,12 @@ void free_filespec(struct diff_filespec *spec)
25412541
}
25422542

25432543
void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
2544-
unsigned short mode)
2544+
int sha1_valid, unsigned short mode)
25452545
{
25462546
if (mode) {
25472547
spec->mode = canon_mode(mode);
25482548
hashcpy(spec->sha1, sha1);
2549-
spec->sha1_valid = !is_null_sha1(sha1);
2549+
spec->sha1_valid = sha1_valid;
25502550
}
25512551
}
25522552

@@ -4691,6 +4691,7 @@ static int is_submodule_ignored(const char *path, struct diff_options *options)
46914691
void diff_addremove(struct diff_options *options,
46924692
int addremove, unsigned mode,
46934693
const unsigned char *sha1,
4694+
int sha1_valid,
46944695
const char *concatpath, unsigned dirty_submodule)
46954696
{
46964697
struct diff_filespec *one, *two;
@@ -4722,9 +4723,9 @@ void diff_addremove(struct diff_options *options,
47224723
two = alloc_filespec(concatpath);
47234724

47244725
if (addremove != '+')
4725-
fill_filespec(one, sha1, mode);
4726+
fill_filespec(one, sha1, sha1_valid, mode);
47264727
if (addremove != '-') {
4727-
fill_filespec(two, sha1, mode);
4728+
fill_filespec(two, sha1, sha1_valid, mode);
47284729
two->dirty_submodule = dirty_submodule;
47294730
}
47304731

@@ -4737,6 +4738,7 @@ void diff_change(struct diff_options *options,
47374738
unsigned old_mode, unsigned new_mode,
47384739
const unsigned char *old_sha1,
47394740
const unsigned char *new_sha1,
4741+
int old_sha1_valid, int new_sha1_valid,
47404742
const char *concatpath,
47414743
unsigned old_dirty_submodule, unsigned new_dirty_submodule)
47424744
{
@@ -4751,6 +4753,8 @@ void diff_change(struct diff_options *options,
47514753
const unsigned char *tmp_c;
47524754
tmp = old_mode; old_mode = new_mode; new_mode = tmp;
47534755
tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
4756+
tmp = old_sha1_valid; old_sha1_valid = new_sha1_valid;
4757+
new_sha1_valid = tmp;
47544758
tmp = old_dirty_submodule; old_dirty_submodule = new_dirty_submodule;
47554759
new_dirty_submodule = tmp;
47564760
}
@@ -4761,8 +4765,8 @@ void diff_change(struct diff_options *options,
47614765

47624766
one = alloc_filespec(concatpath);
47634767
two = alloc_filespec(concatpath);
4764-
fill_filespec(one, old_sha1, old_mode);
4765-
fill_filespec(two, new_sha1, new_mode);
4768+
fill_filespec(one, old_sha1, old_sha1_valid, old_mode);
4769+
fill_filespec(two, new_sha1, new_sha1_valid, new_mode);
47664770
one->dirty_submodule = old_dirty_submodule;
47674771
two->dirty_submodule = new_dirty_submodule;
47684772

diff.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ typedef void (*change_fn_t)(struct diff_options *options,
1919
unsigned old_mode, unsigned new_mode,
2020
const unsigned char *old_sha1,
2121
const unsigned char *new_sha1,
22+
int old_sha1_valid, int new_sha1_valid,
2223
const char *fullpath,
2324
unsigned old_dirty_submodule, unsigned new_dirty_submodule);
2425

2526
typedef void (*add_remove_fn_t)(struct diff_options *options,
2627
int addremove, unsigned mode,
2728
const unsigned char *sha1,
29+
int sha1_valid,
2830
const char *fullpath, unsigned dirty_submodule);
2931

3032
typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
@@ -214,12 +216,15 @@ extern void diff_addremove(struct diff_options *,
214216
int addremove,
215217
unsigned mode,
216218
const unsigned char *sha1,
219+
int sha1_valid,
217220
const char *fullpath, unsigned dirty_submodule);
218221

219222
extern void diff_change(struct diff_options *,
220223
unsigned mode1, unsigned mode2,
221224
const unsigned char *sha1,
222225
const unsigned char *sha2,
226+
int sha1_valid,
227+
int sha2_valid,
223228
const char *fullpath,
224229
unsigned dirty_submodule1, unsigned dirty_submodule2);
225230

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
4848
memmove(rename_dst + first + 1, rename_dst + first,
4949
(rename_dst_nr - first - 1) * sizeof(*rename_dst));
5050
rename_dst[first].two = alloc_filespec(two->path);
51-
fill_filespec(rename_dst[first].two, two->sha1, two->mode);
51+
fill_filespec(rename_dst[first].two, two->sha1, two->sha1_valid, two->mode);
5252
rename_dst[first].pair = NULL;
5353
return &(rename_dst[first]);
5454
}

0 commit comments

Comments
 (0)