1
1
/*
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
+ /**
2
11
* This is a sample program that is similar to "git init". See the
3
12
* documentation for that (try "git help init") to understand what this
4
13
* program is emulating.
8
17
* This also contains a special additional option that regular "git init"
9
18
* does not support which is "--initial-commit" to make a first empty commit.
10
19
* 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.
16
20
*/
17
21
18
- #include "common.h"
19
-
20
- /* forward declarations of helpers */
22
+ /** Forward declarations of helpers */
21
23
struct opts {
22
24
int no_options ;
23
25
int quiet ;
@@ -41,17 +43,19 @@ int main(int argc, char *argv[])
41
43
42
44
parse_opts (& o , argc , argv );
43
45
44
- /* Initialize repository */
46
+ /* Initialize repository. */
45
47
46
48
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
48
51
* simple case of git_repository_init() API usage...
49
52
*/
50
53
check_lg2 (git_repository_init (& repo , o .dir , 0 ),
51
54
"Could not initialize repository" , NULL );
52
55
}
53
56
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
55
59
* extended init API to handle them
56
60
*/
57
61
git_repository_init_options initopts = GIT_REPOSITORY_INIT_OPTIONS_INIT ;
@@ -66,7 +70,8 @@ int main(int argc, char *argv[])
66
70
}
67
71
68
72
if (o .gitdir ) {
69
- /* if you specified a separate git directory, then initialize
73
+ /**
74
+ * If you specified a separate git directory, then initialize
70
75
* the repository at that path and use the second path as the
71
76
* working directory of the repository (with a git-link file)
72
77
*/
@@ -81,7 +86,7 @@ int main(int argc, char *argv[])
81
86
"Could not initialize repository" , NULL );
82
87
}
83
88
84
- /* Print a message to stdout like "git init" does */
89
+ /** Print a message to stdout like "git init" does. */
85
90
86
91
if (!o .quiet ) {
87
92
if (o .bare || o .gitdir )
@@ -92,7 +97,8 @@ int main(int argc, char *argv[])
92
97
printf ("Initialized empty Git repository in %s\n" , o .dir );
93
98
}
94
99
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
96
102
* gives the option to create an empty initial commit. This is
97
103
* mostly to demonstrate what it takes to do that, but also some
98
104
* people like to have that empty base commit in their repo.
@@ -108,7 +114,8 @@ int main(int argc, char *argv[])
108
114
return 0 ;
109
115
}
110
116
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
112
119
* empty commit in the repository. This is the helper function that does
113
120
* that.
114
121
*/
@@ -119,7 +126,7 @@ static void create_initial_commit(git_repository *repo)
119
126
git_oid tree_id , commit_id ;
120
127
git_tree * tree ;
121
128
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. */
123
130
124
131
if (git_signature_default (& sig , repo ) < 0 )
125
132
fatal ("Unable to create a commit signature." ,
@@ -130,7 +137,8 @@ static void create_initial_commit(git_repository *repo)
130
137
if (git_repository_index (& index , repo ) < 0 )
131
138
fatal ("Could not open repository index" , NULL );
132
139
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()
134
142
* here to put actual files into the index. For our purposes, we'll
135
143
* leave it empty for now.
136
144
*/
@@ -143,7 +151,8 @@ static void create_initial_commit(git_repository *repo)
143
151
if (git_tree_lookup (& tree , repo , & tree_id ) < 0 )
144
152
fatal ("Could not look up initial tree" , NULL );
145
153
146
- /* Ready to create the initial commit
154
+ /**
155
+ * Ready to create the initial commit.
147
156
*
148
157
* Normally creating a commit would involve looking up the current
149
158
* HEAD commit and making that be the parent of the initial commit,
@@ -155,7 +164,7 @@ static void create_initial_commit(git_repository *repo)
155
164
NULL , "Initial commit" , tree , 0 ) < 0 )
156
165
fatal ("Could not create the initial commit" , NULL );
157
166
158
- /* Clean up so we don't leak memory */
167
+ /** Clean up so we don't leak memory. */
159
168
160
169
git_tree_free (tree );
161
170
git_signature_free (sig );
@@ -171,7 +180,7 @@ static void usage(const char *error, const char *arg)
171
180
exit (1 );
172
181
}
173
182
174
- /* parse the tail of the --shared= argument */
183
+ /** Parse the tail of the --shared= argument. */
175
184
static uint32_t parse_shared (const char * shared )
176
185
{
177
186
if (!strcmp (shared , "false" ) || !strcmp (shared , "umask" ))
@@ -204,7 +213,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
204
213
struct args_info args = ARGS_INFO_INIT ;
205
214
const char * sharedarg ;
206
215
207
- /* Process arguments */
216
+ /** Process arguments. */
208
217
209
218
for (args .pos = 1 ; args .pos < argc ; ++ args .pos ) {
210
219
char * a = argv [args .pos ];
0 commit comments