summaryrefslogtreecommitdiff
path: root/ex/v0.21.1/init.html
blob: 058923f37cec235cfc2aade227882146de71088b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>init.c</title>
  <link rel="stylesheet" href="../css.css">
  <style type="text/css">
    a.fnlink {text-decoration: none}
    a.fnlink:hover {text-decoration: underline}
  </style>
</head>
<body>
<div id='container'>
  <div id="background"></div>
  <div id="jump_to">
    Jump To &hellip;
    <div id="jump_wrapper">
      <div id="jump_page">
        <a class="source" href="../../#v0.21.1">API Docs</a>
          <a class="source" href="add.html">add.c</a>
          <a class="source" href="blame.html">blame.c</a>
          <a class="source" href="cat-file.html">cat-file.c</a>
          <a class="source" href="common.html">common.c</a>
          <a class="source" href="diff.html">diff.c</a>
          <a class="source" href="for-each-ref.html">for-each-ref.c</a>
          <a class="source" href="general.html">general.c</a>
          <a class="source" href="init.html">init.c</a>
          <a class="source" href="log.html">log.c</a>
          <a class="source" href="network/clone.html">clone.c</a>
          <a class="source" href="network/common.html">common.c</a>
          <a class="source" href="network/fetch.html">fetch.c</a>
          <a class="source" href="network/git2.html">git2.c</a>
          <a class="source" href="network/index-pack.html">index-pack.c</a>
          <a class="source" href="network/ls-remote.html">ls-remote.c</a>
          <a class="source" href="rev-list.html">rev-list.c</a>
          <a class="source" href="rev-parse.html">rev-parse.c</a>
          <a class="source" href="showindex.html">showindex.c</a>
          <a class="source" href="status.html">status.c</a>
          <a class="source" href="tag.html">tag.c</a>
      </div>
    </div>
  </div>
  <table cellspacing=0 cellpadding=0>
  <thead>
    <tr>
      <th class=docs><h1>init.c</h1></th>
      <th class=code></th>
    </tr>
  </thead>
  <tbody>
    <tr id='section-1'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-1">&#182;</a>
        </div>
        
      </td>
      <td class=code>
        <div class='highlight'><pre><span class="cm">/*</span>
<span class="cm"> * libgit2 &quot;init&quot; example - shows how to initialize a new repo</span>
<span class="cm"> *</span>
<span class="cm"> * Written by the libgit2 contributors</span>
<span class="cm"> *</span>
<span class="cm"> * To the extent possible under law, the author(s) have dedicated all copyright</span>
<span class="cm"> * and related and neighboring rights to this software to the public domain</span>
<span class="cm"> * worldwide. This software is distributed without any warranty.</span>
<span class="cm"> *</span>
<span class="cm"> * You should have received a copy of the CC0 Public Domain Dedication along</span>
<span class="cm"> * with this software. If not, see</span>
<span class="cm"> * &lt;http://creativecommons.org/publicdomain/zero/1.0/&gt;.</span>
<span class="cm"> */</span>

<span class="cp">#include &quot;common.h&quot;</span></pre></div>
      </td>
    </tr>
    <tr id='section-2'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-2">&#182;</a>
        </div>
        <p>This is a sample program that is similar to &quot;git init&quot;.  See the
documentation for that (try &quot;git help init&quot;) to understand what this
program is emulating.</p>

<p>This demonstrates using the libgit2 APIs to initialize a new repository.</p>

<p>This also contains a special additional option that regular &quot;git init&quot;
does not support which is &quot;--initial-commit&quot; to make a first empty commit.
That is demonstrated in the &quot;create<em>initial</em>commit&quot; helper function.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre></pre></div>
      </td>
    </tr>
    <tr id='section-3'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-3">&#182;</a>
        </div>
        <p>Forward declarations of helpers</p>
      </td>
      <td class=code>
        <div class='highlight'><pre><span class="k">struct</span> <span class="n">opts</span> <span class="p">{</span>
  <span class="kt">int</span> <span class="n">no_options</span><span class="p">;</span>
  <span class="kt">int</span> <span class="n">quiet</span><span class="p">;</span>
  <span class="kt">int</span> <span class="n">bare</span><span class="p">;</span>
  <span class="kt">int</span> <span class="n">initial_commit</span><span class="p">;</span>
  <span class="kt">uint32_t</span> <span class="n">shared</span><span class="p">;</span>
  <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">template</span><span class="p">;</span>
  <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">gitdir</span><span class="p">;</span>
  <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">dir</span><span class="p">;</span>
<span class="p">};</span>
<span class="k">static</span> <span class="kt">void</span> <span class="nf">create_initial_commit</span><span class="p">(</span><span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">);</span>
<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">struct</span> <span class="n">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[]);</span>


<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
  <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
  <span class="k">struct</span> <span class="n">opts</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_UMASK</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">};</span>

  <span class="n"><a name="git_threads_init-6" class="fnlink" href="../../#v0.21.1/group/threads/git_threads_init">git_threads_init</a></span><span class="p">();</span>

  <span class="n">parse_opts</span><span class="p">(</span><span class="o">&amp;</span><span class="n">o</span><span class="p">,</span> <span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">);</span>

  <span class="cm">/* Initialize repository. */</span>

  <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">no_options</span><span class="p">)</span> <span class="p">{</span></pre></div>
      </td>
    </tr>
    <tr id='section-4'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-4">&#182;</a>
        </div>
        <p>No options were specified, so let&#39;s demonstrate the default
simple case of git<em>repository</em>init() API usage...</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>    <span class="n">check_lg2</span><span class="p">(</span><span class="n">git_repository_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">dir</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
      <span class="s">&quot;Could not initialize repository&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
  <span class="p">}</span>
  <span class="k">else</span> <span class="p">{</span></pre></div>
      </td>
    </tr>
    <tr id='section-5'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-5">&#182;</a>
        </div>
        <p>Some command line options were specified, so we&#39;ll use the
extended init API to handle them</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>    <span class="n">git_repository_init_options</span> <span class="n">initopts</span> <span class="o">=</span> <span class="n">GIT_REPOSITORY_INIT_OPTIONS_INIT</span><span class="p">;</span>
    <span class="n">initopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">GIT_REPOSITORY_INIT_MKPATH</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">bare</span><span class="p">)</span>
      <span class="n">initopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_REPOSITORY_INIT_BARE</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">template</span><span class="p">)</span> <span class="p">{</span>
      <span class="n">initopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE</span><span class="p">;</span>
      <span class="n">initopts</span><span class="p">.</span><span class="n">template_path</span> <span class="o">=</span> <span class="n">o</span><span class="p">.</span><span class="n">template</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">gitdir</span><span class="p">)</span> <span class="p">{</span></pre></div>
      </td>
    </tr>
    <tr id='section-6'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-6">&#182;</a>
        </div>
        <p>If you specified a separate git directory, then initialize
the repository at that path and use the second path as the
working directory of the repository (with a git-link file)</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>      <span class="n">initopts</span><span class="p">.</span><span class="n">workdir_path</span> <span class="o">=</span> <span class="n">o</span><span class="p">.</span><span class="n">dir</span><span class="p">;</span>
      <span class="n">o</span><span class="p">.</span><span class="n">dir</span> <span class="o">=</span> <span class="n">o</span><span class="p">.</span><span class="n">gitdir</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">shared</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
      <span class="n">initopts</span><span class="p">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">o</span><span class="p">.</span><span class="n">shared</span><span class="p">;</span>

    <span class="n">check_lg2</span><span class="p">(</span><span class="n">git_repository_init_ext</span><span class="p">(</span><span class="o">&amp;</span><span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">dir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">initopts</span><span class="p">),</span>
        <span class="s">&quot;Could not initialize repository&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
  <span class="p">}</span></pre></div>
      </td>
    </tr>
    <tr id='section-7'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-7">&#182;</a>
        </div>
        <p>Print a message to stdout like &quot;git init&quot; does.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">o</span><span class="p">.</span><span class="n">quiet</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">bare</span> <span class="o">||</span> <span class="n">o</span><span class="p">.</span><span class="n">gitdir</span><span class="p">)</span>
      <span class="n">o</span><span class="p">.</span><span class="n">dir</span> <span class="o">=</span> <span class="n">git_repository_path</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
    <span class="k">else</span>
      <span class="n">o</span><span class="p">.</span><span class="n">dir</span> <span class="o">=</span> <span class="n">git_repository_workdir</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>

    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Initialized empty Git repository in %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">dir</span><span class="p">);</span>
  <span class="p">}</span></pre></div>
      </td>
    </tr>
    <tr id='section-8'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-8">&#182;</a>
        </div>
        <p>As an extension to the basic &quot;git init&quot; command, this example
gives the option to create an empty initial commit.  This is
mostly to demonstrate what it takes to do that, but also some
people like to have that empty base commit in their repo.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">initial_commit</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">create_initial_commit</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Created empty initial commit</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="n">git_repository_free</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
  <span class="n"><a name="git_threads_shutdown-7" class="fnlink" href="../../#v0.21.1/group/threads/git_threads_shutdown">git_threads_shutdown</a></span><span class="p">();</span>

  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span></pre></div>
      </td>
    </tr>
    <tr id='section-9'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-9">&#182;</a>
        </div>
        <p>Unlike regular &quot;git init&quot;, this example shows how to create an initial
empty commit in the repository.  This is the helper function that does
that.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">create_initial_commit</span><span class="p">(</span><span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">git_signature</span> <span class="o">*</span><span class="n">sig</span><span class="p">;</span>
  <span class="n">git_index</span> <span class="o">*</span><span class="n">index</span><span class="p">;</span>
  <span class="n">git_oid</span> <span class="n">tree_id</span><span class="p">,</span> <span class="n">commit_id</span><span class="p">;</span>
  <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</span><span class="p">;</span></pre></div>
      </td>
    </tr>
    <tr id='section-10'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-10">&#182;</a>
        </div>
        <p>First use the config to initialize a commit signature for the user.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_signature_default-4" class="fnlink" href="../../#v0.21.1/group/signature/git_signature_default">git_signature_default</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="p">,</span> <span class="n">repo</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Unable to create a commit signature.&quot;</span><span class="p">,</span>
          <span class="s">&quot;Perhaps &#39;user.name&#39; and &#39;user.email&#39; are not set&quot;</span><span class="p">);</span>

  <span class="cm">/* Now let&#39;s create an empty tree for this commit */</span>

  <span class="k">if</span> <span class="p">(</span><span class="n">git_repository_index</span><span class="p">(</span><span class="o">&amp;</span><span class="n">index</span><span class="p">,</span> <span class="n">repo</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Could not open repository index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span></pre></div>
      </td>
    </tr>
    <tr id='section-11'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-11">&#182;</a>
        </div>
        <p>Outside of this example, you could call git<em>index</em>add_bypath()
here to put actual files into the index.  For our purposes, we&#39;ll
leave it empty for now.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_index_write_tree-3" class="fnlink" href="../../#v0.21.1/group/index/git_index_write_tree">git_index_write_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tree_id</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Unable to write initial tree from index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>

  <span class="n"><a name="git_index_free-2" class="fnlink" href="../../#v0.21.1/group/index/git_index_free">git_index_free</a></span><span class="p">(</span><span class="n">index</span><span class="p">);</span>

  <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_tree_lookup-8" class="fnlink" href="../../#v0.21.1/group/tree/git_tree_lookup">git_tree_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tree</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">tree_id</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Could not look up initial tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span></pre></div>
      </td>
    </tr>
    <tr id='section-12'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-12">&#182;</a>
        </div>
        <p>Ready to create the initial commit.</p>

<p>Normally creating a commit would involve looking up the current
HEAD commit and making that be the parent of the initial commit,
but here this is the first commit so there will be no parent.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_commit_create_v-1" class="fnlink" href="../../#v0.21.1/group/commit/git_commit_create_v">git_commit_create_v</a></span><span class="p">(</span>
      <span class="o">&amp;</span><span class="n">commit_id</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="s">&quot;HEAD&quot;</span><span class="p">,</span> <span class="n">sig</span><span class="p">,</span> <span class="n">sig</span><span class="p">,</span>
      <span class="nb">NULL</span><span class="p">,</span> <span class="s">&quot;Initial commit&quot;</span><span class="p">,</span> <span class="n">tree</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Could not create the initial commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span></pre></div>
      </td>
    </tr>
    <tr id='section-13'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-13">&#182;</a>
        </div>
        <p>Clean up so we don&#39;t leak memory.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="n"><a name="git_tree_free-9" class="fnlink" href="../../#v0.21.1/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">tree</span><span class="p">);</span>
  <span class="n"><a name="git_signature_free-5" class="fnlink" href="../../#v0.21.1/group/signature/git_signature_free">git_signature_free</a></span><span class="p">(</span><span class="n">sig</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span> <span class="nf">usage</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">error</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">arg</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;error: %s &#39;%s&#39;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">error</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
  <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span>
      <span class="s">&quot;usage: init [-q | --quiet] [--bare] [--template=&lt;dir&gt;]</span><span class="se">\n</span><span class="s">&quot;</span>
      <span class="s">&quot;            [--shared[=perms]] [--initial-commit]</span><span class="se">\n</span><span class="s">&quot;</span>
      <span class="s">&quot;            [--separate-git-dir] &lt;directory&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
  <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span></pre></div>
      </td>
    </tr>
    <tr id='section-14'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-14">&#182;</a>
        </div>
        <p>Parse the tail of the --shared= argument.</p>
      </td>
      <td class=code>
        <div class='highlight'><pre><span class="k">static</span> <span class="kt">uint32_t</span> <span class="nf">parse_shared</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">shared</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;false&quot;</span><span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;umask&quot;</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_UMASK</span><span class="p">;</span>

  <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;true&quot;</span><span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_GROUP</span><span class="p">;</span>

  <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;all&quot;</span><span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;world&quot;</span><span class="p">)</span> <span class="o">||</span>
       <span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">shared</span><span class="p">,</span> <span class="s">&quot;everybody&quot;</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_ALL</span><span class="p">;</span>

  <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">shared</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span> <span class="p">{</span>
    <span class="kt">long</span> <span class="n">val</span><span class="p">;</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">end</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
    <span class="n">val</span> <span class="o">=</span> <span class="n">strtol</span><span class="p">(</span><span class="n">shared</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">end</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">end</span> <span class="o">==</span> <span class="n">shared</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">||</span> <span class="o">*</span><span class="n">end</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
      <span class="n">usage</span><span class="p">(</span><span class="s">&quot;invalid octal value for --shared&quot;</span><span class="p">,</span> <span class="n">shared</span><span class="p">);</span>
    <span class="k">return</span> <span class="p">(</span><span class="kt">uint32_t</span><span class="p">)</span><span class="n">val</span><span class="p">;</span>
  <span class="p">}</span>

  <span class="k">else</span>
    <span class="n">usage</span><span class="p">(</span><span class="s">&quot;unknown value for --shared&quot;</span><span class="p">,</span> <span class="n">shared</span><span class="p">);</span>

  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">struct</span> <span class="n">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
  <span class="k">struct</span> <span class="n">args_info</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ARGS_INFO_INIT</span><span class="p">;</span>
  <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">sharedarg</span><span class="p">;</span></pre></div>
      </td>
    </tr>
    <tr id='section-15'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-15">&#182;</a>
        </div>
        <p>Process arguments.</p>

      </td>
      <td class=code>
        <div class='highlight'><pre>  <span class="k">for</span> <span class="p">(</span><span class="n">args</span><span class="p">.</span><span class="n">pos</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">args</span><span class="p">.</span><span class="n">pos</span> <span class="o">&lt;</span> <span class="n">argc</span><span class="p">;</span> <span class="o">++</span><span class="n">args</span><span class="p">.</span><span class="n">pos</span><span class="p">)</span> <span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">a</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="n">args</span><span class="p">.</span><span class="n">pos</span><span class="p">];</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">no_options</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">dir</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span>
        <span class="n">usage</span><span class="p">(</span><span class="s">&quot;extra argument&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">dir</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-q&quot;</span><span class="p">)</span> <span class="o">||</span> <span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--quiet&quot;</span><span class="p">))</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">quiet</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--bare&quot;</span><span class="p">))</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">bare</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--shared&quot;</span><span class="p">))</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">shared</span> <span class="o">=</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_GROUP</span><span class="p">;</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--initial-commit&quot;</span><span class="p">))</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">initial_commit</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sharedarg</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--shared&quot;</span><span class="p">))</span>
      <span class="n">o</span><span class="o">-&gt;</span><span class="n">shared</span> <span class="o">=</span> <span class="n">parse_shared</span><span class="p">(</span><span class="n">sharedarg</span><span class="p">);</span>
    <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">template</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--template&quot;</span><span class="p">)</span> <span class="o">||</span>
             <span class="o">!</span><span class="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">gitdir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--separate-git-dir&quot;</span><span class="p">))</span>
      <span class="n">usage</span><span class="p">(</span><span class="s">&quot;unknown option&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">dir</span><span class="p">)</span>
    <span class="n">usage</span><span class="p">(</span><span class="s">&quot;must specify directory to init&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span></pre></div>
      </td>
    </tr>
  </table>
</div>
</body>