Skip to contentSkip to conversation

One Git To Rule Them All - Prep 2

PATCH New Jason McMullan 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 One Git To Rule Them All - Prep 2

one-git prep patch 2/2

Make pull.c usable in one-git by making 'fetch' an overridable function pointer, instead of an external function.

http-pull.c +3 -1
@@ -39,7 +39,7 @@ static size_t fwrite_sha1_file(void *ptr
 	return size;
 }
 
-int fetch(unsigned char *sha1)
+static int my_fetch(unsigned char *sha1)
 {
 	char *hex = sha1_to_hex(sha1);
 	char *filename = sha1_file_name(sha1);
@@ -98,6 +98,8 @@ int main(int argc, char **argv)
 	char *url;
 	int arg = 1;
 
+	fetch = my_fetch;
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't') {
 			get_tree = 1;
local-pull.c +3 -1
@@ -11,7 +11,7 @@ static int use_filecopy = 1;
 
 static char *path;
 
-int fetch(unsigned char *sha1)
+static int my_fetch(unsigned char *sha1)
 {
 	static int object_name_start = -1;
 	static char filename[PATH_MAX];
@@ -87,6 +87,8 @@ int main(int argc, char **argv)
 	char *commit_id;
 	int arg = 1;
 
+	fetch = my_fetch;
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't')
 			get_tree = 1;
pull.c +8 -0
@@ -14,6 +14,14 @@ static const char commitS[] = "commit";
 static const char treeS[] = "tree";
 static const char blobS[] = "blob";
 
+int null_fetch(unsigned char *sha1)
+{
+	fprintf(stderr,"fetch() routine not implemented.\n");
+	return -1;
+}
+
+int (*fetch)(unsigned char *sha1) = null_fetch;
+
 void pull_say(const char *fmt, const char *hex) {
 	if (get_verbosely)
 		fprintf(stderr, fmt, hex);
pull.h +1 -1
@@ -2,7 +2,7 @@
 #define PULL_H
 
 /** To be provided by the particular implementation. **/
-extern int fetch(unsigned char *sha1);
+extern int (*fetch)(unsigned char *sha1);
 
 /** Set to fetch the target tree. */
 extern int get_tree;
rpull.c +3 -1
@@ -6,7 +6,7 @@
 static int fd_in;
 static int fd_out;
 
-int fetch(unsigned char *sha1)
+static int my_fetch(unsigned char *sha1)
 {
 	int ret;
 	write(fd_out, sha1, 20);
@@ -22,6 +22,8 @@ int main(int argc, char **argv)
 	char *url;
 	int arg = 1;
 
+	fetch = my_fetch;
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't') {
 			get_tree = 1;