summaryrefslogtreecommitdiff
path: root/examples/network
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/Makefile11
-rw-r--r--examples/network/fetch.c32
-rw-r--r--examples/network/ls-remote.c46
3 files changed, 11 insertions, 78 deletions
diff --git a/examples/network/Makefile b/examples/network/Makefile
index 59a607632..ed0c2099f 100644
--- a/examples/network/Makefile
+++ b/examples/network/Makefile
@@ -1,17 +1,8 @@
default: all
-# If you've installed libgit2 to a non-standard location, you can use
-# these lines to make pkg-config find it.
-
-#LIBGIT2_PATH ?= $(HOME)/staging/libgit2/lib DEPS =
-#$(shell PKG_CONFIG_PATH=$(LIBGIT2_PATH)/pkgconfig pkg-config --cflags
-#--libs libgit2)
-
-DEPS = $(shell pkg-config --cflags --libs libgit2)
-
CC = gcc
CFLAGS += -g
-CFLAGS += $(DEPS)
+CFLAGS += -I../../include -L../../ -lgit2
OBJECTS = \
git2.o \
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index dd732f22e..cdd4a4662 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -4,23 +4,6 @@
#include <stdlib.h>
#include <string.h>
-static void show_refs(git_headarray *refs)
-{
- int i;
- git_remote_head *head;
-
- if(refs->len == 0)
- puts("Everything up-to-date");
-
- for(i = 0; i < refs->len; ++i){
- char oid[GIT_OID_HEXSZ + 1] = {0};
- char *havewant;
- head = refs->heads[i];
- git_oid_fmt(oid, &head->oid);
- printf("%s\t%s\n", oid, head->name);
- }
-}
-
static int rename_packfile(char *packname, git_indexer *idx)
{
char path[GIT_PATH_MAX], oid[GIT_OID_HEXSZ + 1], *slash;
@@ -50,20 +33,14 @@ static int rename_packfile(char *packname, git_indexer *idx)
int fetch(git_repository *repo, int argc, char **argv)
{
git_remote *remote = NULL;
- git_config *cfg = NULL;
git_indexer *idx = NULL;
git_indexer_stats stats;
int error;
char *packname = NULL;
- // Load the repository's configuration
- error = git_repository_config(&cfg, repo, NULL, NULL);
- if (error < GIT_SUCCESS)
- return error;
-
// Get the remote and connect to it
printf("Fetching %s\n", argv[1]);
- error = git_remote_get(&remote, cfg, argv[1]);
+ error = git_remote_new(&remote, repo, argv[1], NULL);
if (error < GIT_SUCCESS)
return error;
@@ -71,13 +48,6 @@ int fetch(git_repository *repo, int argc, char **argv)
if (error < GIT_SUCCESS)
return error;
- // Perform the packfile negotiation. This is where the two ends
- // figure out the minimal amount of data that should be transmitted
- // to bring the repository up-to-date
- error = git_remote_negotiate(remote);
- if (error < GIT_SUCCESS)
- return error;
-
// Download the packfile from the server. As we don't know its hash
// yet, it will get a temporary filename
error = git_remote_download(&packname, remote);
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index 77a9f215d..02d432e8b 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -4,31 +4,22 @@
#include <string.h>
#include "common.h"
-static void show_refs(git_headarray *refs)
+static int show_ref__cb(git_remote_head *head, void *payload)
{
- int i;
- git_remote_head *head;
-
-// Take each head that the remote has advertised, store the string
-// representation of the OID in a buffer and print it
-
- for(i = 0; i < refs->len; ++i){
- char oid[GIT_OID_HEXSZ + 1] = {0};
- head = refs->heads[i];
- git_oid_fmt(oid, &head->oid);
- printf("%s\t%s\n", oid, head->name);
- }
+ char oid[GIT_OID_HEXSZ + 1] = {0};
+ git_oid_fmt(oid, &head->oid);
+ printf("%s\t%s\n", oid, head->name);
+ return GIT_SUCCESS;
}
int use_unnamed(git_repository *repo, const char *url)
{
git_remote *remote = NULL;
- git_headarray refs;
int error;
// Create an instance of a remote from the URL. The transport to use
// is detected from the URL
- error = git_remote_new(&remote, repo, url);
+ error = git_remote_new(&remote, repo, url, NULL);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -39,32 +30,20 @@ int use_unnamed(git_repository *repo, const char *url)
goto cleanup;
// With git_remote_ls we can retrieve the advertised heads
- error = git_remote_ls(remote, &refs);
- if (error < GIT_SUCCESS)
- goto cleanup;
-
- show_refs(&refs);
+ error = git_remote_ls(remote, &show_ref__cb, NULL);
cleanup:
git_remote_free(remote);
-
return error;
}
int use_remote(git_repository *repo, char *name)
{
git_remote *remote = NULL;
- git_config *cfg = NULL;
- git_headarray refs;
int error;
- // Load the local configuration for the repository
- error = git_repository_config(&cfg, repo, NULL, NULL);
- if (error < GIT_SUCCESS)
- return error;
-
// Find the remote by name
- error = git_remote_get(&remote, cfg, name);
+ error = git_remote_load(&remote, repo, name);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -72,15 +51,10 @@ int use_remote(git_repository *repo, char *name)
if (error < GIT_SUCCESS)
goto cleanup;
- error = git_remote_ls(remote, &refs);
- if (error < GIT_SUCCESS)
- goto cleanup;
-
- show_refs(&refs);
+ error = git_remote_ls(remote, &show_ref__cb, NULL);
cleanup:
git_remote_free(remote);
-
return error;
}
@@ -89,8 +63,6 @@ cleanup:
int ls_remote(git_repository *repo, int argc, char **argv)
{
- git_headarray heads;
- git_remote_head *head;
int error, i;
/* If there's a ':' in the name, assume it's an URL */