File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 15
15
16
16
PROG = update-cache show-diff init-db write-tree read-tree commit-tree \
17
17
cat-file fsck-cache checkout-cache diff-tree rev-tree show-files \
18
- check-files ls-tree merge-base merge-cache
18
+ check-files ls-tree merge-base merge-cache unpack-file
19
19
20
20
all : $(PROG )
21
21
@@ -78,6 +78,9 @@ merge-base: merge-base.o $(LIB_FILE) object.o commit.o tree.o blob.o
78
78
merge-cache : merge-cache.o $(LIB_FILE )
79
79
$(CC ) $(CFLAGS ) -o merge-cache merge-cache.o $(LIBS )
80
80
81
+ unpack-file : unpack-file.o $(LIB_FILE )
82
+ $(CC ) $(CFLAGS ) -o unpack-file unpack-file.o $(LIBS )
83
+
81
84
blob.o : $(LIB_H )
82
85
cat-file.o : $(LIB_H )
83
86
check-files.o : $(LIB_H )
@@ -100,6 +103,7 @@ show-files.o: $(LIB_H)
100
103
tree.o : $(LIB_H )
101
104
update-cache.o : $(LIB_H )
102
105
usage.o : $(LIB_H )
106
+ unpack-file.o : $(LIB_H )
103
107
write-tree.o : $(LIB_H )
104
108
105
109
clean :
Original file line number Diff line number Diff line change
1
+ #include "cache.h"
2
+
3
+ static char * create_temp_file (unsigned char * sha1 )
4
+ {
5
+ static char path [50 ];
6
+ void * buf ;
7
+ char type [100 ];
8
+ unsigned long size ;
9
+ int fd ;
10
+
11
+ buf = read_sha1_file (sha1 , type , & size );
12
+ if (!buf || strcmp (type , "blob" ))
13
+ die ("unable to read blob object %s" , sha1_to_hex (sha1 ));
14
+
15
+ strcpy (path , ".merge_file_XXXXXX" );
16
+ fd = mkstemp (path );
17
+ if (fd < 0 )
18
+ die ("unable to create temp-file" );
19
+ if (write (fd , buf , size ) != size )
20
+ die ("unable to write temp-file" );
21
+ close (fd );
22
+ return path ;
23
+ }
24
+
25
+ int main (int argc , char * * argv )
26
+ {
27
+ unsigned char sha1 [20 ];
28
+
29
+ if (argc != 2 || get_sha1_hex (argv [1 ], sha1 ))
30
+ usage ("unpack-file.c <sha1>" );
31
+
32
+ puts (create_temp_file (sha1 ));
33
+ return 0 ;
34
+ }
You can’t perform that action at this time.
0 commit comments