Commit 7eeec8f2 by Carlos Martín Nieto

examples/network: consistently use tabs for indentation

parent 88bfe790
...@@ -60,54 +60,54 @@ int update_cb(const char *refname, const git_oid *a, const git_oid *b) ...@@ -60,54 +60,54 @@ int update_cb(const char *refname, const git_oid *a, const git_oid *b)
int fetch(git_repository *repo, int argc, char **argv) int fetch(git_repository *repo, int argc, char **argv)
{ {
git_remote *remote = NULL; git_remote *remote = NULL;
git_off_t bytes = 0; git_off_t bytes = 0;
git_indexer_stats stats; git_indexer_stats stats;
pthread_t worker; pthread_t worker;
struct dl_data data; struct dl_data data;
// Figure out whether it's a named remote or a URL // Figure out whether it's a named remote or a URL
printf("Fetching %s\n", argv[1]); printf("Fetching %s\n", argv[1]);
if (git_remote_load(&remote, repo, argv[1]) < 0) { if (git_remote_load(&remote, repo, argv[1]) < 0) {
if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0) if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0)
return -1; return -1;
} }
// Set up the information for the background worker thread // Set up the information for the background worker thread
data.remote = remote; data.remote = remote;
data.bytes = &bytes; data.bytes = &bytes;
data.stats = &stats; data.stats = &stats;
data.ret = 0; data.ret = 0;
data.finished = 0; data.finished = 0;
memset(&stats, 0, sizeof(stats)); memset(&stats, 0, sizeof(stats));
pthread_create(&worker, NULL, download, &data); pthread_create(&worker, NULL, download, &data);
// Loop while the worker thread is still running. Here we show processed // Loop while the worker thread is still running. Here we show processed
// and total objects in the pack and the amount of received // and total objects in the pack and the amount of received
// data. Most frontends will probably want to show a percentage and // data. Most frontends will probably want to show a percentage and
// the download rate. // the download rate.
do { do {
usleep(10000); usleep(10000);
printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes); printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
} while (!data.finished); } while (!data.finished);
printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes); printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
// Disconnect the underlying connection to prevent from idling. // Disconnect the underlying connection to prevent from idling.
git_remote_disconnect(remote); git_remote_disconnect(remote);
// Update the references in the remote's namespace to point to the // Update the references in the remote's namespace to point to the
// right commits. This may be needed even if there was no packfile // right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been // to download, which can happen e.g. when the branches have been
// changed but all the neede objects are available locally. // changed but all the neede objects are available locally.
if (git_remote_update_tips(remote, update_cb) < 0) if (git_remote_update_tips(remote, update_cb) < 0)
return -1; return -1;
git_remote_free(remote); git_remote_free(remote);
return 0; return 0;
on_error: on_error:
git_remote_free(remote); git_remote_free(remote);
return -1; return -1;
} }
...@@ -8,95 +8,95 @@ ...@@ -8,95 +8,95 @@
// the indexing to finish in a worker thread // the indexing to finish in a worker thread
int index_cb(const git_indexer_stats *stats, void *data) int index_cb(const git_indexer_stats *stats, void *data)
{ {
printf("\rProcessing %d of %d", stats->processed, stats->total); printf("\rProcessing %d of %d", stats->processed, stats->total);
} }
int index_pack(git_repository *repo, int argc, char **argv) int index_pack(git_repository *repo, int argc, char **argv)
{ {
git_indexer_stream *idx; git_indexer_stream *idx;
git_indexer_stats stats = {0, 0}; git_indexer_stats stats = {0, 0};
int error, fd; int error, fd;
char hash[GIT_OID_HEXSZ + 1] = {0}; char hash[GIT_OID_HEXSZ + 1] = {0};
ssize_t read_bytes; ssize_t read_bytes;
char buf[512]; char buf[512];
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "I need a packfile\n"); fprintf(stderr, "I need a packfile\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (git_indexer_stream_new(&idx, ".git") < 0) { if (git_indexer_stream_new(&idx, ".git") < 0) {
puts("bad idx"); puts("bad idx");
return -1; return -1;
} }
if ((fd = open(argv[1], 0)) < 0) { if ((fd = open(argv[1], 0)) < 0) {
perror("open"); perror("open");
return -1; return -1;
} }
do { do {
read_bytes = read(fd, buf, sizeof(buf)); read_bytes = read(fd, buf, sizeof(buf));
if (read_bytes < 0) if (read_bytes < 0)
break; break;
if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0) if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
goto cleanup; goto cleanup;
printf("\rIndexing %d of %d", stats.processed, stats.total); printf("\rIndexing %d of %d", stats.processed, stats.total);
} while (read_bytes > 0); } while (read_bytes > 0);
if (read_bytes < 0) { if (read_bytes < 0) {
error = -1; error = -1;
perror("failed reading"); perror("failed reading");
goto cleanup; goto cleanup;
} }
if ((error = git_indexer_stream_finalize(idx, &stats)) < 0) if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
goto cleanup; goto cleanup;
printf("\rIndexing %d of %d\n", stats.processed, stats.total); printf("\rIndexing %d of %d\n", stats.processed, stats.total);
git_oid_fmt(hash, git_indexer_stream_hash(idx)); git_oid_fmt(hash, git_indexer_stream_hash(idx));
puts(hash); puts(hash);
cleanup: cleanup:
close(fd); close(fd);
git_indexer_stream_free(idx); git_indexer_stream_free(idx);
return error; return error;
} }
int index_pack_old(git_repository *repo, int argc, char **argv) int index_pack_old(git_repository *repo, int argc, char **argv)
{ {
git_indexer *indexer; git_indexer *indexer;
git_indexer_stats stats; git_indexer_stats stats;
int error; int error;
char hash[GIT_OID_HEXSZ + 1] = {0}; char hash[GIT_OID_HEXSZ + 1] = {0};
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "I need a packfile\n"); fprintf(stderr, "I need a packfile\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Create a new indexer // Create a new indexer
error = git_indexer_new(&indexer, argv[1]); error = git_indexer_new(&indexer, argv[1]);
if (error < 0) if (error < 0)
return error; return error;
// Index the packfile. This function can take a very long time and // Index the packfile. This function can take a very long time and
// should be run in a worker thread. // should be run in a worker thread.
error = git_indexer_run(indexer, &stats); error = git_indexer_run(indexer, &stats);
if (error < 0) if (error < 0)
return error; return error;
// Write the information out to an index file // Write the information out to an index file
error = git_indexer_write(indexer); error = git_indexer_write(indexer);
// Get the packfile's hash (which should become it's filename) // Get the packfile's hash (which should become it's filename)
git_oid_fmt(hash, git_indexer_hash(indexer)); git_oid_fmt(hash, git_indexer_hash(indexer));
puts(hash); puts(hash);
git_indexer_free(indexer); git_indexer_free(indexer);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment