Skip to content

Commit 7df437e

Browse files
committed
Merge branch 'maint'
* maint: gitattributes: -crlf is not binary git-apply: Loosen "match_beginning" logic Fix example in git-name-rev documentation shell: do not play duplicated definition games to shrink the executable Fix use of hardlinks in "make install" pack-objects: Allow missing base objects when creating thin packs
2 parents ff1e8bf + bbb896d commit 7df437e

File tree

7 files changed

+146
-13
lines changed

7 files changed

+146
-13
lines changed

Documentation/git-name-rev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Enter 'git-name-rev':
5959

6060
------------
6161
% git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a
62-
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99^0~940
62+
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99~940
6363
------------
6464

6565
Now you are wiser, because you know that it happened 940 revisions before v0.99.

Documentation/gitattributes.txt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ Set::
105105

106106
Unset::
107107

108-
Unsetting the `crlf` attribute on a path is meant to
109-
mark the path as a "binary" file. The path never goes
110-
through line endings conversion upon checkin/checkout.
108+
Unsetting the `crlf` attribute on a path tells git not to
109+
attempt any end-of-line conversion upon checkin or checkout.
111110

112111
Unspecified::
113112

@@ -486,6 +485,41 @@ in the file. E.g. the string `$Format:%H$` will be replaced by the
486485
commit hash.
487486

488487

488+
USING ATTRIBUTE MACROS
489+
----------------------
490+
491+
You do not want any end-of-line conversions applied to, nor textual diffs
492+
produced for, any binary file you track. You would need to specify e.g.
493+
494+
------------
495+
*.jpg -crlf -diff
496+
------------
497+
498+
but that may become cumbersome, when you have many attributes. Using
499+
attribute macros, you can specify groups of attributes set or unset at
500+
the same time. The system knows a built-in attribute macro, `binary`:
501+
502+
------------
503+
*.jpg binary
504+
------------
505+
506+
which is equivalent to the above. Note that the attribute macros can only
507+
be "Set" (see the above example that sets "binary" macro as if it were an
508+
ordinary attribute --- setting it in turn unsets "crlf" and "diff").
509+
510+
511+
DEFINING ATTRIBUTE MACROS
512+
-------------------------
513+
514+
Custom attribute macros can be defined only in the `.gitattributes` file
515+
at the toplevel (i.e. not in any subdirectory). The built-in attribute
516+
macro "binary" is equivalent to:
517+
518+
------------
519+
[attr]binary -diff -crlf
520+
------------
521+
522+
489523
EXAMPLE
490524
-------
491525

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ endif
13791379
{ $(RM) "$$execdir/git-add$X" && \
13801380
ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
13811381
cp git-add$X "$$execdir/git-add$X"; } && \
1382-
{ $(foreach p,$(filter-out git-add,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
1382+
{ $(foreach p,$(filter-out git-add$X,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
13831383
ln "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
13841384
ln -s "git-add$X" "$$execdir/$p" 2>/dev/null || \
13851385
cp "$$execdir/git-add$X" "$$execdir/$p" || exit;) } && \

builtin-apply.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,17 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
19961996
/*
19971997
* A hunk to change lines at the beginning would begin with
19981998
* @@ -1,L +N,M @@
1999+
* but we need to be careful. -U0 that inserts before the second
2000+
* line also has this pattern.
19992001
*
20002002
* And a hunk to add to an empty file would begin with
20012003
* @@ -0,0 +N,M @@
20022004
*
20032005
* In other words, a hunk that is (frag->oldpos <= 1) with or
20042006
* without leading context must match at the beginning.
20052007
*/
2006-
match_beginning = frag->oldpos <= 1;
2008+
match_beginning = (!frag->oldpos ||
2009+
(frag->oldpos == 1 && !unidiff_zero));
20072010

20082011
/*
20092012
* A hunk without trailing lines must match at the end.

builtin-pack-objects.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,12 @@ static void check_object(struct object_entry *entry)
10951095
}
10961096

10971097
entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1098-
if (entry->type < 0)
1099-
die("unable to get type of object %s",
1100-
sha1_to_hex(entry->idx.sha1));
1098+
/*
1099+
* The error condition is checked in prepare_pack(). This is
1100+
* to permit a missing preferred base object to be ignored
1101+
* as a preferred base. Doing so can result in a larger
1102+
* pack file, but the transfer will still take place.
1103+
*/
11011104
}
11021105

11031106
static int pack_offset_sort(const void *_a, const void *_b)
@@ -1721,8 +1724,12 @@ static void prepare_pack(int window, int depth)
17211724
if (entry->no_try_delta)
17221725
continue;
17231726

1724-
if (!entry->preferred_base)
1727+
if (!entry->preferred_base) {
17251728
nr_deltas++;
1729+
if (entry->type < 0)
1730+
die("unable to get type of object %s",
1731+
sha1_to_hex(entry->idx.sha1));
1732+
}
17261733

17271734
delta_list[n++] = entry;
17281735
}

t/t4104-apply-boundary.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ test_expect_success setup '
2727
git diff victim >add-a-patch.with &&
2828
git diff --unified=0 >add-a-patch.without &&
2929
30+
: insert at line two
31+
for i in b a '"$L"' y
32+
do
33+
echo $i
34+
done >victim &&
35+
cat victim >insert-a-expect &&
36+
git diff victim >insert-a-patch.with &&
37+
git diff --unified=0 >insert-a-patch.without &&
38+
3039
: modify at the head
3140
for i in a '"$L"' y
3241
do
@@ -55,7 +64,7 @@ test_expect_success setup '
5564
git diff --unified=0 >add-z-patch.without &&
5665
5766
: modify at the tail
58-
for i in a '"$L"' y
67+
for i in b '"$L"' z
5968
do
6069
echo $i
6170
done >victim &&
@@ -81,7 +90,7 @@ do
8190
with) u= ;;
8291
without) u='--unidiff-zero ' ;;
8392
esac
84-
for kind in add-a add-z mod-a mod-z del-a del-z
93+
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
8594
do
8695
test_expect_success "apply $kind-patch $with context" '
8796
cat original >victim &&
@@ -95,7 +104,7 @@ do
95104
done
96105
done
97106

98-
for kind in add-a add-z mod-a mod-z del-a del-z
107+
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
99108
do
100109
rm -f $kind-ng.without
101110
sed -e "s/^diff --git /diff /" \

t/t5306-pack-nobase.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Google Inc.
4+
#
5+
6+
test_description='git-pack-object with missing base
7+
8+
'
9+
. ./test-lib.sh
10+
11+
# Create A-B chain
12+
#
13+
test_expect_success \
14+
'setup base' \
15+
'for a in a b c d e f g h i; do echo $a >>text; done &&
16+
echo side >side &&
17+
git update-index --add text side &&
18+
A=$(echo A | git commit-tree $(git write-tree)) &&
19+
20+
echo m >>text &&
21+
git update-index text &&
22+
B=$(echo B | git commit-tree $(git write-tree) -p $A) &&
23+
git update-ref HEAD $B
24+
'
25+
26+
# Create repository with C whose parent is B.
27+
# Repository contains C, C^{tree}, C:text, B, B^{tree}.
28+
# Repository is missing B:text (best delta base for C:text).
29+
# Repository is missing A (parent of B).
30+
# Repository is missing A:side.
31+
#
32+
test_expect_success \
33+
'setup patch_clone' \
34+
'base_objects=$(pwd)/.git/objects &&
35+
(mkdir patch_clone &&
36+
cd patch_clone &&
37+
git init &&
38+
echo "$base_objects" >.git/objects/info/alternates &&
39+
echo q >>text &&
40+
git read-tree $B &&
41+
git update-index text &&
42+
git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) &&
43+
rm .git/objects/info/alternates &&
44+
45+
git --git-dir=../.git cat-file commit $B |
46+
git hash-object -t commit -w --stdin &&
47+
48+
git --git-dir=../.git cat-file tree "$B^{tree}" |
49+
git hash-object -t tree -w --stdin
50+
) &&
51+
C=$(git --git-dir=patch_clone/.git rev-parse HEAD)
52+
'
53+
54+
# Clone patch_clone indirectly by cloning base and fetching.
55+
#
56+
test_expect_success \
57+
'indirectly clone patch_clone' \
58+
'(mkdir user_clone &&
59+
cd user_clone &&
60+
git init &&
61+
git pull ../.git &&
62+
test $(git rev-parse HEAD) = $B &&
63+
64+
git pull ../patch_clone/.git &&
65+
test $(git rev-parse HEAD) = $C
66+
)
67+
'
68+
69+
# Cloning the patch_clone directly should fail.
70+
#
71+
test_expect_success \
72+
'clone of patch_clone is incomplete' \
73+
'(mkdir user_direct &&
74+
cd user_direct &&
75+
git init &&
76+
test_must_fail git fetch ../patch_clone/.git
77+
)
78+
'
79+
80+
test_done

0 commit comments

Comments
 (0)