Permalink
Browse files

examples/network: consistently use tabs for indentation

  • Loading branch information...
1 parent 88bfe79 commit 7eeec8f22d2872ac2c88fd27818222537a1d6e37 @carlosmn carlosmn committed May 24, 2012
Showing with 126 additions and 126 deletions.
  1. +50 −50 examples/network/fetch.c
  2. +76 −76 examples/network/index-pack.c
@@ -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)
{
- git_remote *remote = NULL;
- git_off_t bytes = 0;
- git_indexer_stats stats;
- pthread_t worker;
- struct dl_data data;
-
- // Figure out whether it's a named remote or a URL
- printf("Fetching %s\n", argv[1]);
- if (git_remote_load(&remote, repo, argv[1]) < 0) {
- if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0)
- return -1;
- }
-
- // Set up the information for the background worker thread
- data.remote = remote;
- data.bytes = &bytes;
- data.stats = &stats;
- data.ret = 0;
- data.finished = 0;
- memset(&stats, 0, sizeof(stats));
-
- pthread_create(&worker, NULL, download, &data);
-
- // Loop while the worker thread is still running. Here we show processed
- // and total objects in the pack and the amount of received
- // data. Most frontends will probably want to show a percentage and
- // the download rate.
- do {
- usleep(10000);
- printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
- } while (!data.finished);
- printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
-
- // Disconnect the underlying connection to prevent from idling.
- git_remote_disconnect(remote);
-
- // Update the references in the remote's namespace to point to the
- // right commits. This may be needed even if there was no packfile
- // to download, which can happen e.g. when the branches have been
- // changed but all the neede objects are available locally.
- if (git_remote_update_tips(remote, update_cb) < 0)
- return -1;
-
- git_remote_free(remote);
-
- return 0;
-
-on_error:
- git_remote_free(remote);
- return -1;
+ git_remote *remote = NULL;
+ git_off_t bytes = 0;
+ git_indexer_stats stats;
+ pthread_t worker;
+ struct dl_data data;
+
+ // Figure out whether it's a named remote or a URL
+ printf("Fetching %s\n", argv[1]);
+ if (git_remote_load(&remote, repo, argv[1]) < 0) {
+ if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0)
+ return -1;
+ }
+
+ // Set up the information for the background worker thread
+ data.remote = remote;
+ data.bytes = &bytes;
+ data.stats = &stats;
+ data.ret = 0;
+ data.finished = 0;
+ memset(&stats, 0, sizeof(stats));
+
+ pthread_create(&worker, NULL, download, &data);
+
+ // Loop while the worker thread is still running. Here we show processed
+ // and total objects in the pack and the amount of received
+ // data. Most frontends will probably want to show a percentage and
+ // the download rate.
+ do {
+ usleep(10000);
+ printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
+ } while (!data.finished);
+ printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
+
+ // Disconnect the underlying connection to prevent from idling.
+ git_remote_disconnect(remote);
+
+ // Update the references in the remote's namespace to point to the
+ // right commits. This may be needed even if there was no packfile
+ // to download, which can happen e.g. when the branches have been
+ // changed but all the neede objects are available locally.
+ if (git_remote_update_tips(remote, update_cb) < 0)
+ return -1;
+
+ git_remote_free(remote);
+
+ return 0;
+
+ on_error:
+ git_remote_free(remote);
+ return -1;
}
@@ -8,95 +8,95 @@
// the indexing to finish in a worker thread
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)
{
- git_indexer_stream *idx;
- git_indexer_stats stats = {0, 0};
- int error, fd;
- char hash[GIT_OID_HEXSZ + 1] = {0};
- ssize_t read_bytes;
- char buf[512];
-
- if (argc < 2) {
- fprintf(stderr, "I need a packfile\n");
- return EXIT_FAILURE;
- }
-
- if (git_indexer_stream_new(&idx, ".git") < 0) {
- puts("bad idx");
- return -1;
- }
-
- if ((fd = open(argv[1], 0)) < 0) {
- perror("open");
- return -1;
- }
-
- do {
- read_bytes = read(fd, buf, sizeof(buf));
- if (read_bytes < 0)
- break;
-
- if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
- goto cleanup;
-
- printf("\rIndexing %d of %d", stats.processed, stats.total);
- } while (read_bytes > 0);
-
- if (read_bytes < 0) {
- error = -1;
- perror("failed reading");
- goto cleanup;
- }
-
- if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
- goto cleanup;
-
- printf("\rIndexing %d of %d\n", stats.processed, stats.total);
-
- git_oid_fmt(hash, git_indexer_stream_hash(idx));
- puts(hash);
-
-cleanup:
- close(fd);
- git_indexer_stream_free(idx);
- return error;
+ git_indexer_stream *idx;
+ git_indexer_stats stats = {0, 0};
+ int error, fd;
+ char hash[GIT_OID_HEXSZ + 1] = {0};
+ ssize_t read_bytes;
+ char buf[512];
+
+ if (argc < 2) {
+ fprintf(stderr, "I need a packfile\n");
+ return EXIT_FAILURE;
+ }
+
+ if (git_indexer_stream_new(&idx, ".git") < 0) {
+ puts("bad idx");
+ return -1;
+ }
+
+ if ((fd = open(argv[1], 0)) < 0) {
+ perror("open");
+ return -1;
+ }
+
+ do {
+ read_bytes = read(fd, buf, sizeof(buf));
+ if (read_bytes < 0)
+ break;
+
+ if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
+ goto cleanup;
+
+ printf("\rIndexing %d of %d", stats.processed, stats.total);
+ } while (read_bytes > 0);
+
+ if (read_bytes < 0) {
+ error = -1;
+ perror("failed reading");
+ goto cleanup;
+ }
+
+ if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
+ goto cleanup;
+
+ printf("\rIndexing %d of %d\n", stats.processed, stats.total);
+
+ git_oid_fmt(hash, git_indexer_stream_hash(idx));
+ puts(hash);
+
+ cleanup:
+ close(fd);
+ git_indexer_stream_free(idx);
+ return error;
}
int index_pack_old(git_repository *repo, int argc, char **argv)
{
- git_indexer *indexer;
- git_indexer_stats stats;
- int error;
- char hash[GIT_OID_HEXSZ + 1] = {0};
+ git_indexer *indexer;
+ git_indexer_stats stats;
+ int error;
+ char hash[GIT_OID_HEXSZ + 1] = {0};
- if (argc < 2) {
- fprintf(stderr, "I need a packfile\n");
- return EXIT_FAILURE;
- }
+ if (argc < 2) {
+ fprintf(stderr, "I need a packfile\n");
+ return EXIT_FAILURE;
+ }
- // Create a new indexer
- error = git_indexer_new(&indexer, argv[1]);
- if (error < 0)
- return error;
+ // Create a new indexer
+ error = git_indexer_new(&indexer, argv[1]);
+ if (error < 0)
+ return error;
- // Index the packfile. This function can take a very long time and
- // should be run in a worker thread.
- error = git_indexer_run(indexer, &stats);
- if (error < 0)
- return error;
+ // Index the packfile. This function can take a very long time and
+ // should be run in a worker thread.
+ error = git_indexer_run(indexer, &stats);
+ if (error < 0)
+ return error;
- // Write the information out to an index file
- error = git_indexer_write(indexer);
+ // Write the information out to an index file
+ error = git_indexer_write(indexer);
- // Get the packfile's hash (which should become it's filename)
- git_oid_fmt(hash, git_indexer_hash(indexer));
- puts(hash);
+ // Get the packfile's hash (which should become it's filename)
+ git_oid_fmt(hash, git_indexer_hash(indexer));
+ puts(hash);
- git_indexer_free(indexer);
+ git_indexer_free(indexer);
- return 0;
+ return 0;
}

0 comments on commit 7eeec8f

Please sign in to comment.