Skip to content

Commit 54c26fb

Browse files
author
Linus Torvalds
committed
Automatic merge of /home/torvalds/junkio/.git/
2 parents aa03413 + ee28152 commit 54c26fb

File tree

7 files changed

+114
-90
lines changed

7 files changed

+114
-90
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PROG= git-update-cache git-diff-files git-init-db git-write-tree \
2121
git-check-files git-ls-tree git-merge-base git-merge-cache \
2222
git-unpack-file git-export git-diff-cache git-convert-cache \
2323
git-http-pull git-rpush git-rpull git-rev-list git-mktag \
24-
git-diff-tree-helper git-tar-tree git-local-pull
24+
git-diff-tree-helper git-tar-tree git-local-pull git-write-blob
2525

2626
all: $(PROG)
2727

@@ -94,6 +94,7 @@ git-rev-list: rev-list.c
9494
git-mktag: mktag.c
9595
git-diff-tree-helper: diff-tree-helper.c
9696
git-tar-tree: tar-tree.c
97+
git-write-blob: write-blob.c
9798

9899
git-http-pull: LIBS += -lcurl
99100

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extern int remove_entry_at(int pos);
116116
extern int remove_file_from_cache(char *path);
117117
extern int same_name(struct cache_entry *a, struct cache_entry *b);
118118
extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
119+
extern int index_fd(unsigned char *sha1, int fd, struct stat *st);
119120

120121
#define MTIME_CHANGED 0x0001
121122
#define CTIME_CHANGED 0x0002

git-apply-patch-script

100644100755
File mode changed.

git-merge-one-file-script

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,69 @@
66
# $2 - file in branch1 SHA1 (or empty)
77
# $3 - file in branch2 SHA1 (or empty)
88
# $4 - pathname in repository
9-
#
9+
# $5 - orignal file mode (or empty)
10+
# $6 - file in branch1 mode (or empty)
11+
# $7 - file in branch2 mode (or empty)
1012
#
1113
# Handle some trivial cases.. The _really_ trivial cases have
1214
# been handled already by git-read-tree, but that one doesn't
13-
# do any merges that migth change the tree layout
14-
#
15-
16-
# if the directory is newly added in a branch, it might not exist
17-
# in the current tree
18-
dir=$(dirname "$4")
19-
mkdir -p "$dir" || exit
15+
# do any merges that migth change the tree layout.
2016

2117
case "${1:-.}${2:-.}${3:-.}" in
2218
#
23-
# deleted in both
19+
# Deleted in both.
2420
#
2521
"$1..")
26-
echo "ERROR: $4 is removed in both branches"
27-
echo "ERROR: This is a potential rename conflict"
22+
echo "ERROR: $4 is removed in both branches."
23+
echo "ERROR: This is a potential rename conflict."
2824
exit 1;;
2925
#
30-
# deleted in one and unchanged in the other
26+
# Deleted in one and unchanged in the other.
3127
#
3228
"$1.." | "$1.$1" | "$1$1.")
3329
echo "Removing $4"
34-
rm -f -- "$4" && exec git-update-cache --remove -- "$4" ;;
30+
exec git-update-cache --force-remove "$4" ;;
3531
#
36-
# added in one
32+
# Added in one.
3733
#
3834
".$2." | "..$3" )
3935
case "$6$7" in *7??) mode=+x;; *) mode=-x;; esac
40-
echo "Adding $4 with perm $mode"
41-
rm -f -- "$4" &&
42-
git-cat-file blob "$2$3" >"$4" &&
43-
chmod "$mode" -- "$4" &&
44-
exec git-update-cache --add -- "$4" ;;
36+
echo "Adding $4 with perm $mode."
37+
exec git-update-cache --add --cacheinfo "$6$7" "$2$3" "$4" ;;
4538
#
46-
# Added in both (check for same permissions)
39+
# Added in both (check for same permissions).
4740
#
48-
".$2$2")
41+
".$3$2")
4942
if [ "$6" != "$7" ]; then
50-
echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
43+
echo "ERROR: File $4 added identically in both branches,"
44+
echo "ERROR: but permissions conflict $6->$7."
5145
exit 1
5246
fi
5347
case "$6" in *7??) mode=+x;; *) mode=-x;; esac
5448
echo "Adding $4 with perm $mode"
55-
rm -f -- "$4" &&
56-
git-cat-file blob "$2" >"$4" &&
57-
chmod "$mode" -- "$4" &&
58-
exec git-update-cache --add -- "$4" ;;
49+
exec git-update-cache --add --cacheinfo "$6" "$2" "$4" ;;
5950
#
60-
# Modified in both, but differently ;(
51+
# Modified in both, but differently.
6152
#
6253
"$1$2$3")
63-
echo "Auto-merging $4"
54+
echo "Auto-merging $4."
6455
orig=$(git-unpack-file $1)
6556
src1=$(git-unpack-file $2)
6657
src2=$(git-unpack-file $3)
6758
merge "$src2" "$orig" "$src1"
6859
ret=$?
6960
if [ "$6" != "$7" ]; then
70-
echo "ERROR: Permissions $5->$6->$7 don't match merging $src2"
71-
if [ $ret -ne 0 ]; then
72-
echo "ERROR: Leaving conflict merge in $src2"
73-
fi
74-
exit 1
61+
echo "ERROR: Permissions $5->$6->$7 don't match."
7562
fi
7663
if [ $ret -ne 0 ]; then
77-
echo "ERROR: Leaving conflict merge in $src2"
64+
echo "ERROR: Leaving conflict merge in $src2."
7865
exit 1
7966
fi
80-
case "$6" in *7??) mode=+x;; *) mode=-x;; esac
81-
rm -f -- "$4" && cat "$src2" >"$4" && chmod "$mode" -- "$4" &&
82-
exec git-update-cache --add -- "$4" ;;
67+
sha1=$(git-write-blob "$src2") || {
68+
echo "ERROR: Leaving conflict merge in $src2."
69+
}
70+
exec git-update-cache --add --cacheinfo "$6" $sha1 "$4" ;;
8371
*)
84-
echo "Not handling case $4: $1 -> $2 -> $3" ;;
72+
echo "ERROR: Not handling case $4: $1 -> $2 -> $3" ;;
8573
esac
8674
exit 1

sha1_file.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,54 @@ int has_sha1_file(const unsigned char *sha1)
460460
return 1;
461461
return 0;
462462
}
463+
464+
int index_fd(unsigned char *sha1, int fd, struct stat *st)
465+
{
466+
z_stream stream;
467+
unsigned long size = st->st_size;
468+
int max_out_bytes = size + 200;
469+
void *out = xmalloc(max_out_bytes);
470+
void *metadata = xmalloc(200);
471+
int metadata_size;
472+
void *in;
473+
SHA_CTX c;
474+
475+
in = "";
476+
if (size)
477+
in = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
478+
close(fd);
479+
if (!out || (int)(long)in == -1)
480+
return -1;
481+
482+
metadata_size = 1+sprintf(metadata, "blob %lu", size);
483+
484+
SHA1_Init(&c);
485+
SHA1_Update(&c, metadata, metadata_size);
486+
SHA1_Update(&c, in, size);
487+
SHA1_Final(sha1, &c);
488+
489+
memset(&stream, 0, sizeof(stream));
490+
deflateInit(&stream, Z_BEST_COMPRESSION);
491+
492+
/*
493+
* ASCII size + nul byte
494+
*/
495+
stream.next_in = metadata;
496+
stream.avail_in = metadata_size;
497+
stream.next_out = out;
498+
stream.avail_out = max_out_bytes;
499+
while (deflate(&stream, 0) == Z_OK)
500+
/* nothing */;
501+
502+
/*
503+
* File content
504+
*/
505+
stream.next_in = in;
506+
stream.avail_in = size;
507+
while (deflate(&stream, Z_FINISH) == Z_OK)
508+
/*nothing */;
509+
510+
deflateEnd(&stream);
511+
512+
return write_sha1_buffer(sha1, out, stream.total_out);
513+
}

update-cache.c

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,6 @@ static inline long IS_ERR(const void *ptr)
3131
return (unsigned long)ptr > (unsigned long)-1000L;
3232
}
3333

34-
static int index_fd(unsigned char *sha1, int fd, struct stat *st)
35-
{
36-
z_stream stream;
37-
unsigned long size = st->st_size;
38-
int max_out_bytes = size + 200;
39-
void *out = xmalloc(max_out_bytes);
40-
void *metadata = xmalloc(200);
41-
int metadata_size;
42-
void *in;
43-
SHA_CTX c;
44-
45-
in = "";
46-
if (size)
47-
in = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
48-
close(fd);
49-
if (!out || (int)(long)in == -1)
50-
return -1;
51-
52-
metadata_size = 1+sprintf(metadata, "blob %lu", size);
53-
54-
SHA1_Init(&c);
55-
SHA1_Update(&c, metadata, metadata_size);
56-
SHA1_Update(&c, in, size);
57-
SHA1_Final(sha1, &c);
58-
59-
memset(&stream, 0, sizeof(stream));
60-
deflateInit(&stream, Z_BEST_COMPRESSION);
61-
62-
/*
63-
* ASCII size + nul byte
64-
*/
65-
stream.next_in = metadata;
66-
stream.avail_in = metadata_size;
67-
stream.next_out = out;
68-
stream.avail_out = max_out_bytes;
69-
while (deflate(&stream, 0) == Z_OK)
70-
/* nothing */;
71-
72-
/*
73-
* File content
74-
*/
75-
stream.next_in = in;
76-
stream.avail_in = size;
77-
while (deflate(&stream, Z_FINISH) == Z_OK)
78-
/*nothing */;
79-
80-
deflateEnd(&stream);
81-
82-
return write_sha1_buffer(sha1, out, stream.total_out);
83-
}
84-
8534
/*
8635
* This only updates the "non-critical" parts of the directory
8736
* cache, ie the parts that aren't tracked by GIT, and only used
@@ -357,6 +306,15 @@ int main(int argc, char **argv)
357306
i += 3;
358307
continue;
359308
}
309+
if (!strcmp(path, "--force-remove")) {
310+
if (argc <= i + 1)
311+
die("update-cache: --force-remove <path>");
312+
if (remove_file_from_cache(argv[i+1]))
313+
die("update-cache: --force-remove cannot remove %s", argv[i+1]);
314+
i++;
315+
continue;
316+
}
317+
360318
if (!strcmp(path, "--ignore-missing")) {
361319
not_new = 1;
362320
continue;

write-blob.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* GIT - The information manager from hell
3+
*
4+
* Copyright (C) Linus Torvalds, 2005
5+
*/
6+
#include "cache.h"
7+
8+
int main(int argc, char **argv)
9+
{
10+
int i;
11+
12+
for (i = 1 ; i < argc; i++) {
13+
char *path = argv[i];
14+
int fd;
15+
struct stat st;
16+
unsigned char sha1[20];
17+
fd = open(path, O_RDONLY);
18+
if (fd < 0 ||
19+
fstat(fd, &st) < 0 ||
20+
index_fd(sha1, fd, &st) < 0)
21+
die("Unable to add blob %s to database", path);
22+
printf("%s\n", sha1_to_hex(sha1));
23+
}
24+
return 0;
25+
}

0 commit comments

Comments
 (0)