Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Aug 31, 2008
2 parents ff1e8bf + bbb896d commit 7df437e
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Documentation/git-name-rev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Enter 'git-name-rev':

------------
% git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99^0~940
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99~940
------------

Now you are wiser, because you know that it happened 940 revisions before v0.99.
Expand Down
40 changes: 37 additions & 3 deletions Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ Set::

Unset::

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

Unspecified::

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


USING ATTRIBUTE MACROS
----------------------

You do not want any end-of-line conversions applied to, nor textual diffs
produced for, any binary file you track. You would need to specify e.g.

------------
*.jpg -crlf -diff
------------

but that may become cumbersome, when you have many attributes. Using
attribute macros, you can specify groups of attributes set or unset at
the same time. The system knows a built-in attribute macro, `binary`:

------------
*.jpg binary
------------

which is equivalent to the above. Note that the attribute macros can only
be "Set" (see the above example that sets "binary" macro as if it were an
ordinary attribute --- setting it in turn unsets "crlf" and "diff").


DEFINING ATTRIBUTE MACROS
-------------------------

Custom attribute macros can be defined only in the `.gitattributes` file
at the toplevel (i.e. not in any subdirectory). The built-in attribute
macro "binary" is equivalent to:

------------
[attr]binary -diff -crlf
------------


EXAMPLE
-------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ endif
{ $(RM) "$$execdir/git-add$X" && \
ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
cp git-add$X "$$execdir/git-add$X"; } && \
{ $(foreach p,$(filter-out git-add,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
{ $(foreach p,$(filter-out git-add$X,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
ln "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
ln -s "git-add$X" "$$execdir/$p" 2>/dev/null || \
cp "$$execdir/git-add$X" "$$execdir/$p" || exit;) } && \
Expand Down
5 changes: 4 additions & 1 deletion builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1996,14 +1996,17 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
/*
* A hunk to change lines at the beginning would begin with
* @@ -1,L +N,M @@
* but we need to be careful. -U0 that inserts before the second
* line also has this pattern.
*
* And a hunk to add to an empty file would begin with
* @@ -0,0 +N,M @@
*
* In other words, a hunk that is (frag->oldpos <= 1) with or
* without leading context must match at the beginning.
*/
match_beginning = frag->oldpos <= 1;
match_beginning = (!frag->oldpos ||
(frag->oldpos == 1 && !unidiff_zero));

/*
* A hunk without trailing lines must match at the end.
Expand Down
15 changes: 11 additions & 4 deletions builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,12 @@ static void check_object(struct object_entry *entry)
}

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

static int pack_offset_sort(const void *_a, const void *_b)
Expand Down Expand Up @@ -1721,8 +1724,12 @@ static void prepare_pack(int window, int depth)
if (entry->no_try_delta)
continue;

if (!entry->preferred_base)
if (!entry->preferred_base) {
nr_deltas++;
if (entry->type < 0)
die("unable to get type of object %s",
sha1_to_hex(entry->idx.sha1));
}

delta_list[n++] = entry;
}
Expand Down
15 changes: 12 additions & 3 deletions t/t4104-apply-boundary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ test_expect_success setup '
git diff victim >add-a-patch.with &&
git diff --unified=0 >add-a-patch.without &&
: insert at line two
for i in b a '"$L"' y
do
echo $i
done >victim &&
cat victim >insert-a-expect &&
git diff victim >insert-a-patch.with &&
git diff --unified=0 >insert-a-patch.without &&
: modify at the head
for i in a '"$L"' y
do
Expand Down Expand Up @@ -55,7 +64,7 @@ test_expect_success setup '
git diff --unified=0 >add-z-patch.without &&
: modify at the tail
for i in a '"$L"' y
for i in b '"$L"' z
do
echo $i
done >victim &&
Expand All @@ -81,7 +90,7 @@ do
with) u= ;;
without) u='--unidiff-zero ' ;;
esac
for kind in add-a add-z mod-a mod-z del-a del-z
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
do
test_expect_success "apply $kind-patch $with context" '
cat original >victim &&
Expand All @@ -95,7 +104,7 @@ do
done
done

for kind in add-a add-z mod-a mod-z del-a del-z
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
do
rm -f $kind-ng.without
sed -e "s/^diff --git /diff /" \
Expand Down
80 changes: 80 additions & 0 deletions t/t5306-pack-nobase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh
#
# Copyright (c) 2008 Google Inc.
#

test_description='git-pack-object with missing base
'
. ./test-lib.sh

# Create A-B chain
#
test_expect_success \
'setup base' \
'for a in a b c d e f g h i; do echo $a >>text; done &&
echo side >side &&
git update-index --add text side &&
A=$(echo A | git commit-tree $(git write-tree)) &&
echo m >>text &&
git update-index text &&
B=$(echo B | git commit-tree $(git write-tree) -p $A) &&
git update-ref HEAD $B
'

# Create repository with C whose parent is B.
# Repository contains C, C^{tree}, C:text, B, B^{tree}.
# Repository is missing B:text (best delta base for C:text).
# Repository is missing A (parent of B).
# Repository is missing A:side.
#
test_expect_success \
'setup patch_clone' \
'base_objects=$(pwd)/.git/objects &&
(mkdir patch_clone &&
cd patch_clone &&
git init &&
echo "$base_objects" >.git/objects/info/alternates &&
echo q >>text &&
git read-tree $B &&
git update-index text &&
git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) &&
rm .git/objects/info/alternates &&
git --git-dir=../.git cat-file commit $B |
git hash-object -t commit -w --stdin &&
git --git-dir=../.git cat-file tree "$B^{tree}" |
git hash-object -t tree -w --stdin
) &&
C=$(git --git-dir=patch_clone/.git rev-parse HEAD)
'

# Clone patch_clone indirectly by cloning base and fetching.
#
test_expect_success \
'indirectly clone patch_clone' \
'(mkdir user_clone &&
cd user_clone &&
git init &&
git pull ../.git &&
test $(git rev-parse HEAD) = $B &&
git pull ../patch_clone/.git &&
test $(git rev-parse HEAD) = $C
)
'

# Cloning the patch_clone directly should fail.
#
test_expect_success \
'clone of patch_clone is incomplete' \
'(mkdir user_direct &&
cd user_direct &&
git init &&
test_must_fail git fetch ../patch_clone/.git
)
'

test_done

0 comments on commit 7df437e

Please sign in to comment.