Skip to content

Commit 85c6730

Browse files
committed
Format comments for use with docco
1 parent dbdb22b commit 85c6730

File tree

5 files changed

+86
-72
lines changed

5 files changed

+86
-72
lines changed

examples/diff.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "common.h"
99

10-
/*
10+
/**
1111
* This example demonstrates the use of the libgit2 diff APIs to
1212
* create `git_diff` objects and display them, emulating a number of
1313
* core Git `diff` command line options.
@@ -26,11 +26,7 @@ static const char *colors[] = {
2626
"\033[36m" /* cyan */
2727
};
2828

29-
/* this implements very rudimentary colorized output */
30-
static int color_printer(
31-
const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
32-
33-
/* the 'opts' struct captures all the various parsed command line options */
29+
/** The 'opts' struct captures all the various parsed command line options. */
3430
struct opts {
3531
git_diff_options diffopts;
3632
git_diff_find_options findopts;
@@ -43,6 +39,8 @@ struct opts {
4339
};
4440

4541
static void parse_opts(struct opts *o, int argc, char *argv[]);
42+
static int color_printer(
43+
const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
4644

4745
int main(int argc, char *argv[])
4846
{
@@ -61,12 +59,14 @@ int main(int argc, char *argv[])
6159
check_lg2(git_repository_open_ext(&repo, o.dir, 0, NULL),
6260
"Could not open repository", o.dir);
6361

64-
/* Possible argument patterns:
65-
* <sha1> <sha2>
66-
* <sha1> --cached
67-
* <sha1>
68-
* --cached
69-
* nothing
62+
/**
63+
* Possible argument patterns:
64+
*
65+
* * <sha1> <sha2>
66+
* * <sha1> --cached
67+
* * <sha1>
68+
* * --cached
69+
* * nothing
7070
*
7171
* Currently ranged arguments like <sha1>..<sha2> and <sha1>...<sha2>
7272
* are not supported in this example
@@ -100,14 +100,14 @@ int main(int argc, char *argv[])
100100
git_diff_index_to_workdir(&diff, repo, NULL, &o.diffopts),
101101
"diff index to working directory", NULL);
102102

103-
/* apply rename and copy detection if requested */
103+
/** Apply rename and copy detection if requested. */
104104

105105
if ((o.findopts.flags & GIT_DIFF_FIND_ALL) != 0)
106106
check_lg2(
107107
git_diff_find_similar(diff, &o.findopts),
108108
"finding renames and copies", NULL);
109109

110-
/* generate simple output using libgit2 display helper */
110+
/** Generate simple output using libgit2 display helper. */
111111

112112
if (o.color >= 0)
113113
fputs(colors[0], stdout);
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
119119
if (o.color >= 0)
120120
fputs(colors[0], stdout);
121121

122-
/* cleanup before exiting */
122+
/** Cleanup before exiting. */
123123

124124
git_diff_free(diff);
125125
git_tree_free(t1);
@@ -141,6 +141,7 @@ static void usage(const char *message, const char *arg)
141141
exit(1);
142142
}
143143

144+
/** This implements very rudimentary colorized output. */
144145
static int color_printer(
145146
const git_diff_delta *delta,
146147
const git_diff_hunk *hunk,
@@ -177,7 +178,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
177178
{
178179
struct args_info args = ARGS_INFO_INIT;
179180

180-
/* parse arguments as copied from git-diff */
181+
/* Parse arguments as copied from git-diff. */
181182

182183
for (args.pos = 1; args.pos < argc; ++args.pos) {
183184
const char *a = argv[args.pos];

examples/init.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#include "common.h"
9+
10+
/**
211
* This is a sample program that is similar to "git init". See the
312
* documentation for that (try "git help init") to understand what this
413
* program is emulating.
@@ -8,16 +17,9 @@
817
* This also contains a special additional option that regular "git init"
918
* does not support which is "--initial-commit" to make a first empty commit.
1019
* That is demonstrated in the "create_initial_commit" helper function.
11-
*
12-
* Copyright (C) the libgit2 contributors. All rights reserved.
13-
*
14-
* This file is part of libgit2, distributed under the GNU GPL v2 with
15-
* a Linking Exception. For full terms see the included COPYING file.
1620
*/
1721

18-
#include "common.h"
19-
20-
/* forward declarations of helpers */
22+
/** Forward declarations of helpers */
2123
struct opts {
2224
int no_options;
2325
int quiet;
@@ -41,17 +43,19 @@ int main(int argc, char *argv[])
4143

4244
parse_opts(&o, argc, argv);
4345

44-
/* Initialize repository */
46+
/* Initialize repository. */
4547

4648
if (o.no_options) {
47-
/* No options were specified, so let's demonstrate the default
49+
/**
50+
* No options were specified, so let's demonstrate the default
4851
* simple case of git_repository_init() API usage...
4952
*/
5053
check_lg2(git_repository_init(&repo, o.dir, 0),
5154
"Could not initialize repository", NULL);
5255
}
5356
else {
54-
/* Some command line options were specified, so we'll use the
57+
/**
58+
* Some command line options were specified, so we'll use the
5559
* extended init API to handle them
5660
*/
5761
git_repository_init_options initopts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
@@ -66,7 +70,8 @@ int main(int argc, char *argv[])
6670
}
6771

6872
if (o.gitdir) {
69-
/* if you specified a separate git directory, then initialize
73+
/**
74+
* If you specified a separate git directory, then initialize
7075
* the repository at that path and use the second path as the
7176
* working directory of the repository (with a git-link file)
7277
*/
@@ -81,7 +86,7 @@ int main(int argc, char *argv[])
8186
"Could not initialize repository", NULL);
8287
}
8388

84-
/* Print a message to stdout like "git init" does */
89+
/** Print a message to stdout like "git init" does. */
8590

8691
if (!o.quiet) {
8792
if (o.bare || o.gitdir)
@@ -92,7 +97,8 @@ int main(int argc, char *argv[])
9297
printf("Initialized empty Git repository in %s\n", o.dir);
9398
}
9499

95-
/* As an extension to the basic "git init" command, this example
100+
/**
101+
* As an extension to the basic "git init" command, this example
96102
* gives the option to create an empty initial commit. This is
97103
* mostly to demonstrate what it takes to do that, but also some
98104
* people like to have that empty base commit in their repo.
@@ -108,7 +114,8 @@ int main(int argc, char *argv[])
108114
return 0;
109115
}
110116

111-
/* Unlike regular "git init", this example shows how to create an initial
117+
/**
118+
* Unlike regular "git init", this example shows how to create an initial
112119
* empty commit in the repository. This is the helper function that does
113120
* that.
114121
*/
@@ -119,7 +126,7 @@ static void create_initial_commit(git_repository *repo)
119126
git_oid tree_id, commit_id;
120127
git_tree *tree;
121128

122-
/* First use the config to initialize a commit signature for the user */
129+
/** First use the config to initialize a commit signature for the user. */
123130

124131
if (git_signature_default(&sig, repo) < 0)
125132
fatal("Unable to create a commit signature.",
@@ -130,7 +137,8 @@ static void create_initial_commit(git_repository *repo)
130137
if (git_repository_index(&index, repo) < 0)
131138
fatal("Could not open repository index", NULL);
132139

133-
/* Outside of this example, you could call git_index_add_bypath()
140+
/**
141+
* Outside of this example, you could call git_index_add_bypath()
134142
* here to put actual files into the index. For our purposes, we'll
135143
* leave it empty for now.
136144
*/
@@ -143,7 +151,8 @@ static void create_initial_commit(git_repository *repo)
143151
if (git_tree_lookup(&tree, repo, &tree_id) < 0)
144152
fatal("Could not look up initial tree", NULL);
145153

146-
/* Ready to create the initial commit
154+
/**
155+
* Ready to create the initial commit.
147156
*
148157
* Normally creating a commit would involve looking up the current
149158
* HEAD commit and making that be the parent of the initial commit,
@@ -155,7 +164,7 @@ static void create_initial_commit(git_repository *repo)
155164
NULL, "Initial commit", tree, 0) < 0)
156165
fatal("Could not create the initial commit", NULL);
157166

158-
/* Clean up so we don't leak memory */
167+
/** Clean up so we don't leak memory. */
159168

160169
git_tree_free(tree);
161170
git_signature_free(sig);
@@ -171,7 +180,7 @@ static void usage(const char *error, const char *arg)
171180
exit(1);
172181
}
173182

174-
/* parse the tail of the --shared= argument */
183+
/** Parse the tail of the --shared= argument. */
175184
static uint32_t parse_shared(const char *shared)
176185
{
177186
if (!strcmp(shared, "false") || !strcmp(shared, "umask"))
@@ -204,7 +213,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
204213
struct args_info args = ARGS_INFO_INIT;
205214
const char *sharedarg;
206215

207-
/* Process arguments */
216+
/** Process arguments. */
208217

209218
for (args.pos = 1; args.pos < argc; ++args.pos) {
210219
char *a = argv[args.pos];

0 commit comments

Comments
 (0)