summaryrefslogtreecommitdiff
path: root/ex/v1.6.2
diff options
context:
space:
mode:
Diffstat (limited to 'ex/v1.6.2')
-rw-r--r--ex/v1.6.2/add.html235
-rw-r--r--ex/v1.6.2/args.html62
-rw-r--r--ex/v1.6.2/blame.html328
-rw-r--r--ex/v1.6.2/cat-file.html357
-rw-r--r--ex/v1.6.2/checkout.html457
-rw-r--r--ex/v1.6.2/clone.html62
-rw-r--r--ex/v1.6.2/commit.html168
-rw-r--r--ex/v1.6.2/common.html62
-rw-r--r--ex/v1.6.2/config.html150
-rw-r--r--ex/v1.6.2/describe.html268
-rw-r--r--ex/v1.6.2/diff.html516
-rw-r--r--ex/v1.6.2/fetch.html214
-rw-r--r--ex/v1.6.2/for-each-ref.html62
-rw-r--r--ex/v1.6.2/general.html1167
-rw-r--r--ex/v1.6.2/index-pack.html62
-rw-r--r--ex/v1.6.2/init.html415
-rw-r--r--ex/v1.6.2/lg2.html62
-rw-r--r--ex/v1.6.2/log.html808
-rw-r--r--ex/v1.6.2/ls-files.html209
-rw-r--r--ex/v1.6.2/ls-remote.html153
-rw-r--r--ex/v1.6.2/merge.html439
-rw-r--r--ex/v1.6.2/push.html147
-rw-r--r--ex/v1.6.2/remote.html334
-rw-r--r--ex/v1.6.2/rev-list.html62
-rw-r--r--ex/v1.6.2/rev-parse.html182
-rw-r--r--ex/v1.6.2/show-index.html62
-rw-r--r--ex/v1.6.2/stash.html62
-rw-r--r--ex/v1.6.2/status.html663
-rw-r--r--ex/v1.6.2/tag.html512
29 files changed, 8280 insertions, 0 deletions
diff --git a/ex/v1.6.2/add.html b/ex/v1.6.2/add.html
new file mode 100644
index 000000000..fc615e6af
--- /dev/null
+++ b/ex/v1.6.2/add.html
@@ -0,0 +1,235 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>add.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>add.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;add&quot; example - shows how to modify the index</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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>The following example demonstrates how to add files with libgit2.</p>
+
+<p>It will use the repository in the current working directory, and act
+on files passed as its parameters.</p>
+
+<p>Recognized options are:
+ -v/--verbose: show the file&#39;s status after acting on it.
+ -n/--dry-run: do not actually change the index.
+ -u/--update: update the index instead of adding to it.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">enum</span> <span class="n">index_mode</span> <span class="p">{</span>
+ <span class="n">INDEX_NONE</span><span class="p">,</span>
+ <span class="n">INDEX_ADD</span>
+<span class="p">};</span>
+
+<span class="k">struct</span> <span class="n">index_options</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">dry_run</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">verbose</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">enum</span> <span class="n">index_mode</span> <span class="n">mode</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">add_update</span><span class="p">;</span>
+<span class="p">};</span>
+
+<span class="cm">/* Forward declarations for helpers */</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">repo_path</span><span class="p">,</span> <span class="k">struct</span> <span class="n">index_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">struct</span> <span class="n">args_info</span> <span class="o">*</span><span class="n">args</span><span class="p">);</span>
+<span class="kt">int</span> <span class="nf">print_matched_cb</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">matched_pathspec</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">);</span>
+
+<span class="kt">int</span> <span class="nf">lg2_add</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="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_index_matched_path_cb</span> <span class="n">matched_cb</span> <span class="o">=</span> <span class="nb">NULL</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_strarray</span> <span class="n">array</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="k">struct</span> <span class="n">index_options</span> <span class="n">options</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</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="n">options</span><span class="p">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">INDEX_ADD</span><span class="p">;</span>
+
+ <span class="cm">/* Parse the options &amp; arguments. */</span>
+ <span class="n">parse_opts</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">options</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">);</span>
+ <span class="n">strarray_from_args</span><span class="p">(</span><span class="o">&amp;</span><span class="n">array</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">);</span>
+
+ <span class="cm">/* Grab the repository&#39;s index. */</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_index-5" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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="s">&quot;Could not open repository index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="cm">/* Setup a callback if the requested options need it */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">options</span><span class="p">.</span><span class="n">verbose</span> <span class="o">||</span> <span class="n">options</span><span class="p">.</span><span class="n">dry_run</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">matched_cb</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">print_matched_cb</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">options</span><span class="p">.</span><span class="n">repo</span> <span class="o">=</span> <span class="n">repo</span><span class="p">;</span>
+
+ <span class="cm">/* Perform the requested action with the index and files */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">options</span><span class="p">.</span><span class="n">add_update</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_index_update_all-4" class="fnlink" href="../../#v1.6.2/group/index/git_index_update_all">git_index_update_all</a></span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">array</span><span class="p">,</span> <span class="n">matched_cb</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">options</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n"><a name="git_index_add_all-3" class="fnlink" href="../../#v1.6.2/group/index/git_index_add_all">git_index_add_all</a></span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">array</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">matched_cb</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">options</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Cleanup memory */</span>
+ <span class="n"><a name="git_index_write-2" class="fnlink" href="../../#v1.6.2/group/index/git_index_write">git_index_write</a></span><span class="p">(</span><span class="n">index</span><span class="p">);</span>
+ <span class="n"><a name="git_index_free-1" class="fnlink" href="../../#v1.6.2/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">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="cm">/*</span>
+<span class="cm"> * This callback is called for each file under consideration by</span>
+<span class="cm"> * git_index_(update|add)_all above.</span>
+<span class="cm"> * It makes uses of the callback&#39;s ability to abort the action.</span>
+<span class="cm"> */</span>
+<span class="kt">int</span> <span class="nf">print_matched_cb</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">matched_pathspec</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">struct</span> <span class="n">index_options</span> <span class="o">*</span><span class="n">opts</span> <span class="o">=</span> <span class="p">(</span><span class="k">struct</span> <span class="n">index_options</span> <span class="o">*</span><span class="p">)(</span><span class="n">payload</span><span class="p">);</span>
+ <span class="kt">int</span> <span class="n">ret</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">status</span><span class="p">;</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">matched_pathspec</span><span class="p">;</span>
+
+ <span class="cm">/* Get the file status */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_status_file-6" class="fnlink" href="../../#v1.6.2/group/status/git_status_file">git_status_file</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">status</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_MODIFIED</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_NEW</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;add &#39;%s&#39;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">path</span><span class="p">);</span>
+ <span class="n">ret</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">ret</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">dry_run</span><span class="p">)</span>
+ <span class="n">ret</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">return</span> <span class="n">ret</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_usage</span><span class="p">(</span><span class="kt">void</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;usage: add [options] [--] file-spec [file-spec] [...]</span><span class="se">\n\n</span><span class="s">&quot;</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;</span><span class="se">\t</span><span class="s">-n, --dry-run dry run</span><span class="se">\n</span><span class="s">&quot;</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;</span><span class="se">\t</span><span class="s">-v, --verbose be verbose</span><span class="se">\n</span><span class="s">&quot;</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;</span><span class="se">\t</span><span class="s">-u, --update update tracked files</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>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">repo_path</span><span class="p">,</span> <span class="k">struct</span> <span class="n">index_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">struct</span> <span class="n">args_info</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">argc</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">args</span><span class="o">-&gt;</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="o">-&gt;</span><span class="n">pos</span> <span class="o">&lt;</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">argc</span><span class="p">;</span> <span class="o">++</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">pos</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">curr</span> <span class="o">=</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">pos</span><span class="p">];</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">curr</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="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="s">&quot;add&quot;</span><span class="p">,</span> <span class="n">curr</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">mode</span> <span class="o">=</span> <span class="n">INDEX_ADD</span><span class="p">;</span>
+ <span class="k">continue</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="n">opts</span><span class="o">-&gt;</span><span class="n">mode</span> <span class="o">==</span> <span class="n">INDEX_NONE</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;missing command: %s&quot;</span><span class="p">,</span> <span class="n">curr</span><span class="p">);</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="cm">/* We might be looking at a filename */</span>
+ <span class="k">break</span><span class="p">;</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="n">match_bool_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">verbose</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--verbose&quot;</span><span class="p">)</span> <span class="o">||</span>
+ <span class="n">match_bool_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">dry_run</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--dry-run&quot;</span><span class="p">)</span> <span class="o">||</span>
+ <span class="n">match_str_arg</span><span class="p">(</span><span class="n">repo_path</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">)</span> <span class="o">||</span>
+ <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">mode</span> <span class="o">==</span> <span class="n">INDEX_ADD</span> <span class="o">&amp;&amp;</span> <span class="n">match_bool_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">add_update</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--update&quot;</span><span class="p">)))</span> <span class="p">{</span>
+ <span class="k">continue</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="n">match_bool_arg</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--help&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+ <span class="k">break</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="n">match_arg_separator</span><span class="p">(</span><span class="n">args</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</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;Unsupported option %s.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">curr</span><span class="p">);</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/args.html b/ex/v1.6.2/args.html
new file mode 100644
index 000000000..d1be00751
--- /dev/null
+++ b/ex/v1.6.2/args.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>args.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>args.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/blame.html b/ex/v1.6.2/blame.html
new file mode 100644
index 000000000..8a03b5476
--- /dev/null
+++ b/ex/v1.6.2/blame.html
@@ -0,0 +1,328 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>blame.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>blame.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;blame&quot; example - shows how to use the blame API</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates how to invoke the libgit2 blame API to roughly
+simulate the output of <code>git blame</code> and a few of its command line arguments.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">blame_opts</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">commitspec</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">C</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">M</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">start_line</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">end_line</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">F</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">blame_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">lg2_blame</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="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="kt">int</span> <span class="n">line</span><span class="p">,</span> <span class="n">break_on_null_hunk</span><span class="p">;</span>
+ <span class="n">git_object_size_t</span> <span class="n">i</span><span class="p">,</span> <span class="n">rawsize</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">spec</span><span class="p">[</span><span class="mi">1024</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="k">struct</span> <span class="n">blame_opts</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">rawdata</span><span class="p">;</span>
+ <span class="n">git_revspec</span> <span class="n">revspec</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="n">git_blame_options</span> <span class="n">blameopts</span> <span class="o">=</span> <span class="n">GIT_BLAME_OPTIONS_INIT</span><span class="p">;</span>
+ <span class="n">git_blame</span> <span class="o">*</span><span class="n">blame</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_blob</span> <span class="o">*</span><span class="n">blob</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</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="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">M</span><span class="p">)</span> <span class="n">blameopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES</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">C</span><span class="p">)</span> <span class="n">blameopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES</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">F</span><span class="p">)</span> <span class="n">blameopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_BLAME_FIRST_PARENT</span><span class="p">;</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>The commit range comes in &quot;committish&quot; form. Use the rev-parse API to
+nail down the end points.</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">commitspec</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse-23" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">revspec</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">commitspec</span><span class="p">),</span> <span class="s">&quot;Couldn&#39;t parse commit spec&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_SINGLE</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_cpy-18" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blameopts</span><span class="p">.</span><span class="n">newest_commit</span><span class="p">,</span> <span class="n"><a name="git_object_id-8" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">from</span><span class="p">));</span>
+ <span class="n"><a name="git_object_free-12" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">from</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_cpy-19" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blameopts</span><span class="p">.</span><span class="n">oldest_commit</span><span class="p">,</span> <span class="n"><a name="git_object_id-9" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">from</span><span class="p">));</span>
+ <span class="n"><a name="git_oid_cpy-20" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blameopts</span><span class="p">.</span><span class="n">newest_commit</span><span class="p">,</span> <span class="n"><a name="git_object_id-10" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">to</span><span class="p">));</span>
+ <span class="n"><a name="git_object_free-13" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">from</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-14" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">revspec</span><span class="p">.</span><span class="n">to</span><span class="p">);</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>Run the blame.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_blame_file-2" class="fnlink" href="../../#v1.6.2/group/blame/git_blame_file">git_blame_file</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blame</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">path</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">blameopts</span><span class="p">),</span> <span class="s">&quot;Blame error&quot;</span><span class="p">,</span> <span class="nb">NULL</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>Get the raw data inside the blob for output. We use the
+<code>committish:path/to/file.txt</code> format to find it.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_oid_is_zero-21" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_is_zero">git_oid_is_zero</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blameopts</span><span class="p">.</span><span class="n">newest_commit</span><span class="p">))</span>
+ <span class="n">strcpy</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="s">&quot;HEAD&quot;</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n"><a name="git_oid_tostr-16" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">spec</span><span class="p">),</span> <span class="o">&amp;</span><span class="n">blameopts</span><span class="p">.</span><span class="n">newest_commit</span><span class="p">);</span>
+ <span class="n">strcat</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="s">&quot;:&quot;</span><span class="p">);</span>
+ <span class="n">strcat</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">path</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-22" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">spec</span><span class="p">),</span> <span class="s">&quot;Object lookup error&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_blob_lookup-4" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_lookup">git_blob_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blob</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n"><a name="git_object_id-11" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)),</span> <span class="s">&quot;Blob lookup error&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-15" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</span>
+
+ <span class="n">rawdata</span> <span class="o">=</span> <span class="n"><a name="git_blob_rawcontent-6" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawcontent">git_blob_rawcontent</a></span><span class="p">(</span><span class="n">blob</span><span class="p">);</span>
+ <span class="n">rawsize</span> <span class="o">=</span> <span class="n"><a name="git_blob_rawsize-7" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawsize">git_blob_rawsize</a></span><span class="p">(</span><span class="n">blob</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>Produce the output.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">line</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">break_on_null_hunk</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">rawsize</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">eol</span> <span class="o">=</span> <span class="n">memchr</span><span class="p">(</span><span class="n">rawdata</span> <span class="o">+</span> <span class="n">i</span><span class="p">,</span> <span class="sc">&#39;\n&#39;</span><span class="p">,</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)(</span><span class="n">rawsize</span> <span class="o">-</span> <span class="n">i</span><span class="p">));</span>
+ <span class="kt">char</span> <span class="n">oid</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="k">const</span> <span class="n">git_blame_hunk</span> <span class="o">*</span><span class="n">hunk</span> <span class="o">=</span> <span class="n"><a name="git_blame_get_hunk_byline-1" class="fnlink" href="../../#v1.6.2/group/blame/git_blame_get_hunk_byline">git_blame_get_hunk_byline</a></span><span class="p">(</span><span class="n">blame</span><span class="p">,</span> <span class="n">line</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">break_on_null_hunk</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">hunk</span><span class="p">)</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">hunk</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="n">sig</span><span class="p">[</span><span class="mi">128</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="n">break_on_null_hunk</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="n"><a name="git_oid_tostr-17" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">hunk</span><span class="o">-&gt;</span><span class="n">final_commit_id</span><span class="p">);</span>
+ <span class="n">snprintf</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="s">&quot;%s &lt;%s&gt;&quot;</span><span class="p">,</span> <span class="n">hunk</span><span class="o">-&gt;</span><span class="n">final_signature</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">hunk</span><span class="o">-&gt;</span><span class="n">final_signature</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s ( %-30s %3d) %.*s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">oid</span><span class="p">,</span>
+ <span class="n">sig</span><span class="p">,</span>
+ <span class="n">line</span><span class="p">,</span>
+ <span class="p">(</span><span class="kt">int</span><span class="p">)(</span><span class="n">eol</span> <span class="o">-</span> <span class="n">rawdata</span> <span class="o">-</span> <span class="n">i</span><span class="p">),</span>
+ <span class="n">rawdata</span> <span class="o">+</span> <span class="n">i</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n">i</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)(</span><span class="n">eol</span> <span class="o">-</span> <span class="n">rawdata</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
+ <span class="n">line</span><span class="o">++</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>Cleanup.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_blob_free-5" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_free">git_blob_free</a></span><span class="p">(</span><span class="n">blob</span><span class="p">);</span>
+ <span class="n"><a name="git_blame_free-3" class="fnlink" href="../../#v1.6.2/group/blame/git_blame_free">git_blame_free</a></span><span class="p">(</span><span class="n">blame</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-8'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-8">&#182;</a>
+ </div>
+ <p>Tell the user how to make this thing work.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">msg</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="k">if</span> <span class="p">(</span><span class="n">msg</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">msg</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">msg</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: blame [options] [&lt;commit range&gt;] &lt;path&gt;</span><span class="se">\n</span><span class="s">&quot;</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;</span><span class="se">\n</span><span class="s">&quot;</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; &lt;commit range&gt; example: `HEAD~10..HEAD`, or `1234abcd`</span><span class="se">\n</span><span class="s">&quot;</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; -L &lt;n,m&gt; process only line range n-m, counting from 1</span><span class="se">\n</span><span class="s">&quot;</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; -M find line moves within and across files</span><span class="se">\n</span><span class="s">&quot;</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; -C find line copies within and across files</span><span class="se">\n</span><span class="s">&quot;</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; -F follow only the first parent commits</span><span class="se">\n</span><span class="s">&quot;</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;</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-9'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-9">&#182;</a>
+ </div>
+ <p>Parse the arguments.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">blame_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="kt">int</span> <span class="n">i</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">bare_args</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">)</span> <span class="n">usage</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">argc</span><span class="p">;</span> <span class="n">i</span><span class="o">++</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">i</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="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
+ <span class="k">while</span> <span class="p">(</span><span class="n">bare_args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">3</span><span class="p">)</span> <span class="o">++</span><span class="n">i</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Invalid argument set&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">bare_args</span><span class="p">[</span><span class="n">i</span><span class="p">]</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;--&quot;</span><span class="p">))</span>
+ <span class="k">continue</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">strcasecmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-M&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">M</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">strcasecmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-C&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">C</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">strcasecmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-F&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">F</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">strcasecmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-L&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">i</span><span class="o">++</span><span class="p">;</span> <span class="n">a</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">&gt;=</span> <span class="n">argc</span><span class="p">)</span> <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Not enough arguments to -L&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;%d,%d&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">start_line</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">end_line</span><span class="p">)</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;-L format error&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>
+ <span class="cm">/* commit range */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">commitspec</span><span class="p">)</span> <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Only one commit spec allowed&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">commitspec</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Handle the bare arguments */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">bare_args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Please specify a path&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">path</span> <span class="o">=</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">bare_args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="p">{</span>
+ <span class="cm">/* &lt;commitspec&gt; &lt;path&gt; */</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">path</span> <span class="o">=</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">commitspec</span> <span class="o">=</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">bare_args</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="p">{</span>
+ <span class="cm">/* &lt;oldcommit&gt; &lt;newcommit&gt; &lt;path&gt; */</span>
+ <span class="kt">char</span> <span class="n">spec</span><span class="p">[</span><span class="mi">128</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">path</span> <span class="o">=</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
+ <span class="n">sprintf</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="s">&quot;%s..%s&quot;</span><span class="p">,</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">bare_args</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">commitspec</span> <span class="o">=</span> <span class="n">spec</span><span class="p">;</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/cat-file.html b/ex/v1.6.2/cat-file.html
new file mode 100644
index 000000000..0caaf31d3
--- /dev/null
+++ b/ex/v1.6.2/cat-file.html
@@ -0,0 +1,357 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>cat-file.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>cat-file.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;cat-file&quot; example - shows how to print data from the ODB</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_signature</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">header</span><span class="p">,</span> <span class="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">sig</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">sign</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">offset</span><span class="p">,</span> <span class="n">hours</span><span class="p">,</span> <span class="n">minutes</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">sig</span><span class="p">)</span>
+ <span class="k">return</span><span class="p">;</span>
+
+ <span class="n">offset</span> <span class="o">=</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">when</span><span class="p">.</span><span class="n">offset</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">offset</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">sign</span> <span class="o">=</span> <span class="sc">&#39;-&#39;</span><span class="p">;</span>
+ <span class="n">offset</span> <span class="o">=</span> <span class="o">-</span><span class="n">offset</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">sign</span> <span class="o">=</span> <span class="sc">&#39;+&#39;</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">hours</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">/</span> <span class="mi">60</span><span class="p">;</span>
+ <span class="n">minutes</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">60</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s %s &lt;%s&gt; %ld %c%02d%02d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">header</span><span class="p">,</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">,</span> <span class="p">(</span><span class="kt">long</span><span class="p">)</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">when</span><span class="p">.</span><span class="n">time</span><span class="p">,</span>
+ <span class="n">sign</span><span class="p">,</span> <span class="n">hours</span><span class="p">,</span> <span class="n">minutes</span><span class="p">);</span>
+<span class="p">}</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>Printing out a blob is simple, get the contents and print</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">show_blob</span><span class="p">(</span><span class="k">const</span> <span class="n">git_blob</span> <span class="o">*</span><span class="n">blob</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="cm">/* ? Does this need crlf filtering? */</span>
+ <span class="n">fwrite</span><span class="p">(</span><span class="n"><a name="git_blob_rawcontent-1" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawcontent">git_blob_rawcontent</a></span><span class="p">(</span><span class="n">blob</span><span class="p">),</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)</span><span class="n"><a name="git_blob_rawsize-2" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawsize">git_blob_rawsize</a></span><span class="p">(</span><span class="n">blob</span><span class="p">),</span> <span class="mi">1</span><span class="p">,</span> <span class="n">stdout</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Show each entry with its type, id and attributes</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">show_tree</span><span class="p">(</span><span class="k">const</span> <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">,</span> <span class="n">max_i</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_tree_entrycount-37" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entrycount">git_tree_entrycount</a></span><span class="p">(</span><span class="n">tree</span><span class="p">);</span>
+ <span class="kt">char</span> <span class="n">oidstr</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+ <span class="k">const</span> <span class="n">git_tree_entry</span> <span class="o">*</span><span class="n">te</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">max_i</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">te</span> <span class="o">=</span> <span class="n"><a name="git_tree_entry_byindex-38" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_byindex">git_tree_entry_byindex</a></span><span class="p">(</span><span class="n">tree</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="n"><a name="git_oid_tostr-24" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oidstr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oidstr</span><span class="p">),</span> <span class="n"><a name="git_tree_entry_id-40" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_id">git_tree_entry_id</a></span><span class="p">(</span><span class="n">te</span><span class="p">));</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%06o %s %s</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n"><a name="git_tree_entry_filemode-42" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_filemode">git_tree_entry_filemode</a></span><span class="p">(</span><span class="n">te</span><span class="p">),</span>
+ <span class="n"><a name="git_object_type2string-16" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_tree_entry_type-41" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_type">git_tree_entry_type</a></span><span class="p">(</span><span class="n">te</span><span class="p">)),</span>
+ <span class="n">oidstr</span><span class="p">,</span> <span class="n"><a name="git_tree_entry_name-39" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_name">git_tree_entry_name</a></span><span class="p">(</span><span class="n">te</span><span class="p">));</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>Commits and tags have a few interesting fields in their header.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">show_commit</span><span class="p">(</span><span class="k">const</span> <span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">max_i</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">oidstr</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+
+ <span class="n"><a name="git_oid_tostr-25" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oidstr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oidstr</span><span class="p">),</span> <span class="n"><a name="git_commit_tree_id-7" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree_id">git_commit_tree_id</a></span><span class="p">(</span><span class="n">commit</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;tree %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oidstr</span><span class="p">);</span>
+
+ <span class="n">max_i</span> <span class="o">=</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_commit_parentcount-8" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parentcount">git_commit_parentcount</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">max_i</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_tostr-26" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oidstr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oidstr</span><span class="p">),</span> <span class="n"><a name="git_commit_parent_id-9" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parent_id">git_commit_parent_id</a></span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="n">i</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;parent %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oidstr</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n">print_signature</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">,</span> <span class="n"><a name="git_commit_author-6" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_author">git_commit_author</a></span><span class="p">(</span><span class="n">commit</span><span class="p">));</span>
+ <span class="n">print_signature</span><span class="p">(</span><span class="s">&quot;committer&quot;</span><span class="p">,</span> <span class="n"><a name="git_commit_committer-5" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_committer">git_commit_committer</a></span><span class="p">(</span><span class="n">commit</span><span class="p">));</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_commit_message-3" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">))</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_commit_message-4" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">));</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">show_tag</span><span class="p">(</span><span class="k">const</span> <span class="n">git_tag</span> <span class="o">*</span><span class="n">tag</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">oidstr</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+
+ <span class="n"><a name="git_oid_tostr-27" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oidstr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oidstr</span><span class="p">),</span> <span class="n"><a name="git_tag_target_id-31" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_target_id">git_tag_target_id</a></span><span class="p">(</span><span class="n">tag</span><span class="p">));;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;object %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oidstr</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;type %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-17" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_tag_target_type-32" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_target_type">git_tag_target_type</a></span><span class="p">(</span><span class="n">tag</span><span class="p">)));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;tag %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_tag_name-33" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_name">git_tag_name</a></span><span class="p">(</span><span class="n">tag</span><span class="p">));</span>
+ <span class="n">print_signature</span><span class="p">(</span><span class="s">&quot;tagger&quot;</span><span class="p">,</span> <span class="n"><a name="git_tag_tagger-34" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_tagger">git_tag_tagger</a></span><span class="p">(</span><span class="n">tag</span><span class="p">));</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_tag_message-35" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_message">git_tag_message</a></span><span class="p">(</span><span class="n">tag</span><span class="p">))</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_tag_message-36" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_message">git_tag_message</a></span><span class="p">(</span><span class="n">tag</span><span class="p">));</span>
+<span class="p">}</span>
+
+<span class="k">typedef</span> <span class="k">enum</span> <span class="p">{</span>
+ <span class="n">SHOW_TYPE</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
+ <span class="n">SHOW_SIZE</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span>
+ <span class="n">SHOW_NONE</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span>
+ <span class="n">SHOW_PRETTY</span> <span class="o">=</span> <span class="mi">4</span>
+<span class="p">}</span> <span class="n">catfile_mode</span><span class="p">;</span>
+
+<span class="cm">/* Forward declarations for option-parsing helper */</span>
+<span class="k">struct</span> <span class="n">catfile_options</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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">rev</span><span class="p">;</span>
+ <span class="n">catfile_mode</span> <span class="n">action</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">verbose</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">catfile_options</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></pre></div>
+ </td>
+ </tr>
+ <tr id='section-5'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Entry point for this command</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_cat_file</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="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">catfile_options</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span> <span class="s">&quot;.&quot;</span><span class="p">,</span> <span class="nb">NULL</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_object</span> <span class="o">*</span><span class="n">obj</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">oidstr</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</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="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-30" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">rev</span><span class="p">),</span>
+ <span class="s">&quot;Could not resolve&quot;</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">rev</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">verbose</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="n">oidstr</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+ <span class="n"><a name="git_oid_tostr-28" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">oidstr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oidstr</span><span class="p">),</span> <span class="n"><a name="git_object_id-10" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">obj</span><span class="p">));</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s %s</span><span class="se">\n</span><span class="s">--</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n"><a name="git_object_type2string-18" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_object_type-12" class="fnlink" href="../../#v1.6.2/group/object/git_object_type">git_object_type</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)),</span> <span class="n">oidstr</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">switch</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">action</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">SHOW_TYPE</span><span class="p">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-19" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_object_type-13" class="fnlink" href="../../#v1.6.2/group/object/git_object_type">git_object_type</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)));</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">SHOW_SIZE</span><span class="p">:</span> <span class="p">{</span>
+ <span class="n">git_odb</span> <span class="o">*</span><span class="n">odb</span><span class="p">;</span>
+ <span class="n">git_odb_object</span> <span class="o">*</span><span class="n">odbobj</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_odb-29" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_odb">git_repository_odb</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">odb</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">&quot;Could not open ODB&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_odb_read-21" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_read">git_odb_read</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">odbobj</span><span class="p">,</span> <span class="n">odb</span><span class="p">,</span> <span class="n"><a name="git_object_id-11" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)),</span>
+ <span class="s">&quot;Could not find obj&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%ld</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">long</span><span class="p">)</span><span class="n"><a name="git_odb_object_size-23" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_size">git_odb_object_size</a></span><span class="p">(</span><span class="n">odbobj</span><span class="p">));</span>
+
+ <span class="n"><a name="git_odb_object_free-22" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_free">git_odb_object_free</a></span><span class="p">(</span><span class="n">odbobj</span><span class="p">);</span>
+ <span class="n"><a name="git_odb_free-20" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_free">git_odb_free</a></span><span class="p">(</span><span class="n">odb</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">SHOW_NONE</span><span class="p">:</span>
+ <span class="cm">/* just want return result */</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">SHOW_PRETTY</span><span class="p">:</span>
+
+ <span class="k">switch</span> <span class="p">(</span><span class="n"><a name="git_object_type-14" class="fnlink" href="../../#v1.6.2/group/object/git_object_type">git_object_type</a></span><span class="p">(</span><span class="n">obj</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_BLOB</span><span class="p">:</span>
+ <span class="n">show_blob</span><span class="p">((</span><span class="k">const</span> <span class="n">git_blob</span> <span class="o">*</span><span class="p">)</span><span class="n">obj</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_COMMIT</span><span class="p">:</span>
+ <span class="n">show_commit</span><span class="p">((</span><span class="k">const</span> <span class="n">git_commit</span> <span class="o">*</span><span class="p">)</span><span class="n">obj</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_TREE</span><span class="p">:</span>
+ <span class="n">show_tree</span><span class="p">((</span><span class="k">const</span> <span class="n">git_tree</span> <span class="o">*</span><span class="p">)</span><span class="n">obj</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_TAG</span><span class="p">:</span>
+ <span class="n">show_tag</span><span class="p">((</span><span class="k">const</span> <span class="n">git_tag</span> <span class="o">*</span><span class="p">)</span><span class="n">obj</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;unknown %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oidstr</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_object_free-15" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</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-6'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-6">&#182;</a>
+ </div>
+ <p>Print out usage information</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">message</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="k">if</span> <span class="p">(</span><span class="n">message</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">message</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</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: cat-file (-t | -s | -e | -p) [-v] [-q] &quot;</span>
+ <span class="s">&quot;[-h|--help] [--git-dir=&lt;dir&gt;] &lt;object&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-7'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-7">&#182;</a>
+ </div>
+ <p>Parse the command-line options taken from git</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">catfile_options</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">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="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">rev</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;Only one rev should be provided&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">rev</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;-t&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">action</span> <span class="o">=</span> <span class="n">SHOW_TYPE</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;-s&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">action</span> <span class="o">=</span> <span class="n">SHOW_SIZE</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;-e&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">action</span> <span class="o">=</span> <span class="n">SHOW_NONE</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;-p&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">action</span> <span class="o">=</span> <span class="n">SHOW_PRETTY</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="n">o</span><span class="o">-&gt;</span><span class="n">verbose</span> <span class="o">=</span> <span class="mi">0</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;-v&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">verbose</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;--help&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;-h&quot;</span><span class="p">))</span>
+ <span class="n">usage</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</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">dir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--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">action</span> <span class="o">||</span> <span class="o">!</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">rev</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="nb">NULL</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>
diff --git a/ex/v1.6.2/checkout.html b/ex/v1.6.2/checkout.html
new file mode 100644
index 000000000..70ab7c97a
--- /dev/null
+++ b/ex/v1.6.2/checkout.html
@@ -0,0 +1,457 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>checkout.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>checkout.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;checkout&quot; example - shows how to perform checkouts</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span>
+
+<span class="cm">/* Define the printf format specifier to use for size_t output */</span>
+<span class="cp">#if defined(_MSC_VER) || defined(__MINGW32__)</span>
+<span class="cp"># define PRIuZ &quot;Iu&quot;</span>
+<span class="cp"># define PRIxZ &quot;Ix&quot;</span>
+<span class="cp"># define PRIdZ &quot;Id&quot;</span>
+<span class="cp">#else</span>
+<span class="cp"># define PRIuZ &quot;zu&quot;</span>
+<span class="cp"># define PRIxZ &quot;zx&quot;</span>
+<span class="cp"># define PRIdZ &quot;zd&quot;</span>
+<span class="cp">#endif</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>The following example demonstrates how to do checkouts with libgit2.</p>
+
+<p>Recognized options are :
+ --force: force the checkout to happen.
+ --[no-]progress: show checkout progress, on by default.
+ --perf: show performance data.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="nl">force</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="nl">progress</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="nl">perf</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
+<span class="p">}</span> <span class="n">checkout_options</span><span class="p">;</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_usage</span><span class="p">(</span><span class="kt">void</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;usage: checkout [options] &lt;branch&gt;</span><span class="se">\n</span><span class="s">&quot;</span>
+ <span class="s">&quot;Options are :</span><span class="se">\n</span><span class="s">&quot;</span>
+ <span class="s">&quot; --git-dir: use the following git repository.</span><span class="se">\n</span><span class="s">&quot;</span>
+ <span class="s">&quot; --force: force the checkout.</span><span class="se">\n</span><span class="s">&quot;</span>
+ <span class="s">&quot; --[no-]progress: show checkout progress.</span><span class="se">\n</span><span class="s">&quot;</span>
+ <span class="s">&quot; --perf: show performance data.</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>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_options</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">repo_path</span><span class="p">,</span> <span class="n">checkout_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">struct</span> <span class="n">args_info</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">argc</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+
+ <span class="n">memset</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">opts</span><span class="p">));</span>
+
+ <span class="cm">/* Default values */</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">progress</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">args</span><span class="o">-&gt;</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="o">-&gt;</span><span class="n">pos</span> <span class="o">&lt;</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">argc</span><span class="p">;</span> <span class="o">++</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">pos</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">curr</span> <span class="o">=</span> <span class="n">args</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="n">args</span><span class="o">-&gt;</span><span class="n">pos</span><span class="p">];</span>
+ <span class="kt">int</span> <span class="n">bool_arg</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">match_arg_separator</span><span class="p">(</span><span class="n">args</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">break</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">curr</span><span class="p">,</span> <span class="s">&quot;--force&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span> <span class="o">=</span> <span class="mi">1</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="n">match_bool_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">bool_arg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--progress&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">progress</span> <span class="o">=</span> <span class="n">bool_arg</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="n">match_bool_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">bool_arg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--perf&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">perf</span> <span class="o">=</span> <span class="n">bool_arg</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="n">match_str_arg</span><span class="p">(</span><span class="n">repo_path</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>This function is called to report progression, ie. it&#39;s called once with
+a NULL path and the number of total steps, then for each subsequent path,
+the current completed_step value.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_checkout_progress</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">completed_steps</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">total_steps</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">payload</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">path</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;checkout started: %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot; steps</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">total_steps</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;checkout: %s %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot;/%&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">completed_steps</span><span class="p">,</span> <span class="n">total_steps</span><span class="p">);</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>This function is called when the checkout completes, and is used to report the
+number of syscalls performed.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_perf_data</span><span class="p">(</span><span class="k">const</span> <span class="n">git_checkout_perfdata</span> <span class="o">*</span><span class="n">perfdata</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">payload</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;perf: stat: %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot; mkdir: %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot; chmod: %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">perfdata</span><span class="o">-&gt;</span><span class="n">stat_calls</span><span class="p">,</span> <span class="n">perfdata</span><span class="o">-&gt;</span><span class="n">mkdir_calls</span><span class="p">,</span> <span class="n">perfdata</span><span class="o">-&gt;</span><span class="n">chmod_calls</span><span class="p">);</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>This is the main &quot;checkout <branch>&quot; function, responsible for performing
+a branch-based checkout.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">perform_checkout_ref</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="n">git_annotated_commit</span> <span class="o">*</span><span class="n">target</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">target_ref</span><span class="p">,</span> <span class="n">checkout_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_checkout_options</span> <span class="n">checkout_opts</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_OPTIONS_INIT</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">ref</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">*</span><span class="n">branch</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">target_commit</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</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>Setup our checkout options from the parsed options</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">checkout_opts</span><span class="p">.</span><span class="n">checkout_strategy</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_SAFE</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span><span class="p">)</span>
+ <span class="n">checkout_opts</span><span class="p">.</span><span class="n">checkout_strategy</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_FORCE</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">progress</span><span class="p">)</span>
+ <span class="n">checkout_opts</span><span class="p">.</span><span class="n">progress_cb</span> <span class="o">=</span> <span class="n">print_checkout_progress</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">perf</span><span class="p">)</span>
+ <span class="n">checkout_opts</span><span class="p">.</span><span class="n">perfdata_cb</span> <span class="o">=</span> <span class="n">print_perf_data</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>Grab the commit we&#39;re interested to move to</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_commit_lookup-9" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target_commit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n"><a name="git_annotated_commit_id-2" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_id">git_annotated_commit_id</a></span><span class="p">(</span><span class="n">target</span><span class="p">));</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to lookup commit: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-11" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</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>Perform the checkout so the workdir corresponds to what target_commit
+contains.</p>
+
+<p>Note that it&#39;s okay to pass a git_commit here, because it will be
+peeled to a tree.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_checkout_tree-8" class="fnlink" href="../../#v1.6.2/group/checkout/git_checkout_tree">git_checkout_tree</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="p">(</span><span class="k">const</span> <span class="n">git_object</span> <span class="o">*</span><span class="p">)</span><span class="n">target_commit</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">checkout_opts</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to checkout tree: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-12" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</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>Now that the checkout has completed, we have to update HEAD.</p>
+
+<p>Depending on the &quot;origin&quot; of target (ie. it&#39;s an OID or a branch name),
+we might need to detach HEAD.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_annotated_commit_ref-3" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_ref">git_annotated_commit_ref</a></span><span class="p">(</span><span class="n">target</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">target_head</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_lookup-15" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_lookup">git_reference_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n"><a name="git_annotated_commit_ref-4" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_ref">git_annotated_commit_ref</a></span><span class="p">(</span><span class="n">target</span><span class="p">)))</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_reference_is_remote-21" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_is_remote">git_reference_is_remote</a></span><span class="p">(</span><span class="n">ref</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">((</span><span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_branch_create_from_annotated-7" class="fnlink" href="../../#v1.6.2/group/branch/git_branch_create_from_annotated">git_branch_create_from_annotated</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">branch</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">target_ref</span><span class="p">,</span> <span class="n">target</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="k">goto</span> <span class="n">error</span><span class="p">;</span>
+ <span class="n">target_head</span> <span class="o">=</span> <span class="n"><a name="git_reference_name-17" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_name">git_reference_name</a></span><span class="p">(</span><span class="n">branch</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">target_head</span> <span class="o">=</span> <span class="n"><a name="git_annotated_commit_ref-5" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_ref">git_annotated_commit_ref</a></span><span class="p">(</span><span class="n">target</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_repository_set_head-23" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_set_head">git_repository_set_head</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">target_head</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_repository_set_head_detached_from_annotated-24" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_set_head_detached_from_annotated">git_repository_set_head_detached_from_annotated</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">target</span><span class="p">);</span>
+ <span class="p">}</span>
+
+<span class="nl">error</span><span class="p">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to update HEAD reference: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-13" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+ <span class="p">}</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n"><a name="git_commit_free-10" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">target_commit</span><span class="p">);</span>
+ <span class="n"><a name="git_reference_free-18" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">branch</span><span class="p">);</span>
+ <span class="n"><a name="git_reference_free-19" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">ref</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">err</span><span class="p">;</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>This corresponds to <code>git switch --guess</code>: if a given ref does
+not exist, git will by default try to guess the reference by
+seeing whether any remote has a branch called <ref>. If there
+is a single remote only that has it, then it is assumed to be
+the desired reference and a local branch is created for it.</p>
+
+<p>The following is a simplified implementation. It will not try
+to check whether the ref is unique across all remotes.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">guess_refish</span><span class="p">(</span><span class="n">git_annotated_commit</span> <span class="o">**</span><span class="n">out</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">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">ref</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_strarray</span> <span class="n">remotes</span> <span class="o">=</span> <span class="p">{</span> <span class="nb">NULL</span><span class="p">,</span> <span class="mi">0</span> <span class="p">};</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">remote_ref</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_list-22" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_list">git_remote_list</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remotes</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="k">goto</span> <span class="n">out</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">remotes</span><span class="p">.</span><span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">refname</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">reflen</span><span class="p">;</span>
+
+ <span class="n">reflen</span> <span class="o">=</span> <span class="n">snprintf</span><span class="p">(</span><span class="n">refname</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s">&quot;refs/remotes/%s/%s&quot;</span><span class="p">,</span> <span class="n">remotes</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">ref</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">((</span><span class="n">refname</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="n">reflen</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="k">goto</span> <span class="n">next</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="n">snprintf</span><span class="p">(</span><span class="n">refname</span><span class="p">,</span> <span class="n">reflen</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&quot;refs/remotes/%s/%s&quot;</span><span class="p">,</span> <span class="n">remotes</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">ref</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_reference_lookup-16" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_lookup">git_reference_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote_ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">refname</span><span class="p">))</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">next</span><span class="p">;</span>
+
+ <span class="k">break</span><span class="p">;</span>
+<span class="nl">next</span><span class="p">:</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">refname</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">error</span> <span class="o">!=</span> <span class="n">GIT_ENOTFOUND</span><span class="p">)</span>
+ <span class="k">break</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">remote_ref</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n">GIT_ENOTFOUND</span><span class="p">;</span>
+ <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_annotated_commit_from_ref-1" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_from_ref">git_annotated_commit_from_ref</a></span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">remote_ref</span><span class="p">))</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
+
+<span class="nl">out</span><span class="p">:</span>
+ <span class="n"><a name="git_reference_free-20" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">remote_ref</span><span class="p">);</span>
+ <span class="n"><a name="git_strarray_dispose-26" class="fnlink" href="../../#v1.6.2/group/strarray/git_strarray_dispose">git_strarray_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remotes</span><span class="p">);</span>
+ <span class="k">return</span> <span class="n">error</span><span class="p">;</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>That example&#39;s entry point</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_checkout</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="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="n">checkout_options</span> <span class="n">opts</span><span class="p">;</span>
+ <span class="n">git_repository_state_t</span> <span class="n">state</span><span class="p">;</span>
+ <span class="n">git_annotated_commit</span> <span class="o">*</span><span class="n">checkout_target</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span> <span class="o">=</span> <span class="s">&quot;.&quot;</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>Parse our command line options</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">path</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</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>Make sure we&#39;re not about to checkout while something else is going on</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">state</span> <span class="o">=</span> <span class="n"><a name="git_repository_state-25" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_state">git_repository_state</a></span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">!=</span> <span class="n">GIT_REPOSITORY_STATE_NONE</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;repository is in unexpected state %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">match_arg_separator</span><span class="p">(</span><span class="o">&amp;</span><span class="n">args</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>Try to checkout the given path</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;unhandled path-based checkout</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="k">goto</span> <span class="n">cleanup</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-15'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-15">&#182;</a>
+ </div>
+ <p>Try to resolve a &quot;refish&quot; argument to a target libgit2 can use</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">((</span><span class="n">err</span> <span class="o">=</span> <span class="n">resolve_refish</span><span class="p">(</span><span class="o">&amp;</span><span class="n">checkout_target</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">args</span><span class="p">.</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="o">&lt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span>
+ <span class="p">(</span><span class="n">err</span> <span class="o">=</span> <span class="n">guess_refish</span><span class="p">(</span><span class="o">&amp;</span><span class="n">checkout_target</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">args</span><span class="p">.</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="o">&lt;</span> <span class="mi">0</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;failed to resolve %s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">.</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="n"><a name="git_error_last-14" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n">perform_checkout_ref</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">checkout_target</span><span class="p">,</span> <span class="n">args</span><span class="p">.</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="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="p">}</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n"><a name="git_annotated_commit_free-6" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_free">git_annotated_commit_free</a></span><span class="p">(</span><span class="n">checkout_target</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">err</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/clone.html b/ex/v1.6.2/clone.html
new file mode 100644
index 000000000..29707b080
--- /dev/null
+++ b/ex/v1.6.2/clone.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>clone.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>clone.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/commit.html b/ex/v1.6.2/commit.html
new file mode 100644
index 000000000..40b48220c
--- /dev/null
+++ b/ex/v1.6.2/commit.html
@@ -0,0 +1,168 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>commit.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>commit.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;commit&quot; example - shows how to create a git commit</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the libgit2 commit APIs to roughly
+simulate <code>git commit</code> with the commit message argument.</p>
+
+<p>This does not have:</p>
+
+<ul>
+<li>Robust error handling</li>
+<li>Most of the <code>git commit</code> options</li>
+</ul>
+
+<p>This does have:</p>
+
+<ul>
+<li>Example of performing a git commit with a comment</li>
+</ul>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_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="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">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">opt</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">comment</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="n">git_oid</span> <span class="n">commit_oid</span><span class="p">,</span><span class="n">tree_oid</span><span class="p">;</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</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_object</span> <span class="o">*</span><span class="n">parent</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">ref</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_signature</span> <span class="o">*</span><span class="n">signature</span><span class="p">;</span>
+
+ <span class="cm">/* Validate args */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;</span> <span class="mi">3</span> <span class="o">||</span> <span class="n">strcmp</span><span class="p">(</span><span class="n">opt</span><span class="p">,</span> <span class="s">&quot;-m&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;USAGE: %s -m &lt;comment&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_revparse_ext-9" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_ext">git_revparse_ext</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ref</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="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">==</span> <span class="n">GIT_ENOTFOUND</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;HEAD not found. Creating first commit</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="mi">0</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="n">error</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="n">git_error</span> <span class="o">*</span><span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_error_last-2" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">();</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;ERROR %d: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">err</span><span class="o">-&gt;</span><span class="n">klass</span><span class="p">,</span> <span class="n">err</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;ERROR %d: no detailed info</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="p">}</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_index-8" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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="s">&quot;Could not open repository index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_index_write_tree-5" class="fnlink" href="../../#v1.6.2/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_oid</span><span class="p">,</span> <span class="n">index</span><span class="p">),</span> <span class="s">&quot;Could not write tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_index_write-4" class="fnlink" href="../../#v1.6.2/group/index/git_index_write">git_index_write</a></span><span class="p">(</span><span class="n">index</span><span class="p">),</span> <span class="s">&quot;Could not write index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tree_lookup-12" class="fnlink" href="../../#v1.6.2/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_oid</span><span class="p">),</span> <span class="s">&quot;Error looking up tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_signature_default-10" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_default">git_signature_default</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">signature</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">&quot;Error creating signature&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_create_v-1" class="fnlink" href="../../#v1.6.2/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_oid</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">signature</span><span class="p">,</span>
+ <span class="n">signature</span><span class="p">,</span>
+ <span class="nb">NULL</span><span class="p">,</span>
+ <span class="n">comment</span><span class="p">,</span>
+ <span class="n">tree</span><span class="p">,</span>
+ <span class="n">parent</span> <span class="o">?</span> <span class="mi">1</span> <span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">parent</span><span class="p">),</span> <span class="s">&quot;Error creating commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n"><a name="git_index_free-3" class="fnlink" href="../../#v1.6.2/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="n"><a name="git_signature_free-11" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_free">git_signature_free</a></span><span class="p">(</span><span class="n">signature</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-13" class="fnlink" href="../../#v1.6.2/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_object_free-6" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">parent</span><span class="p">);</span>
+ <span class="n"><a name="git_reference_free-7" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">ref</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/common.html b/ex/v1.6.2/common.html
new file mode 100644
index 000000000..1c3601dd5
--- /dev/null
+++ b/ex/v1.6.2/common.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>common.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>common.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/config.html b/ex/v1.6.2/config.html
new file mode 100644
index 000000000..852e1cad2
--- /dev/null
+++ b/ex/v1.6.2/config.html
@@ -0,0 +1,150 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>config.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>config.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;config&quot; example - shows how to use the config API</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">config_get</span><span class="p">(</span><span class="n">git_config</span> <span class="o">*</span><span class="n">cfg</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">key</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_config_entry</span> <span class="o">*</span><span class="n">entry</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_config_get_entry-4" class="fnlink" href="../../#v1.6.2/group/config/git_config_get_entry">git_config_get_entry</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">entry</span><span class="p">,</span> <span class="n">cfg</span><span class="p">,</span> <span class="n">key</span><span class="p">))</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">!=</span> <span class="n">GIT_ENOTFOUND</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Unable to get configuration: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-6" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">puts</span><span class="p">(</span><span class="n">entry</span><span class="o">-&gt;</span><span class="n">value</span><span class="p">);</span>
+
+ <span class="cm">/* Free the git_config_entry after use with `<a name="git_config_entry_free-1" class="fnlink" href="../../#v1.6.2/group/config/git_config_entry_free">git_config_entry_free</a>()`. */</span>
+ <span class="n"><a name="git_config_entry_free-2" class="fnlink" href="../../#v1.6.2/group/config/git_config_entry_free">git_config_entry_free</a></span><span class="p">(</span><span class="n">entry</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">int</span> <span class="nf">config_set</span><span class="p">(</span><span class="n">git_config</span> <span class="o">*</span><span class="n">cfg</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">key</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">value</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_config_set_string-5" class="fnlink" href="../../#v1.6.2/group/config/git_config_set_string">git_config_set_string</a></span><span class="p">(</span><span class="n">cfg</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Unable to set configuration: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-7" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</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="kt">int</span> <span class="nf">lg2_config</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="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_config</span> <span class="o">*</span><span class="n">cfg</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_config-9" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_config">git_repository_config</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">cfg</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="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Unable to obtain repository config: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-8" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">out</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n">config_get</span><span class="p">(</span><span class="n">cfg</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</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="n">argc</span> <span class="o">==</span> <span class="mi">3</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n">config_set</span><span class="p">(</span><span class="n">cfg</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">]);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;USAGE: %s config &lt;KEY&gt; [&lt;VALUE&gt;]</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</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>The configuration file must be freed once it&#39;s no longer
+being used by the user.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_config_free-3" class="fnlink" href="../../#v1.6.2/group/config/git_config_free">git_config_free</a></span><span class="p">(</span><span class="n">cfg</span><span class="p">);</span>
+<span class="nl">out</span><span class="p">:</span>
+ <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/describe.html b/ex/v1.6.2/describe.html
new file mode 100644
index 000000000..4b304861a
--- /dev/null
+++ b/ex/v1.6.2/describe.html
@@ -0,0 +1,268 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>describe.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>describe.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;describe&quot; example - shows how to describe commits</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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>The following example partially reimplements the <code>git describe</code> command
+and some of its options.</p>
+
+<p>These commands should work:</p>
+
+<ul>
+<li>Describe HEAD with default options (<code>describe</code>)</li>
+<li>Describe specified revision (<code>describe master~2</code>)</li>
+<li>Describe specified revisions (<code>describe master~2 HEAD~3</code>)</li>
+<li>Describe HEAD with dirty state suffix (<code>describe --dirty=*</code>)</li>
+<li>Describe consider all refs (<code>describe --all master</code>)</li>
+<li>Describe consider lightweight tags (<code>describe --tags temp-tag</code>)</li>
+<li>Describe show non-default abbreviated size (<code>describe --abbrev=10</code>)</li>
+<li>Describe always output the long format if matches a tag (<code>describe --long v1.0</code>)</li>
+<li>Describe consider only tags of specified pattern (<code>describe --match v*-release</code>)</li>
+<li>Describe show the fallback result (<code>describe --always</code>)</li>
+<li>Describe follow only the first parent commit (<code>describe --first-parent</code>)</li>
+</ul>
+
+<p>The command line parsing logic is simplified and doesn&#39;t handle
+all of the use cases.</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>describe_options represents the parsed command line options</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">describe_options</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">commits</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">commit_count</span><span class="p">;</span>
+ <span class="n">git_describe_options</span> <span class="n">describe_options</span><span class="p">;</span>
+ <span class="n">git_describe_format_options</span> <span class="n">format_options</span><span class="p">;</span>
+<span class="p">};</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">opts_add_commit</span><span class="p">(</span><span class="k">struct</span> <span class="n">describe_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">commit</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">sz</span><span class="p">;</span>
+
+ <span class="n">assert</span><span class="p">(</span><span class="n">opts</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">sz</span> <span class="o">=</span> <span class="o">++</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span> <span class="o">=</span> <span class="n">xrealloc</span><span class="p">((</span><span class="kt">void</span> <span class="o">*</span><span class="p">)</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span><span class="p">,</span> <span class="n">sz</span><span class="p">);</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span><span class="p">[</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">commit</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">do_describe_single</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">struct</span> <span class="n">describe_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">rev</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">commit</span><span class="p">;</span>
+ <span class="n">git_describe_result</span> <span class="o">*</span><span class="n">describe_result</span><span class="p">;</span>
+ <span class="n">git_buf</span> <span class="n">buf</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">0</span> <span class="p">};</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">rev</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-6" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">commit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">rev</span><span class="p">),</span>
+ <span class="s">&quot;Failed to lookup rev&quot;</span><span class="p">,</span> <span class="n">rev</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_describe_commit-3" class="fnlink" href="../../#v1.6.2/group/describe/git_describe_commit">git_describe_commit</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">describe_result</span><span class="p">,</span> <span class="n">commit</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">),</span>
+ <span class="s">&quot;Failed to describe rev&quot;</span><span class="p">,</span> <span class="n">rev</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_describe_workdir-4" class="fnlink" href="../../#v1.6.2/group/describe/git_describe_workdir">git_describe_workdir</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">describe_result</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">),</span>
+ <span class="s">&quot;Failed to describe workdir&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_describe_format-5" class="fnlink" href="../../#v1.6.2/group/describe/git_describe_format">git_describe_format</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">buf</span><span class="p">,</span> <span class="n">describe_result</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">),</span>
+ <span class="s">&quot;Failed to format describe rev&quot;</span><span class="p">,</span> <span class="n">rev</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">buf</span><span class="p">.</span><span class="n">ptr</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">do_describe</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">struct</span> <span class="n">describe_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">do_describe_single</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="n">do_describe_single</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_usage</span><span class="p">(</span><span class="kt">void</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;usage: see `git help describe`</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-4'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>Parse command line arguments</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_options</span><span class="p">(</span><span class="k">struct</span> <span class="n">describe_options</span> <span class="o">*</span><span class="n">opts</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">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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">curr</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">curr</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="n">opts_add_commit</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">curr</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">curr</span><span class="p">,</span> <span class="s">&quot;--all&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">describe_strategy</span> <span class="o">=</span> <span class="n">GIT_DESCRIBE_ALL</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">curr</span><span class="p">,</span> <span class="s">&quot;--tags&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">describe_strategy</span> <span class="o">=</span> <span class="n">GIT_DESCRIBE_TAGS</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">curr</span><span class="p">,</span> <span class="s">&quot;--exact-match&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">max_candidates_tags</span> <span class="o">=</span> <span class="mi">0</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">curr</span><span class="p">,</span> <span class="s">&quot;--long&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">always_use_long_format</span> <span class="o">=</span> <span class="mi">1</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">curr</span><span class="p">,</span> <span class="s">&quot;--always&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">show_commit_oid_as_fallback</span> <span class="o">=</span> <span class="mi">1</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">curr</span><span class="p">,</span> <span class="s">&quot;--first-parent&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">only_follow_first_parent</span> <span class="o">=</span> <span class="mi">1</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="n">optional_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">dirty_suffix</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--dirty&quot;</span><span class="p">,</span> <span class="s">&quot;-dirty&quot;</span><span class="p">))</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="n">match_int_arg</span><span class="p">((</span><span class="kt">int</span> <span class="o">*</span><span class="p">)</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">abbreviated_size</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--abbrev&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</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="n">match_int_arg</span><span class="p">((</span><span class="kt">int</span> <span class="o">*</span><span class="p">)</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">max_candidates_tags</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--candidates&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</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="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">.</span><span class="n">pattern</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--match&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">dirty_suffix</span><span class="p">)</span>
+ <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;--dirty is incompatible with commit-ishes&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>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">dirty_suffix</span> <span class="o">||</span> <span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">.</span><span class="n">dirty_suffix</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="p">{</span>
+ <span class="n">opts_add_commit</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s">&quot;HEAD&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</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>Initialize describe_options struct</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">describe_options_init</span><span class="p">(</span><span class="k">struct</span> <span class="n">describe_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">memset</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">opts</span><span class="p">));</span>
+
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commits</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">commit_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n"><a name="git_describe_options_init-1" class="fnlink" href="../../#v1.6.2/group/describe/git_describe_options_init">git_describe_options_init</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">describe_options</span><span class="p">,</span> <span class="n">GIT_DESCRIBE_OPTIONS_VERSION</span><span class="p">);</span>
+ <span class="n"><a name="git_describe_format_options_init-2" class="fnlink" href="../../#v1.6.2/group/describe/git_describe_format_options_init">git_describe_format_options_init</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">format_options</span><span class="p">,</span> <span class="n">GIT_DESCRIBE_FORMAT_OPTIONS_VERSION</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kt">int</span> <span class="nf">lg2_describe</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="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">describe_options</span> <span class="n">opts</span><span class="p">;</span>
+
+ <span class="n">describe_options_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</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="n">do_describe</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</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>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/diff.html b/ex/v1.6.2/diff.html
new file mode 100644
index 000000000..07bd49f97
--- /dev/null
+++ b/ex/v1.6.2/diff.html
@@ -0,0 +1,516 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>diff.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>diff.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;diff&quot; example - shows how to use the diff API</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the use of the libgit2 diff APIs to
+create <code>git_diff</code> objects and display them, emulating a number of
+core Git <code>diff</code> command line options.</p>
+
+<p>This covers on a portion of the core Git diff options and doesn&#39;t
+have particularly good error handling, but it should show most of
+the core libgit2 diff APIs, including various types of diffs and
+how to do renaming detection and patch formatting.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">colors</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="s">&quot;</span><span class="se">\033</span><span class="s">[m&quot;</span><span class="p">,</span> <span class="cm">/* reset */</span>
+ <span class="s">&quot;</span><span class="se">\033</span><span class="s">[1m&quot;</span><span class="p">,</span> <span class="cm">/* bold */</span>
+ <span class="s">&quot;</span><span class="se">\033</span><span class="s">[31m&quot;</span><span class="p">,</span> <span class="cm">/* red */</span>
+ <span class="s">&quot;</span><span class="se">\033</span><span class="s">[32m&quot;</span><span class="p">,</span> <span class="cm">/* green */</span>
+ <span class="s">&quot;</span><span class="se">\033</span><span class="s">[36m&quot;</span> <span class="cm">/* cyan */</span>
+<span class="p">};</span>
+
+<span class="k">enum</span> <span class="p">{</span>
+ <span class="n">OUTPUT_DIFF</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">0</span><span class="p">),</span>
+ <span class="n">OUTPUT_STAT</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">1</span><span class="p">),</span>
+ <span class="n">OUTPUT_SHORTSTAT</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">2</span><span class="p">),</span>
+ <span class="n">OUTPUT_NUMSTAT</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">3</span><span class="p">),</span>
+ <span class="n">OUTPUT_SUMMARY</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">4</span><span class="p">)</span>
+<span class="p">};</span>
+
+<span class="k">enum</span> <span class="p">{</span>
+ <span class="n">CACHE_NORMAL</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+ <span class="n">CACHE_ONLY</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
+ <span class="n">CACHE_NONE</span> <span class="o">=</span> <span class="mi">2</span>
+<span class="p">};</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>The &#39;diff_options&#39; struct captures all the various parsed command line options.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">diff_options</span> <span class="p">{</span>
+ <span class="n">git_diff_options</span> <span class="n">diffopts</span><span class="p">;</span>
+ <span class="n">git_diff_find_options</span> <span class="n">findopts</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">color</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">no_index</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">cache</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">output</span><span class="p">;</span>
+ <span class="n">git_diff_format_t</span> <span class="n">format</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">treeish1</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">treeish2</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></pre></div>
+ </td>
+ </tr>
+ <tr id='section-4'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>These functions are implemented at the end</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">message</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="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">diff_options</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="k">static</span> <span class="kt">int</span> <span class="nf">color_printer</span><span class="p">(</span>
+ <span class="k">const</span> <span class="n">git_diff_delta</span><span class="o">*</span><span class="p">,</span> <span class="k">const</span> <span class="n">git_diff_hunk</span><span class="o">*</span><span class="p">,</span> <span class="k">const</span> <span class="n">git_diff_line</span><span class="o">*</span><span class="p">,</span> <span class="kt">void</span><span class="o">*</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">diff_print_stats</span><span class="p">(</span><span class="n">git_diff</span> <span class="o">*</span><span class="n">diff</span><span class="p">,</span> <span class="k">struct</span> <span class="n">diff_options</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">compute_diff_no_index</span><span class="p">(</span><span class="n">git_diff</span> <span class="o">**</span><span class="n">diff</span><span class="p">,</span> <span class="k">struct</span> <span class="n">diff_options</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+
+<span class="kt">int</span> <span class="nf">lg2_diff</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="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_tree</span> <span class="o">*</span><span class="n">t1</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">*</span><span class="n">t2</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_diff</span> <span class="o">*</span><span class="n">diff</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">diff_options</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="n">GIT_DIFF_OPTIONS_INIT</span><span class="p">,</span> <span class="n">GIT_DIFF_FIND_OPTIONS_INIT</span><span class="p">,</span>
+ <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</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="n">GIT_DIFF_FORMAT_PATCH</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="s">&quot;.&quot;</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></pre></div>
+ </td>
+ </tr>
+ <tr id='section-5'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-5">&#182;</a>
+ </div>
+ <p>Possible argument patterns:</p>
+
+<ul>
+<li>&lt;sha1&gt; &lt;sha2&gt;</li>
+<li>&lt;sha1&gt; --cached</li>
+<li>&lt;sha1&gt;</li>
+<li>--cached</li>
+<li>--nocache (don&#39;t use index data in diff at all)</li>
+<li>--no-index &lt;file1&gt; &lt;file2&gt;</li>
+<li>nothing</li>
+</ul>
+
+<p>Currently ranged arguments like &lt;sha1&gt;..&lt;sha2&gt; and &lt;sha1&gt;...&lt;sha2&gt;
+are not supported in this example</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">no_index</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">compute_diff_no_index</span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</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">treeish1</span><span class="p">)</span>
+ <span class="n">treeish_to_tree</span><span class="p">(</span><span class="o">&amp;</span><span class="n">t1</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">treeish1</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">treeish2</span><span class="p">)</span>
+ <span class="n">treeish_to_tree</span><span class="p">(</span><span class="o">&amp;</span><span class="n">t2</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">treeish2</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">t1</span> <span class="o">&amp;&amp;</span> <span class="n">t2</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_tree_to_tree-4" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">t1</span><span class="p">,</span> <span class="n">t2</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;diff trees&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">cache</span> <span class="o">!=</span> <span class="n">CACHE_NORMAL</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">t1</span><span class="p">)</span>
+ <span class="n">treeish_to_tree</span><span class="p">(</span><span class="o">&amp;</span><span class="n">t1</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="k">if</span> <span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">cache</span> <span class="o">==</span> <span class="n">CACHE_NONE</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_tree_to_workdir-7" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_workdir">git_diff_tree_to_workdir</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">t1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;diff tree to working directory&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_tree_to_index-5" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_index">git_diff_tree_to_index</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">t1</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;diff tree to index&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="k">if</span> <span class="p">(</span><span class="n">t1</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_tree_to_workdir_with_index-8" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_workdir_with_index">git_diff_tree_to_workdir_with_index</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">t1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;diff tree to working directory&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_index_to_workdir-6" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_index_to_workdir">git_diff_index_to_workdir</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;diff index to working directory&quot;</span><span class="p">,</span> <span class="nb">NULL</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>Apply rename and copy detection if requested.</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">findopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_DIFF_FIND_ALL</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_find_similar-9" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_find_similar">git_diff_find_similar</a></span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">findopts</span><span class="p">),</span>
+ <span class="s">&quot;finding renames and copies&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>Generate simple output using libgit2 display helper.</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">output</span><span class="p">)</span>
+ <span class="n">o</span><span class="p">.</span><span class="n">output</span> <span class="o">=</span> <span class="n">OUTPUT_DIFF</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">output</span> <span class="o">!=</span> <span class="n">OUTPUT_DIFF</span><span class="p">)</span>
+ <span class="n">diff_print_stats</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</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">output</span> <span class="o">&amp;</span> <span class="n">OUTPUT_DIFF</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</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">color</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="n">colors</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">stdout</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_print-10" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_print">git_diff_print</a></span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">format</span><span class="p">,</span> <span class="n">color_printer</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">color</span><span class="p">),</span>
+ <span class="s">&quot;displaying diff&quot;</span><span class="p">,</span> <span class="nb">NULL</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">color</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="n">colors</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">stdout</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>Cleanup before exiting.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_diff_free-3" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_free">git_diff_free</a></span><span class="p">(</span><span class="n">diff</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-18" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">t1</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-19" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">t2</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">compute_diff_no_index</span><span class="p">(</span><span class="n">git_diff</span> <span class="o">**</span><span class="n">diff</span><span class="p">,</span> <span class="k">struct</span> <span class="n">diff_options</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_patch</span> <span class="o">*</span><span class="n">patch</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">file1_str</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">file2_str</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_buf</span> <span class="n">buf</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</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">treeish1</span> <span class="o">||</span> <span class="o">!</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;two files should be provided as arguments&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">file1_str</span> <span class="o">=</span> <span class="n">read_file</span><span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish1</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">file1_str</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;file cannot be read&quot;</span><span class="p">,</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish1</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">file2_str</span> <span class="o">=</span> <span class="n">read_file</span><span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">file2_str</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;file cannot be read&quot;</span><span class="p">,</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_patch_from_buffers-15" class="fnlink" href="../../#v1.6.2/group/patch/git_patch_from_buffers">git_patch_from_buffers</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">patch</span><span class="p">,</span> <span class="n">file1_str</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">file1_str</span><span class="p">),</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish1</span><span class="p">,</span> <span class="n">file2_str</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">file2_str</span><span class="p">),</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;patch buffers&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_patch_to_buf-17" class="fnlink" href="../../#v1.6.2/group/patch/git_patch_to_buf">git_patch_to_buf</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">buf</span><span class="p">,</span> <span class="n">patch</span><span class="p">),</span>
+ <span class="s">&quot;patch to buf&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_from_buffer-11" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_from_buffer">git_diff_from_buffer</a></span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">buf</span><span class="p">.</span><span class="n">ptr</span><span class="p">,</span> <span class="n">buf</span><span class="p">.</span><span class="n">size</span><span class="p">),</span>
+ <span class="s">&quot;diff from patch&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n"><a name="git_patch_free-16" class="fnlink" href="../../#v1.6.2/group/patch/git_patch_free">git_patch_free</a></span><span class="p">(</span><span class="n">patch</span><span class="p">);</span>
+ <span class="n"><a name="git_buf_dispose-1" class="fnlink" href="../../#v1.6.2/group/buf/git_buf_dispose">git_buf_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">buf</span><span class="p">);</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">file1_str</span><span class="p">);</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">file2_str</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">message</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="k">if</span> <span class="p">(</span><span class="n">message</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">message</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</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: diff [&lt;tree-oid&gt; [&lt;tree-oid&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-9'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-9">&#182;</a>
+ </div>
+ <p>This implements very rudimentary colorized output.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">color_printer</span><span class="p">(</span>
+ <span class="k">const</span> <span class="n">git_diff_delta</span> <span class="o">*</span><span class="n">delta</span><span class="p">,</span>
+ <span class="k">const</span> <span class="n">git_diff_hunk</span> <span class="o">*</span><span class="n">hunk</span><span class="p">,</span>
+ <span class="k">const</span> <span class="n">git_diff_line</span> <span class="o">*</span><span class="n">line</span><span class="p">,</span>
+ <span class="kt">void</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="o">*</span><span class="n">last_color</span> <span class="o">=</span> <span class="n">data</span><span class="p">,</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">delta</span><span class="p">;</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">hunk</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">last_color</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="n">line</span><span class="o">-&gt;</span><span class="n">origin</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_ADDITION</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_DELETION</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_ADD_EOFNL</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_DEL_EOFNL</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_FILE_HDR</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_DIFF_LINE_HUNK_HDR</span><span class="p">:</span> <span class="n">color</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span> <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">color</span> <span class="o">!=</span> <span class="o">*</span><span class="n">last_color</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">last_color</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">||</span> <span class="n">color</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="n">colors</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">stdout</span><span class="p">);</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="n">colors</span><span class="p">[</span><span class="n">color</span><span class="p">],</span> <span class="n">stdout</span><span class="p">);</span>
+ <span class="o">*</span><span class="n">last_color</span> <span class="o">=</span> <span class="n">color</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="n">diff_output</span><span class="p">(</span><span class="n">delta</span><span class="p">,</span> <span class="n">hunk</span><span class="p">,</span> <span class="n">line</span><span class="p">,</span> <span class="n">stdout</span><span class="p">);</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>Parse arguments as copied from git-diff.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">diff_options</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">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="k">const</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="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish1</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish1</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">treeish2</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Only one or two tree identifiers can be provided&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="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;-p&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;-u&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;--patch&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">output</span> <span class="o">|=</span> <span class="n">OUTPUT_DIFF</span><span class="p">;</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">GIT_DIFF_FORMAT_PATCH</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;--cached&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">cache</span> <span class="o">=</span> <span class="n">CACHE_ONLY</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">no_index</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">usage</span><span class="p">(</span><span class="s">&quot;--cached and --no-index are incompatible&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="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;--nocache&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">cache</span> <span class="o">=</span> <span class="n">CACHE_NONE</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;--name-only&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;--format=name&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">GIT_DIFF_FORMAT_NAME_ONLY</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;--name-status&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;--format=name-status&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">GIT_DIFF_FORMAT_NAME_STATUS</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;--raw&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;--format=raw&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">GIT_DIFF_FORMAT_RAW</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;--format=diff-index&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">GIT_DIFF_FORMAT_RAW</span><span class="p">;</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">id_abbrev</span> <span class="o">=</span> <span class="mi">40</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;--no-index&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">no_index</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">o</span><span class="o">-&gt;</span><span class="n">cache</span> <span class="o">==</span> <span class="n">CACHE_ONLY</span><span class="p">)</span> <span class="n">usage</span><span class="p">(</span><span class="s">&quot;--cached and --no-index are incompatible&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="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;--color&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">color</span> <span class="o">=</span> <span class="mi">0</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;--no-color&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">color</span> <span class="o">=</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;-R&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_REVERSE</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;-a&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;--text&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_FORCE_TEXT</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;--ignore-space-at-eol&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_IGNORE_WHITESPACE_EOL</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;-b&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;--ignore-space-change&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_IGNORE_WHITESPACE_CHANGE</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;-w&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;--ignore-all-space&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_IGNORE_WHITESPACE</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;--ignored&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_INCLUDE_IGNORED</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;--untracked&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_INCLUDE_UNTRACKED</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;--patience&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_PATIENCE</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;--minimal&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_MINIMAL</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;--stat&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">output</span> <span class="o">|=</span> <span class="n">OUTPUT_STAT</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;--numstat&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">output</span> <span class="o">|=</span> <span class="n">OUTPUT_NUMSTAT</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;--shortstat&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">output</span> <span class="o">|=</span> <span class="n">OUTPUT_SHORTSTAT</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;--summary&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">output</span> <span class="o">|=</span> <span class="n">OUTPUT_SUMMARY</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_uint16_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">rename_threshold</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-M&quot;</span><span class="p">)</span> <span class="o">||</span>
+ <span class="n">match_uint16_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">rename_threshold</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--find-renames&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_FIND_RENAMES</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_uint16_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">copy_threshold</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-C&quot;</span><span class="p">)</span> <span class="o">||</span>
+ <span class="n">match_uint16_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">copy_threshold</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--find-copies&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_FIND_COPIES</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;--find-copies-harder&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">is_prefixed</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;-B&quot;</span><span class="p">)</span> <span class="o">||</span> <span class="n">is_prefixed</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--break-rewrites&quot;</span><span class="p">))</span>
+ <span class="cm">/* TODO: parse thresholds */</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">findopts</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_DIFF_FIND_REWRITES</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_uint32_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">context_lines</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-U&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
+ <span class="o">!</span><span class="n">match_uint32_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">context_lines</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--unified&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
+ <span class="o">!</span><span class="n">match_uint32_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">interhunk_lines</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--inter-hunk-context&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span>
+ <span class="o">!</span><span class="n">match_uint16_arg</span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">id_abbrev</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--abbrev&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</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">diffopts</span><span class="p">.</span><span class="n">old_prefix</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--src-prefix&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</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">diffopts</span><span class="p">.</span><span class="n">new_prefix</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--dst-prefix&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</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">dir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">))</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Unknown command line argument&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="p">}</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>Display diff output with &quot;--stat&quot;, &quot;--numstat&quot;, or &quot;--shortstat&quot;</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">diff_print_stats</span><span class="p">(</span><span class="n">git_diff</span> <span class="o">*</span><span class="n">diff</span><span class="p">,</span> <span class="k">struct</span> <span class="n">diff_options</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_diff_stats</span> <span class="o">*</span><span class="n">stats</span><span class="p">;</span>
+ <span class="n">git_buf</span> <span class="n">b</span> <span class="o">=</span> <span class="n">GIT_BUF_INIT</span><span class="p">;</span>
+ <span class="n">git_diff_stats_format_t</span> <span class="n">format</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_get_stats-12" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_get_stats">git_diff_get_stats</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">stats</span><span class="p">,</span> <span class="n">diff</span><span class="p">),</span> <span class="s">&quot;generating stats for diff&quot;</span><span class="p">,</span> <span class="nb">NULL</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">output</span> <span class="o">&amp;</span> <span class="n">OUTPUT_STAT</span><span class="p">)</span>
+ <span class="n">format</span> <span class="o">|=</span> <span class="n">GIT_DIFF_STATS_FULL</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">output</span> <span class="o">&amp;</span> <span class="n">OUTPUT_SHORTSTAT</span><span class="p">)</span>
+ <span class="n">format</span> <span class="o">|=</span> <span class="n">GIT_DIFF_STATS_SHORT</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">output</span> <span class="o">&amp;</span> <span class="n">OUTPUT_NUMSTAT</span><span class="p">)</span>
+ <span class="n">format</span> <span class="o">|=</span> <span class="n">GIT_DIFF_STATS_NUMBER</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">output</span> <span class="o">&amp;</span> <span class="n">OUTPUT_SUMMARY</span><span class="p">)</span>
+ <span class="n">format</span> <span class="o">|=</span> <span class="n">GIT_DIFF_STATS_INCLUDE_SUMMARY</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_stats_to_buf-13" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_stats_to_buf">git_diff_stats_to_buf</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">b</span><span class="p">,</span> <span class="n">stats</span><span class="p">,</span> <span class="n">format</span><span class="p">,</span> <span class="mi">80</span><span class="p">),</span> <span class="s">&quot;formatting stats&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">fputs</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">ptr</span><span class="p">,</span> <span class="n">stdout</span><span class="p">);</span>
+
+ <span class="n"><a name="git_buf_dispose-2" class="fnlink" href="../../#v1.6.2/group/buf/git_buf_dispose">git_buf_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>
+ <span class="n"><a name="git_diff_stats_free-14" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_stats_free">git_diff_stats_free</a></span><span class="p">(</span><span class="n">stats</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/fetch.html b/ex/v1.6.2/fetch.html
new file mode 100644
index 000000000..51f7a9b45
--- /dev/null
+++ b/ex/v1.6.2/fetch.html
@@ -0,0 +1,214 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>fetch.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>fetch.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></span><span class="cp">#include</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">progress_cb</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">str</span><span class="p">,</span> <span class="kt">int</span> <span class="n">len</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">data</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;remote: %.*s&quot;</span><span class="p">,</span> <span class="n">len</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span>
+ <span class="n">fflush</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span> <span class="cm">/* We don&#39;t have the \n to force the flush */</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-2'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p>This function gets called for each remote-tracking branch that gets
+updated. The message we output depends on whether it&#39;s a new one or
+an update.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">update_cb</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">refname</span><span class="p">,</span> <span class="k">const</span> <span class="n">git_oid</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="k">const</span> <span class="n">git_oid</span> <span class="o">*</span><span class="n">b</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">a_str</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="n">b_str</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">];</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">data</span><span class="p">;</span>
+
+ <span class="n"><a name="git_oid_fmt-1" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">b_str</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
+ <span class="n">b_str</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_oid_is_zero-3" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_is_zero">git_oid_is_zero</a></span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;[new] %.20s %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">b_str</span><span class="p">,</span> <span class="n">refname</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_fmt-2" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">a_str</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="n">a_str</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;[updated] %.10s..%.10s %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">a_str</span><span class="p">,</span> <span class="n">b_str</span><span class="p">,</span> <span class="n">refname</span><span class="p">);</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-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>This gets called during the download and indexing. 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.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">transfer_progress_cb</span><span class="p">(</span><span class="k">const</span> <span class="n">git_indexer_progress</span> <span class="o">*</span><span class="n">stats</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">payload</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">stats</span><span class="o">-&gt;</span><span class="n">received_objects</span> <span class="o">==</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">total_objects</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Resolving deltas %u/%u</span><span class="se">\r</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">stats</span><span class="o">-&gt;</span><span class="n">indexed_deltas</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">total_deltas</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="n">stats</span><span class="o">-&gt;</span><span class="n">total_objects</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Received %u/%u objects (%u) in %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot; bytes</span><span class="se">\r</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">stats</span><span class="o">-&gt;</span><span class="n">received_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">total_objects</span><span class="p">,</span>
+ <span class="n">stats</span><span class="o">-&gt;</span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">received_bytes</span><span class="p">);</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-4'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>Entry point for this command</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_fetch</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="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_remote</span> <span class="o">*</span><span class="n">remote</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_indexer_progress</span> <span class="o">*</span><span class="n">stats</span><span class="p">;</span>
+ <span class="n">git_fetch_options</span> <span class="n">fetch_opts</span> <span class="o">=</span> <span class="n">GIT_FETCH_OPTIONS_INIT</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;</span> <span class="mi">2</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;usage: %s fetch &lt;repo&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]);</span>
+ <span class="k">return</span> <span class="n">EXIT_FAILURE</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Figure out whether it&#39;s a named remote or a URL */</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Fetching %s for repo %p</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">repo</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_remote_lookup-5" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_remote_create_anonymous-4" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_create_anonymous">git_remote_create_anonymous</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">on_error</span><span class="p">;</span>
+
+ <span class="cm">/* Set up the callbacks (only update_tips for now) */</span>
+ <span class="n">fetch_opts</span><span class="p">.</span><span class="n">callbacks</span><span class="p">.</span><span class="n">update_tips</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">update_cb</span><span class="p">;</span>
+ <span class="n">fetch_opts</span><span class="p">.</span><span class="n">callbacks</span><span class="p">.</span><span class="n">sideband_progress</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">progress_cb</span><span class="p">;</span>
+ <span class="n">fetch_opts</span><span class="p">.</span><span class="n">callbacks</span><span class="p">.</span><span class="n">transfer_progress</span> <span class="o">=</span> <span class="n">transfer_progress_cb</span><span class="p">;</span>
+ <span class="n">fetch_opts</span><span class="p">.</span><span class="n">callbacks</span><span class="p">.</span><span class="n">credentials</span> <span class="o">=</span> <span class="n">cred_acquire_cb</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>Perform the fetch with the configured refspecs from the
+config. Update the reflog for the updated references with
+&quot;fetch&quot;.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_remote_fetch-8" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_fetch">git_remote_fetch</a></span><span class="p">(</span><span class="n">remote</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">fetch_opts</span><span class="p">,</span> <span class="s">&quot;fetch&quot;</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">on_error</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 there are local objects (we got a thin pack), then tell
+the user how many objects we saved from having to cross the
+network.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">stats</span> <span class="o">=</span> <span class="n"><a name="git_remote_stats-9" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_stats">git_remote_stats</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">stats</span><span class="o">-&gt;</span><span class="n">local_objects</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\r</span><span class="s">Received %u/%u objects in %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot; bytes (used %u local objects)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">stats</span><span class="o">-&gt;</span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">total_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">received_bytes</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">local_objects</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span><span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\r</span><span class="s">Received %u/%u objects in %&quot;</span> <span class="n">PRIuZ</span> <span class="s">&quot;bytes</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">stats</span><span class="o">-&gt;</span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">total_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-&gt;</span><span class="n">received_bytes</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_remote_free-6" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_free">git_remote_free</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="nl">on_error</span><span class="p">:</span>
+ <span class="n"><a name="git_remote_free-7" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_free">git_remote_free</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/for-each-ref.html b/ex/v1.6.2/for-each-ref.html
new file mode 100644
index 000000000..fc893b160
--- /dev/null
+++ b/ex/v1.6.2/for-each-ref.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>for-each-ref.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>for-each-ref.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/general.html b/ex/v1.6.2/general.html
new file mode 100644
index 000000000..6621cb3aa
--- /dev/null
+++ b/ex/v1.6.2/general.html
@@ -0,0 +1,1167 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>general.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>general.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;general&quot; example - shows basic libgit2 concepts</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></pre></div>
+ </td>
+ </tr>
+ <tr id='section-2'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-2">&#182;</a>
+ </div>
+ <p><a href="http://libgit2.github.com"><strong>libgit2</strong></a> is a portable, pure C implementation of the Git core
+methods provided as a re-entrant linkable library with a solid API,
+allowing you to write native speed custom Git applications in any
+language which supports C bindings.</p>
+
+<p>This file is an example of using that API in a real, compilable C file.
+As the API is updated, this file will be updated to demonstrate the new
+functionality.</p>
+
+<p>If you&#39;re trying to write something in C using <a href="http://libgit2.github.com">libgit2</a>, you should
+also check out the generated <a href="http://libgit2.github.com/libgit2">API documentation</a>. We try to link to
+the relevant sections of the API docs in each section in this file.</p>
+
+<p><strong>libgit2</strong> (for the most part) only implements the core plumbing
+functions, not really the higher level porcelain stuff. For a primer on
+Git Internals that you will need to know to work with Git at this level,
+check out <a href="https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain">Chapter 10</a> of the Pro Git book.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#include</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Includes'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Includes">&#182;</a>
+ </div>
+ <h3>Includes</h3>
+
+<p>Including the <code>git2.h</code> header will include all the other libgit2 headers
+that you need. It should be the only thing you need to include in order
+to compile properly and get all the libgit2 API.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#include</span> <span class="cpf">&quot;git2.h&quot;</span><span class="cp"></span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">oid_parsing</span><span class="p">(</span><span class="n">git_oid</span> <span class="o">*</span><span class="n">out</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">object_database</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="n">git_oid</span> <span class="o">*</span><span class="n">oid</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">commit_writing</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">commit_parsing</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">tag_parsing</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">tree_parsing</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">blob_parsing</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">revwalking</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">index_walking</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">reference_listing</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">config_files</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">repo_path</span><span class="p">,</span> <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</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>Almost all libgit2 functions return 0 on success or negative on error.
+This is not production quality error checking, but should be sufficient
+as an example.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">check_error</span><span class="p">(</span><span class="kt">int</span> <span class="n">error_code</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">action</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">const</span> <span class="n">git_error</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_error_last-33" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">();</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">error_code</span><span class="p">)</span>
+ <span class="k">return</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Error %d %s - %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">error_code</span><span class="p">,</span> <span class="n">action</span><span class="p">,</span>
+ <span class="p">(</span><span class="n">error</span> <span class="o">&amp;&amp;</span> <span class="n">error</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">)</span> <span class="o">?</span> <span class="n">error</span><span class="o">-&gt;</span><span class="nl">message</span> <span class="p">:</span> <span class="s">&quot;???&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>
+
+<span class="kt">int</span> <span class="nf">lg2_general</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="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="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">repo_path</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>Initialize the library, this will set up any global state which libgit2 needs
+including threading and crypto</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_libgit2_init-34" class="fnlink" href="../../#v1.6.2/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Opening_the_Repository'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Opening_the_Repository">&#182;</a>
+ </div>
+ <h3>Opening the Repository</h3>
+
+<p>There are a couple of methods for opening a repository, this being the
+simplest. There are also <a href="http://libgit2.github.com/libgit2/#HEAD/group/repository">methods</a> for specifying the index file
+and work tree locations, here we assume they are in the normal places.</p>
+
+<p>(Try running this program against tests/resources/testrepo.git.)</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">repo_path</span> <span class="o">=</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">?</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">:</span> <span class="s">&quot;/opt/libgit2-test/.git&quot;</span><span class="p">;</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_open-59" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_open">git_repository_open</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">repo</span><span class="p">,</span> <span class="n">repo_path</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;opening repository&quot;</span><span class="p">);</span>
+
+ <span class="n">oid_parsing</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">object_database</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">commit_writing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">commit_parsing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">tag_parsing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">tree_parsing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">blob_parsing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">revwalking</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">index_walking</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">reference_listing</span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="n">config_files</span><span class="p">(</span><span class="n">repo_path</span><span class="p">,</span> <span class="n">repo</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>Finally, when you&#39;re done with the repository, you can free it as well.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_repository_free-60" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_free">git_repository_free</a></span><span class="p">(</span><span class="n">repo</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-SHA-1_Value_Conversions'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-SHA-1_Value_Conversions">&#182;</a>
+ </div>
+ <h3>SHA-1 Value Conversions</h3>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">oid_parsing</span><span class="p">(</span><span class="n">git_oid</span> <span class="o">*</span><span class="n">oid</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">out</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">];</span>
+ <span class="kt">char</span> <span class="n">hex</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;4a202b346bb0fb0db7eff3cffeb3c70babbd2045&quot;</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;*Hex to Raw*</span><span class="se">\n</span><span class="s">&quot;</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>For our first example, we will convert a 40 character hex value to the
+20 byte raw SHA1 value.</p>
+
+<p>The <code>git_oid</code> is the structure that keeps the SHA value. We will use
+this throughout the example for storing the value of the current SHA
+key we&#39;re working with.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="n">hex</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="n">hex</span><span class="p">);</span>
+<span class="cp">#endif</span>
+
+ <span class="cm">/*</span>
+<span class="cm"> * Once we&#39;ve converted the string into the oid value, we can get the raw</span>
+<span class="cm"> * value of the SHA by accessing `oid.id`</span>
+<span class="cm"> *</span>
+<span class="cm"> * Next we will convert the 20 byte raw SHA1 value to a human readable 40</span>
+<span class="cm"> * char hex value.</span>
+<span class="cm"> */</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Raw to Hex*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">out</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</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>If you have a oid, you can easily get the hex value of the SHA as well.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_oid_fmt-48" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">oid</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;SHA hex string: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">out</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Working_with_the_Object_Database'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Working_with_the_Object_Database">&#182;</a>
+ </div>
+ <h3>Working with the Object Database</h3>
+
+<p><strong>libgit2</strong> provides <a href="http://libgit2.github.com/libgit2/#HEAD/group/odb">direct access</a> to the object database. The
+object database is where the actual objects are stored in Git. For
+working with raw objects, we&#39;ll need to get this structure from the
+repository.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">object_database</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="n">git_oid</span> <span class="o">*</span><span class="n">oid</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">oid_hex</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">0</span> <span class="p">};</span>
+ <span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="n">data</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">str_type</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="n">git_odb_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">;</span>
+ <span class="n">git_odb</span> <span class="o">*</span><span class="n">odb</span><span class="p">;</span>
+ <span class="n">git_object_t</span> <span class="n">otype</span><span class="p">;</span>
+
+ <span class="n"><a name="git_repository_odb-63" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_odb">git_repository_odb</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">odb</span><span class="p">,</span> <span class="n">repo</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Raw_Object_Reading'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Raw_Object_Reading">&#182;</a>
+ </div>
+ <h4>Raw Object Reading</h4>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Raw Object Read*</span><span class="se">\n</span><span class="s">&quot;</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>We can read raw objects directly from the object database if we have
+the oid (SHA) of the object. This allows us to access objects without
+knowing their type and inspect the raw bytes unparsed.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_odb_read-42" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_read">git_odb_read</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">odb</span><span class="p">,</span> <span class="n">oid</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;finding object in repository&quot;</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>A raw object only has three properties - the type (commit, blob, tree
+or tag), the size of the raw data and the raw, unparsed data itself.
+For a commit or tag, that raw data is human readable plain ASCII
+text. For a blob it is just file contents, so it could be text or
+binary data. For a tree it is a special binary format, so it&#39;s unlikely
+to be hugely helpful as a raw object.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">data</span> <span class="o">=</span> <span class="p">(</span><span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="p">)</span><span class="n"><a name="git_odb_object_data-45" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_data">git_odb_object_data</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</span>
+ <span class="n">otype</span> <span class="o">=</span> <span class="n"><a name="git_odb_object_type-47" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_type">git_odb_object_type</a></span><span class="p">(</span><span class="n">obj</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>We provide methods to convert from the object type which is an enum, to
+a string representation of that value (and vice-versa).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">str_type</span> <span class="o">=</span> <span class="n"><a name="git_object_type2string-39" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n">otype</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;object length and type: %d, %s</span><span class="se">\n</span><span class="s">object data: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_odb_object_size-46" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_size">git_odb_object_size</a></span><span class="p">(</span><span class="n">obj</span><span class="p">),</span>
+ <span class="n">str_type</span><span class="p">,</span> <span class="n">data</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-16'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-16">&#182;</a>
+ </div>
+ <p>For proper memory management, close the object when you are done with
+it or it will leak memory.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_odb_object_free-44" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_object_free">git_odb_object_free</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Raw_Object_Writing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Raw_Object_Writing">&#182;</a>
+ </div>
+ <h4>Raw Object Writing</h4>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Raw Object Write*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-18'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-18">&#182;</a>
+ </div>
+ <p>You can also write raw object data to Git. This is pretty cool because
+it gives you direct access to the key/value properties of Git. Here
+we&#39;ll write a new blob object that just contains a simple string.
+Notice that we have to specify the object type as the <code>git_otype</code> enum.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_odb_write-43" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_write">git_odb_write</a></span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="n">odb</span><span class="p">,</span> <span class="s">&quot;test data&quot;</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="s">&quot;test data&quot;</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">GIT_OBJECT_BLOB</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-19'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-19">&#182;</a>
+ </div>
+ <p>Now that we&#39;ve written the object, we can check out what SHA1 was
+generated when the object was written to our database.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_oid_fmt-49" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid_hex</span><span class="p">,</span> <span class="n">oid</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Written Object: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oid_hex</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-20'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-20">&#182;</a>
+ </div>
+ <p>Free the object database after usage.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_odb_free-41" class="fnlink" href="../../#v1.6.2/group/odb/git_odb_free">git_odb_free</a></span><span class="p">(</span><span class="n">odb</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Writing_Commits'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Writing_Commits">&#182;</a>
+ </div>
+ <h4>Writing Commits</h4>
+
+<p>libgit2 provides a couple of methods to create commit objects easily as
+well. There are four different create signatures, we&#39;ll just show one
+of them here. You can read about the other ones in the <a href="http://libgit2.github.com/libgit2/#HEAD/group/commit">commit API
+docs</a>.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">commit_writing</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_oid</span> <span class="n">tree_id</span><span class="p">,</span> <span class="n">parent_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>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">parent</span><span class="p">;</span>
+ <span class="n">git_signature</span> <span class="o">*</span><span class="n">author</span><span class="p">,</span> <span class="o">*</span><span class="n">committer</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">oid_hex</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">0</span> <span class="p">};</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Commit Writing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-22'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-22">&#182;</a>
+ </div>
+ <p>Creating signatures for an authoring identity and time is simple. You
+will need to do this to specify who created a commit and when. Default
+values for the name and email should be found in the <code>user.name</code> and
+<code>user.email</code> configuration options. See the <code>config</code> section of this
+example file to see how to access config values.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_signature_new-70" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_new">git_signature_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">author</span><span class="p">,</span>
+ <span class="s">&quot;Scott Chacon&quot;</span><span class="p">,</span> <span class="s">&quot;schacon@gmail.com&quot;</span><span class="p">,</span> <span class="mi">123456789</span><span class="p">,</span> <span class="mi">60</span><span class="p">);</span>
+ <span class="n"><a name="git_signature_new-71" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_new">git_signature_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">committer</span><span class="p">,</span>
+ <span class="s">&quot;Scott A Chacon&quot;</span><span class="p">,</span> <span class="s">&quot;scott@github.com&quot;</span><span class="p">,</span> <span class="mi">987654321</span><span class="p">,</span> <span class="mi">90</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-23'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-23">&#182;</a>
+ </div>
+ <p>Commit objects need a tree to point to and optionally one or more
+parents. Here we&#39;re creating oid objects to create the commit with,
+but you can also use</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">tree_id</span><span class="p">,</span> <span class="s">&quot;f60079018b664e4e79329a7ef9559c8d9e0378d1&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent_id</span><span class="p">,</span> <span class="s">&quot;5b5b025afb0b4c913b4c338a42934a3863bf3644&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">tree_id</span><span class="p">,</span> <span class="s">&quot;f60079018b664e4e79329a7ef9559c8d9e0378d1&quot;</span><span class="p">);</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent_id</span><span class="p">,</span> <span class="s">&quot;5b5b025afb0b4c913b4c338a42934a3863bf3644&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span>
+ <span class="n"><a name="git_tree_lookup-81" class="fnlink" href="../../#v1.6.2/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="n"><a name="git_commit_lookup-6" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">parent_id</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-24'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-24">&#182;</a>
+ </div>
+ <p>Here we actually create the commit object with a single call with all
+the values we need to create the commit. The SHA key is written to the
+<code>commit_id</code> variable here.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_commit_create_v-25" class="fnlink" href="../../#v1.6.2/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="cm">/* out id */</span>
+ <span class="n">repo</span><span class="p">,</span>
+ <span class="nb">NULL</span><span class="p">,</span> <span class="cm">/* do not update the HEAD */</span>
+ <span class="n">author</span><span class="p">,</span>
+ <span class="n">committer</span><span class="p">,</span>
+ <span class="nb">NULL</span><span class="p">,</span> <span class="cm">/* use default message encoding */</span>
+ <span class="s">&quot;example commit&quot;</span><span class="p">,</span>
+ <span class="n">tree</span><span class="p">,</span>
+ <span class="mi">1</span><span class="p">,</span> <span class="n">parent</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-25'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-25">&#182;</a>
+ </div>
+ <p>Now we can take a look at the commit SHA we&#39;ve generated.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_oid_fmt-50" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid_hex</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">commit_id</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;New Commit: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oid_hex</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-26'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-26">&#182;</a>
+ </div>
+ <p>Free all objects used in the meanwhile.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_tree_free-83" class="fnlink" href="../../#v1.6.2/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_commit_free-9" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">parent</span><span class="p">);</span>
+ <span class="n"><a name="git_signature_free-72" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_free">git_signature_free</a></span><span class="p">(</span><span class="n">author</span><span class="p">);</span>
+ <span class="n"><a name="git_signature_free-73" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_free">git_signature_free</a></span><span class="p">(</span><span class="n">committer</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Object_Parsing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Object_Parsing">&#182;</a>
+ </div>
+ <h3>Object Parsing</h3>
+
+<p>libgit2 has methods to parse every object type in Git so you don&#39;t have
+to work directly with the raw data. This is much faster and simpler
+than trying to deal with the raw data yourself.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Commit_Parsing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Commit_Parsing">&#182;</a>
+ </div>
+ <h4>Commit Parsing</h4>
+
+<p><a href="http://libgit2.github.com/libgit2/#HEAD/group/commit">Parsing commit objects</a> is simple and gives you access to all the
+data in the commit - the author (name, email, datetime), committer
+(same), tree, message, encoding and parent(s).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">commit_parsing</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="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">author</span><span class="p">,</span> <span class="o">*</span><span class="n">cmtter</span><span class="p">;</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="o">*</span><span class="n">parent</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">oid_hex</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">];</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">parents</span><span class="p">,</span> <span class="n">p</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="kt">time_t</span> <span class="n">time</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Commit Parsing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+
+<span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;8496071c1b46c854b31185ea97743be6a8774479&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;8496071c1b46c854b31185ea97743be6a8774479&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_commit_lookup-7" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">commit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;looking up commit&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-29'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-29">&#182;</a>
+ </div>
+ <p>Each of the properties of the commit object are accessible via methods,
+including commonly needed variations, such as <code><a name="git_commit_time-18" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_time">git_commit_time</a></code> which
+returns the author time and <code><a name="git_commit_message-15" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></code> which gives you the
+commit message (as a NUL-terminated string).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">message</span> <span class="o">=</span> <span class="n"><a name="git_commit_message-16" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="n">author</span> <span class="o">=</span> <span class="n"><a name="git_commit_author-21" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_author">git_commit_author</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="n">cmtter</span> <span class="o">=</span> <span class="n"><a name="git_commit_committer-20" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_committer">git_commit_committer</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="n">time</span> <span class="o">=</span> <span class="n"><a name="git_commit_time-19" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_time">git_commit_time</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-30'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-30">&#182;</a>
+ </div>
+ <p>The author and committer methods return [git<em>signature] structures,
+which give you name, email and <code>when</code>, which is a `git</em>time` structure,
+giving you a timestamp and timezone offset.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Author: %s (%s)</span><span class="se">\n</span><span class="s">Committer: %s (%s)</span><span class="se">\n</span><span class="s">Date: %s</span><span class="se">\n</span><span class="s">Message: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">author</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">author</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">,</span>
+ <span class="n">cmtter</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">cmtter</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">,</span>
+ <span class="n">ctime</span><span class="p">(</span><span class="o">&amp;</span><span class="n">time</span><span class="p">),</span> <span class="n">message</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-31'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-31">&#182;</a>
+ </div>
+ <p>Commits can have zero or more parents. The first (root) commit will
+have no parents, most commits will have one (i.e. the commit it was
+based on) and merge commits will have two or more. Commits can
+technically have any number, though it&#39;s rare to have more than two.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">parents</span> <span class="o">=</span> <span class="n"><a name="git_commit_parentcount-23" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parentcount">git_commit_parentcount</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span><span class="n">p</span> <span class="o">&lt;</span> <span class="n">parents</span><span class="p">;</span><span class="n">p</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">memset</span><span class="p">(</span><span class="n">oid_hex</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">oid_hex</span><span class="p">));</span>
+
+ <span class="n"><a name="git_commit_parent-24" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent</span><span class="p">,</span> <span class="n">commit</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
+ <span class="n"><a name="git_oid_fmt-51" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid_hex</span><span class="p">,</span> <span class="n"><a name="git_commit_id-14" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_id">git_commit_id</a></span><span class="p">(</span><span class="n">parent</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Parent: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oid_hex</span><span class="p">);</span>
+ <span class="n"><a name="git_commit_free-10" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">parent</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_commit_free-11" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Tag_Parsing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Tag_Parsing">&#182;</a>
+ </div>
+ <h4>Tag Parsing</h4>
+
+<p>You can parse and create tags with the <a href="http://libgit2.github.com/libgit2/#HEAD/group/tag">tag management API</a>, which
+functions very similarly to the commit lookup, parsing and creation
+methods, since the objects themselves are very similar.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">tag_parsing</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_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">;</span>
+ <span class="n">git_object_t</span> <span class="n">type</span><span class="p">;</span>
+ <span class="n">git_tag</span> <span class="o">*</span><span class="n">tag</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Tag Parsing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-33'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-33">&#182;</a>
+ </div>
+ <p>We create an oid for the tag object if we know the SHA and look it up
+the same way that we would a commit (or any other object).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;b25fa35b38051e4ae45d4222e795f9df2e43f1d1&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;b25fa35b38051e4ae45d4222e795f9df2e43f1d1&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_tag_lookup-75" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_lookup">git_tag_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tag</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;looking up tag&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-34'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-34">&#182;</a>
+ </div>
+ <p>Now that we have the tag object, we can extract the information it
+generally contains: the target (usually a commit object), the type of
+the target object (usually &#39;commit&#39;), the name (&#39;v1.0&#39;), the tagger (a
+git_signature - name, email, timestamp), and the tag message.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_tag_target-77" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_target">git_tag_target</a></span><span class="p">((</span><span class="n">git_object</span> <span class="o">**</span><span class="p">)</span><span class="o">&amp;</span><span class="n">commit</span><span class="p">,</span> <span class="n">tag</span><span class="p">);</span>
+ <span class="n">name</span> <span class="o">=</span> <span class="n"><a name="git_tag_name-79" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_name">git_tag_name</a></span><span class="p">(</span><span class="n">tag</span><span class="p">);</span> <span class="cm">/* &quot;test&quot; */</span>
+ <span class="n">type</span> <span class="o">=</span> <span class="n"><a name="git_tag_target_type-78" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_target_type">git_tag_target_type</a></span><span class="p">(</span><span class="n">tag</span><span class="p">);</span> <span class="cm">/* GIT_OBJECT_COMMIT (object_t enum) */</span>
+ <span class="n">message</span> <span class="o">=</span> <span class="n"><a name="git_tag_message-80" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_message">git_tag_message</a></span><span class="p">(</span><span class="n">tag</span><span class="p">);</span> <span class="cm">/* &quot;tag message\n&quot; */</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Tag Name: %s</span><span class="se">\n</span><span class="s">Tag Type: %s</span><span class="se">\n</span><span class="s">Tag Message: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">name</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-40" class="fnlink" href="../../#v1.6.2/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n">type</span><span class="p">),</span> <span class="n">message</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-35'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-35">&#182;</a>
+ </div>
+ <p>Free both the commit and tag after usage.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_commit_free-12" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="n"><a name="git_tag_free-76" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_free">git_tag_free</a></span><span class="p">(</span><span class="n">tag</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Tree_Parsing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Tree_Parsing">&#182;</a>
+ </div>
+ <h4>Tree Parsing</h4>
+
+<p><a href="http://libgit2.github.com/libgit2/#HEAD/group/tree">Tree parsing</a> is a bit different than the other objects, in that
+we have a subtype which is the tree entry. This is not an actual
+object type in Git, but a useful structure for parsing and traversing
+tree entries.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">tree_parsing</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="k">const</span> <span class="n">git_tree_entry</span> <span class="o">*</span><span class="n">entry</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">cnt</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">;</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Tree Parsing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-37'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-37">&#182;</a>
+ </div>
+ <p>Create the oid and lookup the tree object just like the other objects.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;f60079018b664e4e79329a7ef9559c8d9e0378d1&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;f60079018b664e4e79329a7ef9559c8d9e0378d1&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span>
+ <span class="n"><a name="git_tree_lookup-82" class="fnlink" href="../../#v1.6.2/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">oid</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-38'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-38">&#182;</a>
+ </div>
+ <p>Getting the count of entries in the tree so you can iterate over them
+if you want to.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">cnt</span> <span class="o">=</span> <span class="n"><a name="git_tree_entrycount-85" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entrycount">git_tree_entrycount</a></span><span class="p">(</span><span class="n">tree</span><span class="p">);</span> <span class="cm">/* 2 */</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;tree entries: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">cnt</span><span class="p">);</span>
+
+ <span class="n">entry</span> <span class="o">=</span> <span class="n"><a name="git_tree_entry_byindex-87" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_byindex">git_tree_entry_byindex</a></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="n">printf</span><span class="p">(</span><span class="s">&quot;Entry name: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_tree_entry_name-88" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_name">git_tree_entry_name</a></span><span class="p">(</span><span class="n">entry</span><span class="p">));</span> <span class="cm">/* &quot;README&quot; */</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-39'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-39">&#182;</a>
+ </div>
+ <p>You can also access tree entries by name if you know the name of the
+entry you&#39;re looking for.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">entry</span> <span class="o">=</span> <span class="n"><a name="git_tree_entry_byname-86" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_byname">git_tree_entry_byname</a></span><span class="p">(</span><span class="n">tree</span><span class="p">,</span> <span class="s">&quot;README&quot;</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_entry_name-89" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_name">git_tree_entry_name</a></span><span class="p">(</span><span class="n">entry</span><span class="p">);</span> <span class="cm">/* &quot;README&quot; */</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-40'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-40">&#182;</a>
+ </div>
+ <p>Once you have the entry object, you can access the content or subtree
+(or commit, in the case of submodules) that it points to. You can also
+get the mode if you want.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_tree_entry_to_object-90" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_entry_to_object">git_tree_entry_to_object</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">entry</span><span class="p">);</span> <span class="cm">/* blob */</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-41'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-41">&#182;</a>
+ </div>
+ <p>Remember to close the looked-up object and tree once you are done using it</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_object_free-38" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-84" class="fnlink" href="../../#v1.6.2/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="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Blob_Parsing'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Blob_Parsing">&#182;</a>
+ </div>
+ <h4>Blob Parsing</h4>
+
+<p>The last object type is the simplest and requires the least parsing
+help. Blobs are just file contents and can contain anything, there is
+no structure to it. The main advantage to using the <a href="http://libgit2.github.com/libgit2/#HEAD/group/blob">simple blob
+api</a> is that when you&#39;re creating blobs you don&#39;t have to calculate
+the size of the content. There is also a helper for reading a file
+from disk and writing it to the db and getting the oid back so you
+don&#39;t have to do all those steps yourself.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">blob_parsing</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_blob</span> <span class="o">*</span><span class="n">blob</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Blob Parsing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+
+<span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;1385f264afb75a56a5bec74243be9b367ba4ca08&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;1385f264afb75a56a5bec74243be9b367ba4ca08&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span>
+ <span class="n"><a name="git_blob_lookup-1" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_lookup">git_blob_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">blob</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-43'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-43">&#182;</a>
+ </div>
+ <p>You can access a buffer with the raw contents of the blob directly.
+Note that this buffer may not be contain ASCII data for certain blobs
+(e.g. binary files): do not consider the buffer a NULL-terminated
+string, and use the <code><a name="git_blob_rawsize-4" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawsize">git_blob_rawsize</a></code> attribute to find out its exact
+size in bytes</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Blob Size: %ld</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">long</span><span class="p">)</span><span class="n"><a name="git_blob_rawsize-5" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawsize">git_blob_rawsize</a></span><span class="p">(</span><span class="n">blob</span><span class="p">));</span> <span class="cm">/* 8 */</span>
+ <span class="n"><a name="git_blob_rawcontent-3" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_rawcontent">git_blob_rawcontent</a></span><span class="p">(</span><span class="n">blob</span><span class="p">);</span> <span class="cm">/* &quot;content&quot; */</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-44'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-44">&#182;</a>
+ </div>
+ <p>Free the blob after usage.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_blob_free-2" class="fnlink" href="../../#v1.6.2/group/blob/git_blob_free">git_blob_free</a></span><span class="p">(</span><span class="n">blob</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Revwalking'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Revwalking">&#182;</a>
+ </div>
+ <h3>Revwalking</h3>
+
+<p>The libgit2 <a href="http://libgit2.github.com/libgit2/#HEAD/group/revwalk">revision walking api</a> provides methods to traverse the
+directed graph created by the parent pointers of the commit objects.
+Since all commits point back to the commit that came directly before
+them, you can walk this parentage as a graph and find all the commits
+that were ancestors of (reachable from) a given starting point. This
+can allow you to create <code>git log</code> type functionality.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">revwalking</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="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">cauth</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">cmsg</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="n">git_revwalk</span> <span class="o">*</span><span class="n">walk</span><span class="p">;</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">wcommit</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Revwalking*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+
+<span class="cp">#ifdef GIT_EXPERIMENTAL_SHA256</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;5b5b025afb0b4c913b4c338a42934a3863bf3644&quot;</span><span class="p">,</span> <span class="n">GIT_OID_SHA1</span><span class="p">);</span>
+<span class="cp">#else</span>
+ <span class="n">git_oid_fromstr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="s">&quot;5b5b025afb0b4c913b4c338a42934a3863bf3644&quot;</span><span class="p">);</span>
+<span class="cp">#endif</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-46'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-46">&#182;</a>
+ </div>
+ <p>To use the revwalker, create a new walker, tell it how you want to sort
+the output and then push one or more starting points onto the walker.
+If you want to emulate the output of <code>git log</code> you would push the SHA
+of the commit that HEAD points to into the walker and then start
+traversing them. You can also &#39;hide&#39; commits that you want to stop at
+or not see any of their ancestors. So if you want to emulate <code>git log
+branch1..branch2</code>, you would push the oid of <code>branch2</code> and hide the oid
+of <code>branch1</code>.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_revwalk_new-65" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">walk</span><span class="p">,</span> <span class="n">repo</span><span class="p">);</span>
+ <span class="n"><a name="git_revwalk_sorting-68" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_sorting">git_revwalk_sorting</a></span><span class="p">(</span><span class="n">walk</span><span class="p">,</span> <span class="n">GIT_SORT_TOPOLOGICAL</span> <span class="o">|</span> <span class="n">GIT_SORT_REVERSE</span><span class="p">);</span>
+ <span class="n"><a name="git_revwalk_push-66" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_push">git_revwalk_push</a></span><span class="p">(</span><span class="n">walk</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-47'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-47">&#182;</a>
+ </div>
+ <p>Now that we have the starting point pushed onto the walker, we start
+asking for ancestors. It will return them in the sorting order we asked
+for as commit oids. We can then lookup and parse the committed pointed
+at by the returned OID; note that this operation is specially fast
+since the raw contents of the commit object will be cached in memory</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">while</span> <span class="p">((</span><span class="n"><a name="git_revwalk_next-67" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_next">git_revwalk_next</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="n">walk</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_commit_lookup-8" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">wcommit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;looking up commit during revwalk&quot;</span><span class="p">);</span>
+
+ <span class="n">cmsg</span> <span class="o">=</span> <span class="n"><a name="git_commit_message-17" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">wcommit</span><span class="p">);</span>
+ <span class="n">cauth</span> <span class="o">=</span> <span class="n"><a name="git_commit_author-22" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_author">git_commit_author</a></span><span class="p">(</span><span class="n">wcommit</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s (%s)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">cmsg</span><span class="p">,</span> <span class="n">cauth</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">);</span>
+
+ <span class="n"><a name="git_commit_free-13" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">wcommit</span><span class="p">);</span>
+ <span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-48'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-48">&#182;</a>
+ </div>
+ <p>Like the other objects, be sure to free the revwalker when you&#39;re done
+to prevent memory leaks. Also, make sure that the repository being
+walked it not deallocated while the walk is in progress, or it will
+result in undefined behavior</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_revwalk_free-69" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_free">git_revwalk_free</a></span><span class="p">(</span><span class="n">walk</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Index_File_Manipulation_*'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Index_File_Manipulation_*">&#182;</a>
+ </div>
+ <h3>Index File Manipulation *</h3>
+
+<p>The <a href="http://libgit2.github.com/libgit2/#HEAD/group/index">index file API</a> allows you to read, traverse, update and write
+the Git index file (sometimes thought of as the staging area).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">index_walking</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_index</span> <span class="o">*</span><span class="n">index</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">,</span> <span class="n">ecount</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Index Walking*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-50'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-50">&#182;</a>
+ </div>
+ <p>You can either open the index from the standard location in an open
+repository, as we&#39;re doing here, or you can open and manipulate any
+index file with <code>git_index_open_bare()</code>. The index for the repository
+will be located and loaded from disk.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_repository_index-64" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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></pre></div>
+ </td>
+ </tr>
+ <tr id='section-51'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-51">&#182;</a>
+ </div>
+ <p>For each entry in the index, you can get a bunch of information
+including the SHA (oid), path and mode which map to the tree objects
+that are written out. It also has filesystem properties to help
+determine what to inspect for changes (ctime, mtime, dev, ino, uid,
+gid, file<em>size and flags) All these properties are exported publicly in
+the `git</em>index_entry` struct</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">ecount</span> <span class="o">=</span> <span class="n"><a name="git_index_entrycount-36" class="fnlink" href="../../#v1.6.2/group/index/git_index_entrycount">git_index_entrycount</a></span><span class="p">(</span><span class="n">index</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">ecount</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="n">git_index_entry</span> <span class="o">*</span><span class="n">e</span> <span class="o">=</span> <span class="n"><a name="git_index_get_byindex-37" class="fnlink" href="../../#v1.6.2/group/index/git_index_get_byindex">git_index_get_byindex</a></span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;path: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="o">-&gt;</span><span class="n">path</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;mtime: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">e</span><span class="o">-&gt;</span><span class="n">mtime</span><span class="p">.</span><span class="n">seconds</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;fs: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">e</span><span class="o">-&gt;</span><span class="n">file_size</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_index_free-35" class="fnlink" href="../../#v1.6.2/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="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-References'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-References">&#182;</a>
+ </div>
+ <h3>References</h3>
+
+<p>The <a href="http://libgit2.github.com/libgit2/#HEAD/group/reference">reference API</a> allows you to list, resolve, create and update
+references such as branches, tags and remote references (everything in
+the .git/refs directory).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">reference_listing</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_strarray</span> <span class="n">ref_list</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">i</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Reference Listing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-53'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-53">&#182;</a>
+ </div>
+ <p>Here we will implement something like <code>git for-each-ref</code> simply listing
+out all available references and the object SHA they resolve to.</p>
+
+<p>Now that we have the list of reference names, we can lookup each ref
+one at a time and resolve them to the SHA, then print both values out.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n"><a name="git_reference_list-57" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_list">git_reference_list</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ref_list</span><span class="p">,</span> <span class="n">repo</span><span class="p">);</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">ref_list</span><span class="p">.</span><span class="n">count</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">ref</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">oid_hex</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">GIT_OID_SHA1_HEXZERO</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">refname</span><span class="p">;</span>
+
+ <span class="n">refname</span> <span class="o">=</span> <span class="n">ref_list</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
+ <span class="n"><a name="git_reference_lookup-53" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_lookup">git_reference_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">refname</span><span class="p">);</span>
+
+ <span class="k">switch</span> <span class="p">(</span><span class="n"><a name="git_reference_type-56" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_type">git_reference_type</a></span><span class="p">(</span><span class="n">ref</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">GIT_REFERENCE_DIRECT</span><span class="p">:</span>
+ <span class="n"><a name="git_oid_fmt-52" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid_hex</span><span class="p">,</span> <span class="n"><a name="git_reference_target-54" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_target">git_reference_target</a></span><span class="p">(</span><span class="n">ref</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s [%s]</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">refname</span><span class="p">,</span> <span class="n">oid_hex</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="nl">GIT_REFERENCE_SYMBOLIC</span><span class="p">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s =&gt; %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">refname</span><span class="p">,</span> <span class="n"><a name="git_reference_symbolic_target-55" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_symbolic_target">git_reference_symbolic_target</a></span><span class="p">(</span><span class="n">ref</span><span class="p">));</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Unexpected reference type</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>
+
+ <span class="n"><a name="git_reference_free-58" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">ref</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_strarray_dispose-74" class="fnlink" href="../../#v1.6.2/group/strarray/git_strarray_dispose">git_strarray_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ref_list</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-Config_Files'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-Config_Files">&#182;</a>
+ </div>
+ <h3>Config Files</h3>
+
+<p>The <a href="http://libgit2.github.com/libgit2/#HEAD/group/config">config API</a> allows you to list and update config values
+in any of the accessible config file locations (system, global, local).</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">config_files</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">repo_path</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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">email</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">config_path</span><span class="p">[</span><span class="mi">256</span><span class="p">];</span>
+ <span class="kt">int32_t</span> <span class="n">autocorrect</span><span class="p">;</span>
+ <span class="n">git_config</span> <span class="o">*</span><span class="n">cfg</span><span class="p">;</span>
+ <span class="n">git_config</span> <span class="o">*</span><span class="n">snap_cfg</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error_code</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">*Config Listing*</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-55'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-55">&#182;</a>
+ </div>
+ <p>Open a config object so we can read global values from it.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">sprintf</span><span class="p">(</span><span class="n">config_path</span><span class="p">,</span> <span class="s">&quot;%s/config&quot;</span><span class="p">,</span> <span class="n">repo_path</span><span class="p">);</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n"><a name="git_config_open_ondisk-26" class="fnlink" href="../../#v1.6.2/group/config/git_config_open_ondisk">git_config_open_ondisk</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">cfg</span><span class="p">,</span> <span class="n">config_path</span><span class="p">),</span> <span class="s">&quot;opening config&quot;</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_config_get_int32-29" class="fnlink" href="../../#v1.6.2/group/config/git_config_get_int32">git_config_get_int32</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">autocorrect</span><span class="p">,</span> <span class="n">cfg</span><span class="p">,</span> <span class="s">&quot;help.autocorrect&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Autocorrect: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">autocorrect</span><span class="p">);</span>
+
+ <span class="n">check_error</span><span class="p">(</span><span class="n"><a name="git_repository_config_snapshot-61" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_config_snapshot">git_repository_config_snapshot</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">snap_cfg</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">&quot;config snapshot&quot;</span><span class="p">);</span>
+ <span class="n"><a name="git_config_get_string-31" class="fnlink" href="../../#v1.6.2/group/config/git_config_get_string">git_config_get_string</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">email</span><span class="p">,</span> <span class="n">snap_cfg</span><span class="p">,</span> <span class="s">&quot;user.email&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Email: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">email</span><span class="p">);</span>
+
+ <span class="n">error_code</span> <span class="o">=</span> <span class="n"><a name="git_config_get_int32-30" class="fnlink" href="../../#v1.6.2/group/config/git_config_get_int32">git_config_get_int32</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">autocorrect</span><span class="p">,</span> <span class="n">cfg</span><span class="p">,</span> <span class="s">&quot;help.autocorrect&quot;</span><span class="p">);</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="n">error_code</span><span class="p">)</span>
+ <span class="p">{</span>
+ <span class="k">case</span> <span class="mi">0</span><span class="o">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Autocorrect: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">autocorrect</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_ENOTFOUND</span><span class="p">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Autocorrect: Undefined</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error_code</span><span class="p">,</span> <span class="s">&quot;get_int32 failed&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n"><a name="git_config_free-27" class="fnlink" href="../../#v1.6.2/group/config/git_config_free">git_config_free</a></span><span class="p">(</span><span class="n">cfg</span><span class="p">);</span>
+
+ <span class="n">check_error</span><span class="p">(</span><span class="n"><a name="git_repository_config_snapshot-62" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_config_snapshot">git_repository_config_snapshot</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">snap_cfg</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">&quot;config snapshot&quot;</span><span class="p">);</span>
+ <span class="n">error_code</span> <span class="o">=</span> <span class="n"><a name="git_config_get_string-32" class="fnlink" href="../../#v1.6.2/group/config/git_config_get_string">git_config_get_string</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">email</span><span class="p">,</span> <span class="n">snap_cfg</span><span class="p">,</span> <span class="s">&quot;user.email&quot;</span><span class="p">);</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="n">error_code</span><span class="p">)</span>
+ <span class="p">{</span>
+ <span class="k">case</span> <span class="mi">0</span><span class="o">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Email: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">email</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_ENOTFOUND</span><span class="p">:</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Email: Undefined</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="n">check_error</span><span class="p">(</span><span class="n">error_code</span><span class="p">,</span> <span class="s">&quot;get_string failed&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_config_free-28" class="fnlink" href="../../#v1.6.2/group/config/git_config_free">git_config_free</a></span><span class="p">(</span><span class="n">snap_cfg</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/index-pack.html b/ex/v1.6.2/index-pack.html
new file mode 100644
index 000000000..62cd8721c
--- /dev/null
+++ b/ex/v1.6.2/index-pack.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>index-pack.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>index-pack.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/init.html b/ex/v1.6.2/init.html
new file mode 100644
index 000000000..13bb61521
--- /dev/null
+++ b/ex/v1.6.2/init.html
@@ -0,0 +1,415 @@
+<!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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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></span><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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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">init_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">init_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">lg2_init</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="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">init_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">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"><a name="git_repository_init-5" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_init">git_repository_init</a></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"><a name="git_repository_init_ext-6" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_init_ext">git_repository_init_ext</a></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"><a name="git_repository_path-7" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_path">git_repository_path</a></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"><a name="git_repository_workdir-8" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_workdir">git_repository_workdir</a></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"><a name="git_repository_free-4" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_free">git_repository_free</a></span><span class="p">(</span><span class="n">repo</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-10" class="fnlink" href="../../#v1.6.2/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"><a name="git_repository_index-9" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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="../../#v1.6.2/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="../../#v1.6.2/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-12" class="fnlink" href="../../#v1.6.2/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="../../#v1.6.2/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-13" class="fnlink" href="../../#v1.6.2/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-11" class="fnlink" href="../../#v1.6.2/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">init_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="s">&quot;&quot;</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/lg2.html b/ex/v1.6.2/lg2.html
new file mode 100644
index 000000000..21041fb66
--- /dev/null
+++ b/ex/v1.6.2/lg2.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>lg2.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>lg2.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/log.html b/ex/v1.6.2/log.html
new file mode 100644
index 000000000..a785ff2c2
--- /dev/null
+++ b/ex/v1.6.2/log.html
@@ -0,0 +1,808 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>log.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>log.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;log&quot; example - shows how to walk history and get commit info</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the libgit2 rev walker APIs to roughly
+simulate the output of <code>git log</code> and a few of command line arguments.
+<code>git log</code> has many many options and this only shows a few of them.</p>
+
+<p>This does not have:</p>
+
+<ul>
+<li>Robust error handling</li>
+<li>Colorized or paginated output formatting</li>
+<li>Most of the <code>git log</code> options</li>
+</ul>
+
+<p>This does have:</p>
+
+<ul>
+<li>Examples of translating command line arguments to equivalent libgit2
+revwalker configuration calls</li>
+<li>Simplified options to apply pathspec limits and to show basic diffs</li>
+</ul>
+ </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>log_state represents walker being configured while handling options</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">log_state</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">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">repodir</span><span class="p">;</span>
+ <span class="n">git_revwalk</span> <span class="o">*</span><span class="n">walker</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">hide</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">sorting</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">revisions</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>utility functions that are called to configure the walker</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">set_sorting</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">sort_mode</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">push_rev</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">hide</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">add_revision</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">revstr</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>log_options holds other command line options that affect log output</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">log_options</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">show_diff</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">show_log_size</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">skip</span><span class="p">,</span> <span class="n">limit</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">min_parents</span><span class="p">,</span> <span class="n">max_parents</span><span class="p">;</span>
+ <span class="n">git_time_t</span> <span class="n">before</span><span class="p">;</span>
+ <span class="n">git_time_t</span> <span class="n">after</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">author</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">committer</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">grep</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>utility functions that parse options and help with log output</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">parse_options</span><span class="p">(</span>
+ <span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="k">struct</span> <span class="n">log_options</span> <span class="o">*</span><span class="n">opt</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="k">static</span> <span class="kt">void</span> <span class="nf">print_time</span><span class="p">(</span><span class="k">const</span> <span class="n">git_time</span> <span class="o">*</span><span class="n">intime</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">prefix</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_commit</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="k">struct</span> <span class="n">log_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">match_with_parent</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">git_diff_options</span> <span class="o">*</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>utility functions for filtering</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">signature_matches</span><span class="p">(</span><span class="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">sig</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filter</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">log_message_matches</span><span class="p">(</span><span class="k">const</span> <span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filter</span><span class="p">);</span>
+
+<span class="kt">int</span> <span class="nf">lg2_log</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="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="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">printed</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">parents</span><span class="p">,</span> <span class="n">last_arg</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">log_state</span> <span class="n">s</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">log_options</span> <span class="n">opt</span><span class="p">;</span>
+ <span class="n">git_diff_options</span> <span class="n">diffopts</span> <span class="o">=</span> <span class="n">GIT_DIFF_OPTIONS_INIT</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_pathspec</span> <span class="o">*</span><span class="n">ps</span> <span class="o">=</span> <span class="nb">NULL</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>Parse arguments and set up revwalker.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">last_arg</span> <span class="o">=</span> <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">s</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</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="n">s</span><span class="p">.</span><span class="n">repo</span> <span class="o">=</span> <span class="n">repo</span><span class="p">;</span>
+
+ <span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">strings</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">argv</span><span class="p">[</span><span class="n">last_arg</span><span class="p">];</span>
+ <span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">count</span> <span class="o">=</span> <span class="n">argc</span> <span class="o">-</span> <span class="n">last_arg</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_pathspec_new-40" class="fnlink" href="../../#v1.6.2/group/pathspec/git_pathspec_new">git_pathspec_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ps</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">),</span>
+ <span class="s">&quot;Building pathspec&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">s</span><span class="p">.</span><span class="n">revisions</span><span class="p">)</span>
+ <span class="n">add_revision</span><span class="p">(</span><span class="o">&amp;</span><span class="n">s</span><span class="p">,</span> <span class="nb">NULL</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>Use the revwalker to traverse the history.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">printed</span> <span class="o">=</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(;</span> <span class="o">!</span><span class="n"><a name="git_revwalk_next-51" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_next">git_revwalk_next</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="n">s</span><span class="p">.</span><span class="n">walker</span><span class="p">);</span> <span class="n"><a name="git_commit_free-2" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">commit</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_lookup-1" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">commit</span><span class="p">,</span> <span class="n">s</span><span class="p">.</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oid</span><span class="p">),</span>
+ <span class="s">&quot;Failed to look up commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">parents</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_commit_parentcount-20" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parentcount">git_commit_parentcount</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">parents</span> <span class="o">&lt;</span> <span class="n">opt</span><span class="p">.</span><span class="n">min_parents</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opt</span><span class="p">.</span><span class="n">max_parents</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="n">parents</span> <span class="o">&gt;</span> <span class="n">opt</span><span class="p">.</span><span class="n">max_parents</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">unmatched</span> <span class="o">=</span> <span class="n">parents</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">parents</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_tree-15" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tree</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">&quot;Get tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_pathspec_match_tree-42" class="fnlink" href="../../#v1.6.2/group/pathspec/git_pathspec_match_tree">git_pathspec_match_tree</a></span><span class="p">(</span>
+ <span class="nb">NULL</span><span class="p">,</span> <span class="n">tree</span><span class="p">,</span> <span class="n">GIT_PATHSPEC_NO_MATCH_ERROR</span><span class="p">,</span> <span class="n">ps</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">unmatched</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="n"><a name="git_tree_free-55" class="fnlink" href="../../#v1.6.2/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="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">parents</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">unmatched</span> <span class="o">=</span> <span class="n">match_with_parent</span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">diffopts</span><span class="p">)</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">parents</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">match_with_parent</span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">diffopts</span><span class="p">))</span>
+ <span class="n">unmatched</span><span class="o">--</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">unmatched</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">continue</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">signature_matches</span><span class="p">(</span><span class="n"><a name="git_commit_author-13" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_author">git_commit_author</a></span><span class="p">(</span><span class="n">commit</span><span class="p">),</span> <span class="n">opt</span><span class="p">.</span><span class="n">author</span><span class="p">))</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">signature_matches</span><span class="p">(</span><span class="n"><a name="git_commit_committer-12" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_committer">git_commit_committer</a></span><span class="p">(</span><span class="n">commit</span><span class="p">),</span> <span class="n">opt</span><span class="p">.</span><span class="n">committer</span><span class="p">))</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">log_message_matches</span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="n">opt</span><span class="p">.</span><span class="n">grep</span><span class="p">))</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="o">++</span> <span class="o">&lt;</span> <span class="n">opt</span><span class="p">.</span><span class="n">skip</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opt</span><span class="p">.</span><span class="n">limit</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="n">printed</span><span class="o">++</span> <span class="o">&gt;=</span> <span class="n">opt</span><span class="p">.</span><span class="n">limit</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_commit_free-3" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">print_commit</span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opt</span><span class="p">.</span><span class="n">show_diff</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">a</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">*</span><span class="n">b</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_diff</span> <span class="o">*</span><span class="n">diff</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">parents</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_tree-16" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">b</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">&quot;Get tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">parents</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">parent</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_parent-22" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent</span><span class="p">,</span> <span class="n">commit</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="s">&quot;Get parent&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_tree-17" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">parent</span><span class="p">),</span> <span class="s">&quot;Tree for parent&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n"><a name="git_commit_free-4" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">parent</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_diff_tree_to_tree-27" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span>
+ <span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n"><a name="git_commit_owner-7" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_owner">git_commit_owner</a></span><span class="p">(</span><span class="n">commit</span><span class="p">),</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">diffopts</span><span class="p">),</span>
+ <span class="s">&quot;Diff commit with parent&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_print-30" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_print">git_diff_print</a></span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">GIT_DIFF_FORMAT_PATCH</span><span class="p">,</span> <span class="n">diff_output</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">),</span>
+ <span class="s">&quot;Displaying diff&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n"><a name="git_diff_free-25" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_free">git_diff_free</a></span><span class="p">(</span><span class="n">diff</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-56" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-57" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">b</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_pathspec_free-41" class="fnlink" href="../../#v1.6.2/group/pathspec/git_pathspec_free">git_pathspec_free</a></span><span class="p">(</span><span class="n">ps</span><span class="p">);</span>
+ <span class="n"><a name="git_revwalk_free-54" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_free">git_revwalk_free</a></span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">walker</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-10'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-10">&#182;</a>
+ </div>
+ <p>Determine if the given git_signature does not contain the filter text.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">signature_matches</span><span class="p">(</span><span class="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">sig</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filter</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">filter</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">sig</span> <span class="o">!=</span> <span class="nb">NULL</span> <span class="o">&amp;&amp;</span>
+ <span class="p">(</span><span class="n">strstr</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">filter</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">NULL</span> <span class="o">||</span>
+ <span class="n">strstr</span><span class="p">(</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">,</span> <span class="n">filter</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">))</span>
+ <span class="k">return</span> <span class="mi">1</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">int</span> <span class="nf">log_message_matches</span><span class="p">(</span><span class="k">const</span> <span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filter</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">filter</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">message</span> <span class="o">=</span> <span class="n"><a name="git_commit_message-9" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">))</span> <span class="o">!=</span> <span class="nb">NULL</span> <span class="o">&amp;&amp;</span>
+ <span class="n">strstr</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">filter</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">return</span> <span class="mi">1</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-11'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-11">&#182;</a>
+ </div>
+ <p>Push object (for hide or show) onto revwalker.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">push_rev</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">hide</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">hide</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">hide</span> <span class="o">^</span> <span class="n">hide</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>Create revwalker on demand if it doesn&#39;t already exist.</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">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revwalk_new-46" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">),</span>
+ <span class="s">&quot;Could not create revision walker&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n"><a name="git_revwalk_sorting-52" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_sorting">git_revwalk_sorting</a></span><span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</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">obj</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revwalk_push_head-49" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_push_head">git_revwalk_push_head</a></span><span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">),</span>
+ <span class="s">&quot;Could not find repository HEAD&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">hide</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revwalk_hide-50" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_hide">git_revwalk_hide</a></span><span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n"><a name="git_object_id-33" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)),</span>
+ <span class="s">&quot;Reference does not refer to a commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revwalk_push-48" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_push">git_revwalk_push</a></span><span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n"><a name="git_object_id-34" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">obj</span><span class="p">)),</span>
+ <span class="s">&quot;Reference does not refer to a commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n"><a name="git_object_free-37" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</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>Parse revision string and add revs to walker.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">add_revision</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">revstr</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_revspec</span> <span class="n">revs</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">hide</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="o">!</span><span class="n">revstr</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">push_rev</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">hide</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">if</span> <span class="p">(</span><span class="o">*</span><span class="n">revstr</span> <span class="o">==</span> <span class="sc">&#39;^&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">revs</span><span class="p">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">GIT_REVSPEC_SINGLE</span><span class="p">;</span>
+ <span class="n">hide</span> <span class="o">=</span> <span class="o">!</span><span class="n">hide</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_revparse_single-44" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">revs</span><span class="p">.</span><span class="n">from</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">revstr</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</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="n"><a name="git_revparse-45" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">revs</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">revstr</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">revs</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_SINGLE</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">push_rev</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">revs</span><span class="p">.</span><span class="n">from</span><span class="p">,</span> <span class="n">hide</span><span class="p">);</span>
+ <span class="k">else</span> <span class="p">{</span>
+ <span class="n">push_rev</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">revs</span><span class="p">.</span><span class="n">to</span><span class="p">,</span> <span class="n">hide</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">revs</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_MERGE_BASE</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_oid</span> <span class="n">base</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_merge_base-31" class="fnlink" href="../../#v1.6.2/group/merge/git_merge_base">git_merge_base</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">base</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span>
+ <span class="n"><a name="git_object_id-35" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">revs</span><span class="p">.</span><span class="n">from</span><span class="p">),</span> <span class="n"><a name="git_object_id-36" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">revs</span><span class="p">.</span><span class="n">to</span><span class="p">)),</span>
+ <span class="s">&quot;Could not find merge base&quot;</span><span class="p">,</span> <span class="n">revstr</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_object_lookup-32" class="fnlink" href="../../#v1.6.2/group/object/git_object_lookup">git_object_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">revs</span><span class="p">.</span><span class="n">to</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">base</span><span class="p">,</span> <span class="n">GIT_OBJECT_COMMIT</span><span class="p">),</span>
+ <span class="s">&quot;Could not find merge base commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">push_rev</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">revs</span><span class="p">.</span><span class="n">to</span><span class="p">,</span> <span class="n">hide</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n">push_rev</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">revs</span><span class="p">.</span><span class="n">from</span><span class="p">,</span> <span class="o">!</span><span class="n">hide</span><span class="p">);</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-14'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-14">&#182;</a>
+ </div>
+ <p>Update revwalker with sorting mode.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">set_sorting</span><span class="p">(</span><span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">sort_mode</span><span class="p">)</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>Open repo on demand if it isn&#39;t already open.</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">s</span><span class="o">-&gt;</span><span class="n">repo</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">s</span><span class="o">-&gt;</span><span class="n">repodir</span><span class="p">)</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repodir</span> <span class="o">=</span> <span class="s">&quot;.&quot;</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-43" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repodir</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">),</span>
+ <span class="s">&quot;Could not open repository&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repodir</span><span class="p">);</span>
+ <span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-16'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-16">&#182;</a>
+ </div>
+ <p>Create revwalker on demand if it doesn&#39;t already exist.</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">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">)</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revwalk_new-47" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">),</span>
+ <span class="s">&quot;Could not create revision walker&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">sort_mode</span> <span class="o">==</span> <span class="n">GIT_SORT_REVERSE</span><span class="p">)</span>
+ <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span> <span class="o">^</span> <span class="n">GIT_SORT_REVERSE</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span> <span class="o">=</span> <span class="n">sort_mode</span> <span class="o">|</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span> <span class="o">&amp;</span> <span class="n">GIT_SORT_REVERSE</span><span class="p">);</span>
+
+ <span class="n"><a name="git_revwalk_sorting-53" class="fnlink" href="../../#v1.6.2/group/revwalk/git_revwalk_sorting">git_revwalk_sorting</a></span><span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-17'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-17">&#182;</a>
+ </div>
+ <p>Helper to format a git_time value like Git.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_time</span><span class="p">(</span><span class="k">const</span> <span class="n">git_time</span> <span class="o">*</span><span class="n">intime</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">prefix</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">sign</span><span class="p">,</span> <span class="n">out</span><span class="p">[</span><span class="mi">32</span><span class="p">];</span>
+ <span class="k">struct</span> <span class="n">tm</span> <span class="o">*</span><span class="n">intm</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">offset</span><span class="p">,</span> <span class="n">hours</span><span class="p">,</span> <span class="n">minutes</span><span class="p">;</span>
+ <span class="kt">time_t</span> <span class="n">t</span><span class="p">;</span>
+
+ <span class="n">offset</span> <span class="o">=</span> <span class="n">intime</span><span class="o">-&gt;</span><span class="n">offset</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">offset</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">sign</span> <span class="o">=</span> <span class="sc">&#39;-&#39;</span><span class="p">;</span>
+ <span class="n">offset</span> <span class="o">=</span> <span class="o">-</span><span class="n">offset</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">sign</span> <span class="o">=</span> <span class="sc">&#39;+&#39;</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">hours</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">/</span> <span class="mi">60</span><span class="p">;</span>
+ <span class="n">minutes</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">60</span><span class="p">;</span>
+
+ <span class="n">t</span> <span class="o">=</span> <span class="p">(</span><span class="kt">time_t</span><span class="p">)</span><span class="n">intime</span><span class="o">-&gt;</span><span class="n">time</span> <span class="o">+</span> <span class="p">(</span><span class="n">intime</span><span class="o">-&gt;</span><span class="n">offset</span> <span class="o">*</span> <span class="mi">60</span><span class="p">);</span>
+
+ <span class="n">intm</span> <span class="o">=</span> <span class="n">gmtime</span><span class="p">(</span><span class="o">&amp;</span><span class="n">t</span><span class="p">);</span>
+ <span class="n">strftime</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">out</span><span class="p">),</span> <span class="s">&quot;%a %b %e %T %Y&quot;</span><span class="p">,</span> <span class="n">intm</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s%s %c%02d%02d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">prefix</span><span class="p">,</span> <span class="n">out</span><span class="p">,</span> <span class="n">sign</span><span class="p">,</span> <span class="n">hours</span><span class="p">,</span> <span class="n">minutes</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-18'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-18">&#182;</a>
+ </div>
+ <p>Helper to print a commit object.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_commit</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="k">struct</span> <span class="n">log_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="n">buf</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+ <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">count</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_signature</span> <span class="o">*</span><span class="n">sig</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">scan</span><span class="p">,</span> <span class="o">*</span><span class="n">eol</span><span class="p">;</span>
+
+ <span class="n"><a name="git_oid_tostr-38" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="n"><a name="git_commit_id-6" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_id">git_commit_id</a></span><span class="p">(</span><span class="n">commit</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;commit %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">buf</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">show_log_size</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;log size %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">strlen</span><span class="p">(</span><span class="n"><a name="git_commit_message-10" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">)));</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">count</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_commit_parentcount-21" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parentcount">git_commit_parentcount</a></span><span class="p">(</span><span class="n">commit</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Merge:&quot;</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">count</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_tostr-39" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="n"><a name="git_commit_parent_id-24" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parent_id">git_commit_parent_id</a></span><span class="p">(</span><span class="n">commit</span><span class="p">,</span> <span class="n">i</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot; %s&quot;</span><span class="p">,</span> <span class="n">buf</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">sig</span> <span class="o">=</span> <span class="n"><a name="git_commit_author-14" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_author">git_commit_author</a></span><span class="p">(</span><span class="n">commit</span><span class="p">))</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Author: %s &lt;%s&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="n">sig</span><span class="o">-&gt;</span><span class="n">email</span><span class="p">);</span>
+ <span class="n">print_time</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sig</span><span class="o">-&gt;</span><span class="n">when</span><span class="p">,</span> <span class="s">&quot;Date: &quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">scan</span> <span class="o">=</span> <span class="n"><a name="git_commit_message-11" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span> <span class="n">scan</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">scan</span><span class="p">;</span> <span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">eol</span> <span class="o">=</span> <span class="n">scan</span><span class="p">;</span> <span class="o">*</span><span class="n">eol</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">eol</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="p">;</span> <span class="o">++</span><span class="n">eol</span><span class="p">)</span> <span class="cm">/* find eol */</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot; %.*s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)(</span><span class="n">eol</span> <span class="o">-</span> <span class="n">scan</span><span class="p">),</span> <span class="n">scan</span><span class="p">);</span>
+ <span class="n">scan</span> <span class="o">=</span> <span class="o">*</span><span class="n">eol</span> <span class="o">?</span> <span class="n">eol</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">:</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-19'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-19">&#182;</a>
+ </div>
+ <p>Helper to find how many files in a commit changed from its nth parent.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">match_with_parent</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">git_diff_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_commit</span> <span class="o">*</span><span class="n">parent</span><span class="p">;</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="n">b</span><span class="p">;</span>
+ <span class="n">git_diff</span> <span class="o">*</span><span class="n">diff</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">ndeltas</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_commit_parent-23" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parent</span><span class="p">,</span> <span class="n">commit</span><span class="p">,</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)</span><span class="n">i</span><span class="p">),</span> <span class="s">&quot;Get parent&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_tree-18" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">parent</span><span class="p">),</span> <span class="s">&quot;Tree for parent&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_commit_tree-19" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">b</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">&quot;Tree for commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span>
+ <span class="n"><a name="git_diff_tree_to_tree-28" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">diff</span><span class="p">,</span> <span class="n"><a name="git_commit_owner-8" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_owner">git_commit_owner</a></span><span class="p">(</span><span class="n">commit</span><span class="p">),</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">opts</span><span class="p">),</span>
+ <span class="s">&quot;Checking diff between parent and commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">ndeltas</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n"><a name="git_diff_num_deltas-29" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_num_deltas">git_diff_num_deltas</a></span><span class="p">(</span><span class="n">diff</span><span class="p">);</span>
+
+ <span class="n"><a name="git_diff_free-26" class="fnlink" href="../../#v1.6.2/group/diff/git_diff_free">git_diff_free</a></span><span class="p">(</span><span class="n">diff</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-58" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
+ <span class="n"><a name="git_tree_free-59" class="fnlink" href="../../#v1.6.2/group/tree/git_tree_free">git_tree_free</a></span><span class="p">(</span><span class="n">b</span><span class="p">);</span>
+ <span class="n"><a name="git_commit_free-5" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_free">git_commit_free</a></span><span class="p">(</span><span class="n">parent</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">ndeltas</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-20'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-20">&#182;</a>
+ </div>
+ <p>Print a usage message for the program.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">message</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="k">if</span> <span class="p">(</span><span class="n">message</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">message</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</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: log [&lt;options&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-21'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-21">&#182;</a>
+ </div>
+ <p>Parse some log command line options.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">parse_options</span><span class="p">(</span>
+ <span class="k">struct</span> <span class="n">log_state</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="k">struct</span> <span class="n">log_options</span> <span class="o">*</span><span class="n">opt</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="n">memset</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">s</span><span class="p">));</span>
+ <span class="n">s</span><span class="o">-&gt;</span><span class="n">sorting</span> <span class="o">=</span> <span class="n">GIT_SORT_TIME</span><span class="p">;</span>
+
+ <span class="n">memset</span><span class="p">(</span><span class="n">opt</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">opt</span><span class="p">));</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">max_parents</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">limit</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+
+ <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="k">const</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="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">add_revision</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>
+ <span class="n">s</span><span class="o">-&gt;</span><span class="n">revisions</span><span class="o">++</span><span class="p">;</span>
+ <span class="k">else</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-22'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-22">&#182;</a>
+ </div>
+ <p>Try failed revision parse as filename.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">break</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">match_arg_separator</span><span class="p">(</span><span class="o">&amp;</span><span class="n">args</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">break</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;--date-order&quot;</span><span class="p">))</span>
+ <span class="n">set_sorting</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">GIT_SORT_TIME</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;--topo-order&quot;</span><span class="p">))</span>
+ <span class="n">set_sorting</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">GIT_SORT_TOPOLOGICAL</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;--reverse&quot;</span><span class="p">))</span>
+ <span class="n">set_sorting</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">GIT_SORT_REVERSE</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">opt</span><span class="o">-&gt;</span><span class="n">author</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--author&quot;</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-23'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-23">&#182;</a>
+ </div>
+ <p>Found valid --author</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <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">opt</span><span class="o">-&gt;</span><span class="n">committer</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--committer&quot;</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-24'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-24">&#182;</a>
+ </div>
+ <p>Found valid --committer</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <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">opt</span><span class="o">-&gt;</span><span class="n">grep</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--grep&quot;</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-25'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-25">&#182;</a>
+ </div>
+ <p>Found valid --grep</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <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">s</span><span class="o">-&gt;</span><span class="n">repodir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-26'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-26">&#182;</a>
+ </div>
+ <p>Found git-dir.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">skip</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--skip&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-27'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-27">&#182;</a>
+ </div>
+ <p>Found valid --skip.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">limit</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--max-count&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-28'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-28">&#182;</a>
+ </div>
+ <p>Found valid --max-count.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="sc">&#39;0&#39;</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="sc">&#39;9&#39;</span><span class="p">)</span>
+ <span class="n">is_integer</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">limit</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">limit</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-n&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-29'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-29">&#182;</a>
+ </div>
+ <p>Found valid -n.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <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;--merges&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">min_parents</span> <span class="o">=</span> <span class="mi">2</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;--no-merges&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">max_parents</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;--no-min-parents&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">min_parents</span> <span class="o">=</span> <span class="mi">0</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;--no-max-parents&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">max_parents</span> <span class="o">=</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_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">max_parents</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--max-parents=&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-30'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-30">&#182;</a>
+ </div>
+ <p>Found valid --max-parents.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</span><span class="o">-&gt;</span><span class="n">min_parents</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--min-parents=&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-31'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-31">&#182;</a>
+ </div>
+ <p>Found valid --min_parents.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <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;-p&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;-u&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;--patch&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">show_diff</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;--log-size&quot;</span><span class="p">))</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">show_log_size</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Unsupported argument&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="n">args</span><span class="p">.</span><span class="n">pos</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/ls-files.html b/ex/v1.6.2/ls-files.html
new file mode 100644
index 000000000..78afe5c35
--- /dev/null
+++ b/ex/v1.6.2/ls-files.html
@@ -0,0 +1,209 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>ls-files.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>ls-files.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;ls-files&quot; example - shows how to view all files currently in the index</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the libgit2 index APIs to roughly
+simulate the output of <code>git ls-files</code>.
+<code>git ls-files</code> has many options and this currently does not show them.</p>
+
+<p><code>git ls-files</code> base command shows all paths in the index at that time.
+This includes staged and committed files, but unstaged files will not display.</p>
+
+<p>This currently supports the default behavior and the <code>--error-unmatch</code> option.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">ls_options</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">error_unmatch</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">files</span><span class="p">[</span><span class="mi">1024</span><span class="p">];</span>
+ <span class="kt">size_t</span> <span class="n">file_count</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">message</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="k">if</span> <span class="p">(</span><span class="n">message</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">message</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</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: ls-files [--error-unmatch] [--] [&lt;file&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>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">parse_options</span><span class="p">(</span><span class="k">struct</span> <span class="n">ls_options</span> <span class="o">*</span><span class="n">opts</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="kt">int</span> <span class="n">parsing_files</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
+
+ <span class="n">memset</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">ls_options</span><span class="p">));</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">)</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">argc</span><span class="p">;</span> <span class="o">++</span><span class="n">i</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">i</span><span class="p">];</span>
+
+ <span class="cm">/* if it doesn&#39;t start with a &#39;-&#39; or is after the &#39;--&#39; then it is a file */</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="o">||</span> <span class="n">parsing_files</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">parsing_files</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="cm">/* watch for overflows (just in case) */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">file_count</span> <span class="o">==</span> <span class="mi">1024</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;ls-files can only support 1024 files at this time.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">files</span><span class="p">[</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">file_count</span><span class="o">++</span><span class="p">]</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;--&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">parsing_files</span> <span class="o">=</span> <span class="mi">1</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;--error-unmatch&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">error_unmatch</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Unsupported argument&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</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">int</span> <span class="nf">print_paths</span><span class="p">(</span><span class="k">struct</span> <span class="n">ls_options</span> <span class="o">*</span><span class="n">opts</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="p">{</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_index_entry</span> <span class="o">*</span><span class="n">entry</span><span class="p">;</span>
+
+ <span class="cm">/* if there are no files explicitly listed by the user print all entries in the index */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">file_count</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">entry_count</span> <span class="o">=</span> <span class="n"><a name="git_index_entrycount-2" class="fnlink" href="../../#v1.6.2/group/index/git_index_entrycount">git_index_entrycount</a></span><span class="p">(</span><span class="n">index</span><span class="p">);</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">entry_count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">entry</span> <span class="o">=</span> <span class="n"><a name="git_index_get_byindex-3" class="fnlink" href="../../#v1.6.2/group/index/git_index_get_byindex">git_index_get_byindex</a></span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+ <span class="n">puts</span><span class="p">(</span><span class="n">entry</span><span class="o">-&gt;</span><span class="n">path</span><span class="p">);</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="cm">/* loop through the files found in the args and print them if they exist */</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">file_count</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span> <span class="o">=</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">files</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">entry</span> <span class="o">=</span> <span class="n"><a name="git_index_get_bypath-4" class="fnlink" href="../../#v1.6.2/group/index/git_index_get_bypath">git_index_get_bypath</a></span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">GIT_INDEX_STAGE_NORMAL</span><span class="p">))</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">puts</span><span class="p">(</span><span class="n">path</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="n">opts</span><span class="o">-&gt;</span><span class="n">error_unmatch</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: pathspec &#39;%s&#39; did not match any file(s) known to git.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">path</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;Did you forget to &#39;git add&#39;?</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</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="kt">int</span> <span class="nf">lg2_ls_files</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="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_index</span> <span class="o">*</span><span class="n">index</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">ls_options</span> <span class="n">opts</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</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="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_index-5" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n">print_paths</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="p">,</span> <span class="n">index</span><span class="p">);</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n"><a name="git_index_free-1" class="fnlink" href="../../#v1.6.2/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">return</span> <span class="n">error</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/ls-remote.html b/ex/v1.6.2/ls-remote.html
new file mode 100644
index 000000000..b4a99e8e5
--- /dev/null
+++ b/ex/v1.6.2/ls-remote.html
@@ -0,0 +1,153 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>ls-remote.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>ls-remote.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></span><span class="cp">#include</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">use_remote</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="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_remote</span> <span class="o">*</span><span class="n">remote</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_remote_head</span> <span class="o">**</span><span class="n">refs</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">refs_len</span><span class="p">,</span> <span class="n">i</span><span class="p">;</span>
+ <span class="n">git_remote_callbacks</span> <span class="n">callbacks</span> <span class="o">=</span> <span class="n">GIT_REMOTE_CALLBACKS_INIT</span><span class="p">;</span>
+
+ <span class="cm">/* Find the remote by name */</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_lookup-3" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_create_anonymous-2" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_create_anonymous">git_remote_create_anonymous</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+ <span class="p">}</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>Connect to the remote and call the printing function for
+each of the remote references.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">callbacks</span><span class="p">.</span><span class="n">credentials</span> <span class="o">=</span> <span class="n">cred_acquire_cb</span><span class="p">;</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_connect-6" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_connect">git_remote_connect</a></span><span class="p">(</span><span class="n">remote</span><span class="p">,</span> <span class="n">GIT_DIRECTION_FETCH</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">callbacks</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Get the list of references on the remote and print out
+their name next to what they point to.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_remote_ls-4" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_ls">git_remote_ls</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">refs</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">refs_len</span><span class="p">,</span> <span class="n">remote</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">refs_len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="n">oid</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="n"><a name="git_oid_fmt-1" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">oid</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">oid</span><span class="p">,</span> <span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">);</span>
+ <span class="p">}</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n"><a name="git_remote_free-5" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_free">git_remote_free</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="k">return</span> <span class="n">error</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>Entry point for this command</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_ls_remote</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="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="kt">int</span> <span class="n">error</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;</span> <span class="mi">2</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;usage: %s ls-remote &lt;remote&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]);</span>
+ <span class="k">return</span> <span class="n">EXIT_FAILURE</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n">use_remote</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
+
+ <span class="k">return</span> <span class="n">error</span><span class="p">;</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/merge.html b/ex/v1.6.2/merge.html
new file mode 100644
index 000000000..0da4e2969
--- /dev/null
+++ b/ex/v1.6.2/merge.html
@@ -0,0 +1,439 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>merge.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>merge.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;merge&quot; example - shows how to perform merges</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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>The following example demonstrates how to do merges with libgit2.</p>
+
+<p>It will merge whatever commit-ish you pass in into the current branch.</p>
+
+<p>Recognized options are :
+ --no-commit: don&#39;t actually commit the merge.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">merge_options</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">heads</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">heads_count</span><span class="p">;</span>
+
+ <span class="n">git_annotated_commit</span> <span class="o">**</span><span class="n">annotated</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">annotated_count</span><span class="p">;</span>
+
+ <span class="kt">int</span> <span class="nl">no_commit</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
+<span class="p">};</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_usage</span><span class="p">(</span><span class="kt">void</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;usage: merge [--no-commit] &lt;commit...&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>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">merge_options_init</span><span class="p">(</span><span class="k">struct</span> <span class="n">merge_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">memset</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">opts</span><span class="p">));</span>
+
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated_count</span> <span class="o">=</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">opts_add_refish</span><span class="p">(</span><span class="k">struct</span> <span class="n">merge_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">refish</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">sz</span><span class="p">;</span>
+
+ <span class="n">assert</span><span class="p">(</span><span class="n">opts</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">sz</span> <span class="o">=</span> <span class="o">++</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span> <span class="o">=</span> <span class="n">xrealloc</span><span class="p">((</span><span class="kt">void</span> <span class="o">*</span><span class="p">)</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">,</span> <span class="n">sz</span><span class="p">);</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">refish</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_options</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">**</span><span class="n">repo_path</span><span class="p">,</span> <span class="k">struct</span> <span class="n">merge_options</span> <span class="o">*</span><span class="n">opts</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">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+
+ <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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">curr</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">curr</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="n">opts_add_refish</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">curr</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">curr</span><span class="p">,</span> <span class="s">&quot;--no-commit&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">no_commit</span> <span class="o">=</span> <span class="mi">1</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="n">match_str_arg</span><span class="p">(</span><span class="n">repo_path</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">resolve_heads</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">struct</span> <span class="n">merge_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_annotated_commit</span> <span class="o">**</span><span class="n">annotated</span> <span class="o">=</span> <span class="n">calloc</span><span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">git_annotated_commit</span> <span class="o">*</span><span class="p">));</span>
+ <span class="kt">size_t</span> <span class="n">annotated_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">i</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n">resolve_refish</span><span class="p">(</span><span class="o">&amp;</span><span class="n">annotated</span><span class="p">[</span><span class="n">annotated_count</span><span class="o">++</span><span class="p">],</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to resolve refish %s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n"><a name="git_error_last-8" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+ <span class="n">annotated_count</span><span class="o">--</span><span class="p">;</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">annotated_count</span> <span class="o">!=</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads_count</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;unable to parse some refish</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">annotated</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated</span> <span class="o">=</span> <span class="n">annotated</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated_count</span> <span class="o">=</span> <span class="n">annotated_count</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">int</span> <span class="nf">perform_fastforward</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">const</span> <span class="n">git_oid</span> <span class="o">*</span><span class="n">target_oid</span><span class="p">,</span> <span class="kt">int</span> <span class="n">is_unborn</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_checkout_options</span> <span class="n">ff_checkout_options</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_OPTIONS_INIT</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">target_ref</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">new_target_ref</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">target</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</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">is_unborn</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">symbolic_ref</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">head_ref</span><span class="p">;</span>
+
+ <span class="cm">/* HEAD reference is unborn, lookup manually so we don&#39;t try to resolve it */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_lookup-21" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_lookup">git_reference_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">head_ref</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="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to lookup HEAD ref</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Grab the reference HEAD should be pointing to */</span>
+ <span class="n">symbolic_ref</span> <span class="o">=</span> <span class="n"><a name="git_reference_symbolic_target-24" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_symbolic_target">git_reference_symbolic_target</a></span><span class="p">(</span><span class="n">head_ref</span><span class="p">);</span>
+
+ <span class="cm">/* Create our master reference on the target OID */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_create-23" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_create">git_reference_create</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target_ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">symbolic_ref</span><span class="p">,</span> <span class="n">target_oid</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to create master reference</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_reference_free-27" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">head_ref</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="cm">/* HEAD exists, just lookup and resolve */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_repository_head-31" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_head">git_repository_head</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target_ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to get HEAD reference</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Lookup the target object */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_object_lookup-17" class="fnlink" href="../../#v1.6.2/group/object/git_object_lookup">git_object_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">target_oid</span><span class="p">,</span> <span class="n">GIT_OBJECT_COMMIT</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to lookup OID %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n"><a name="git_oid_tostr_s-19" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr_s">git_oid_tostr_s</a></span><span class="p">(</span><span class="n">target_oid</span><span class="p">));</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Checkout the result so the workdir is in the expected state */</span>
+ <span class="n">ff_checkout_options</span><span class="p">.</span><span class="n">checkout_strategy</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_SAFE</span><span class="p">;</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_checkout_tree-5" class="fnlink" href="../../#v1.6.2/group/checkout/git_checkout_tree">git_checkout_tree</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ff_checkout_options</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to checkout HEAD reference</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Move the target reference to the target OID */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_set_target-26" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_set_target">git_reference_set_target</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">new_target_ref</span><span class="p">,</span> <span class="n">target_ref</span><span class="p">,</span> <span class="n">target_oid</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</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;failed to move HEAD reference</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_reference_free-28" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">target_ref</span><span class="p">);</span>
+ <span class="n"><a name="git_reference_free-29" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">new_target_ref</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-18" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">target</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">output_conflicts</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="p">{</span>
+ <span class="n">git_index_conflict_iterator</span> <span class="o">*</span><span class="n">conflicts</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_index_entry</span> <span class="o">*</span><span class="n">ancestor</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_index_entry</span> <span class="o">*</span><span class="n">our</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_index_entry</span> <span class="o">*</span><span class="n">their</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_index_conflict_iterator_new-12" class="fnlink" href="../../#v1.6.2/group/index/git_index_conflict_iterator_new">git_index_conflict_iterator_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">conflicts</span><span class="p">,</span> <span class="n">index</span><span class="p">),</span> <span class="s">&quot;failed to create conflict iterator&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">while</span> <span class="p">((</span><span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_index_conflict_next-13" class="fnlink" href="../../#v1.6.2/group/index/git_index_conflict_next">git_index_conflict_next</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">ancestor</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">our</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">their</span><span class="p">,</span> <span class="n">conflicts</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</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;conflict: a:%s o:%s t:%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">ancestor</span> <span class="o">?</span> <span class="n">ancestor</span><span class="o">-&gt;</span><span class="nl">path</span> <span class="p">:</span> <span class="s">&quot;NULL&quot;</span><span class="p">,</span>
+ <span class="n">our</span><span class="o">-&gt;</span><span class="n">path</span> <span class="o">?</span> <span class="n">our</span><span class="o">-&gt;</span><span class="nl">path</span> <span class="p">:</span> <span class="s">&quot;NULL&quot;</span><span class="p">,</span>
+ <span class="n">their</span><span class="o">-&gt;</span><span class="n">path</span> <span class="o">?</span> <span class="n">their</span><span class="o">-&gt;</span><span class="nl">path</span> <span class="p">:</span> <span class="s">&quot;NULL&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="n">GIT_ITEROVER</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 iterating conflicts</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_index_conflict_iterator_free-14" class="fnlink" href="../../#v1.6.2/group/index/git_index_conflict_iterator_free">git_index_conflict_iterator_free</a></span><span class="p">(</span><span class="n">conflicts</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">create_merge_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="n">git_index</span> <span class="o">*</span><span class="n">index</span><span class="p">,</span> <span class="k">struct</span> <span class="n">merge_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_oid</span> <span class="n">tree_oid</span><span class="p">,</span> <span class="n">commit_oid</span><span class="p">;</span>
+ <span class="n">git_tree</span> <span class="o">*</span><span class="n">tree</span><span class="p">;</span>
+ <span class="n">git_signature</span> <span class="o">*</span><span class="n">sign</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">merge_ref</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_annotated_commit</span> <span class="o">*</span><span class="n">merge_commit</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">head_ref</span><span class="p">;</span>
+ <span class="n">git_commit</span> <span class="o">**</span><span class="n">parents</span> <span class="o">=</span> <span class="n">calloc</span><span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated_count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="p">));</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">msg_target</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">msglen</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">msg</span><span class="p">;</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</span><span class="p">;</span>
+
+ <span class="cm">/* Grab our needed references */</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_head-32" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_head">git_repository_head</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">head_ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">&quot;failed to get repo HEAD&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">resolve_refish</span><span class="p">(</span><span class="o">&amp;</span><span class="n">merge_commit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="mi">0</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;failed to resolve refish %s&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">parents</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Maybe that&#39;s a ref, so DWIM it */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_dwim-22" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_dwim">git_reference_dwim</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">merge_ref</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">heads</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="s">&quot;failed to DWIM reference&quot;</span><span class="p">,</span> <span class="n"><a name="git_error_last-9" class="fnlink" href="../../#v1.6.2/group/error/git_error_last">git_error_last</a></span><span class="p">()</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">);</span>
+
+ <span class="cm">/* Grab a signature */</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_signature_now-36" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_now">git_signature_now</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">sign</span><span class="p">,</span> <span class="s">&quot;Me&quot;</span><span class="p">,</span> <span class="s">&quot;me@example.com&quot;</span><span class="p">),</span> <span class="s">&quot;failed to create signature&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+<span class="cp">#define MERGE_COMMIT_MSG &quot;Merge %s &#39;%s&#39;&quot;</span>
+ <span class="cm">/* Prepare a standard merge commit message */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">merge_ref</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_branch_name-4" class="fnlink" href="../../#v1.6.2/group/branch/git_branch_name">git_branch_name</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">msg_target</span><span class="p">,</span> <span class="n">merge_ref</span><span class="p">),</span> <span class="s">&quot;failed to get branch name of merged ref&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>
+ <span class="n">msg_target</span> <span class="o">=</span> <span class="n"><a name="git_oid_tostr_s-20" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr_s">git_oid_tostr_s</a></span><span class="p">(</span><span class="n"><a name="git_annotated_commit_id-1" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_id">git_annotated_commit_id</a></span><span class="p">(</span><span class="n">merge_commit</span><span class="p">));</span>
+ <span class="p">}</span>
+
+ <span class="n">msglen</span> <span class="o">=</span> <span class="n">snprintf</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">MERGE_COMMIT_MSG</span><span class="p">,</span> <span class="p">(</span><span class="n">merge_ref</span> <span class="o">?</span> <span class="s">&quot;branch&quot;</span> <span class="o">:</span> <span class="s">&quot;commit&quot;</span><span class="p">),</span> <span class="n">msg_target</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">msglen</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">msglen</span><span class="o">++</span><span class="p">;</span>
+ <span class="n">msg</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="n">msglen</span><span class="p">);</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n">snprintf</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">msglen</span><span class="p">,</span> <span class="n">MERGE_COMMIT_MSG</span><span class="p">,</span> <span class="p">(</span><span class="n">merge_ref</span> <span class="o">?</span> <span class="s">&quot;branch&quot;</span> <span class="o">:</span> <span class="s">&quot;commit&quot;</span><span class="p">),</span> <span class="n">msg_target</span><span class="p">);</span>
+
+ <span class="cm">/* This is only to silence the compiler */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+
+ <span class="cm">/* Setup our parent commits */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_reference_peel-30" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_peel">git_reference_peel</a></span><span class="p">((</span><span class="n">git_object</span> <span class="o">**</span><span class="p">)</span><span class="o">&amp;</span><span class="n">parents</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">head_ref</span><span class="p">,</span> <span class="n">GIT_OBJECT_COMMIT</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="s">&quot;failed to peel head reference&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated_count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_commit_lookup-6" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">parents</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span> <span class="n">repo</span><span class="p">,</span> <span class="n"><a name="git_annotated_commit_id-2" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_id">git_annotated_commit_id</a></span><span class="p">(</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Prepare our commit tree */</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_index_write_tree-10" class="fnlink" href="../../#v1.6.2/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_oid</span><span class="p">,</span> <span class="n">index</span><span class="p">),</span> <span class="s">&quot;failed to write merged tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tree_lookup-37" class="fnlink" href="../../#v1.6.2/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_oid</span><span class="p">),</span> <span class="s">&quot;failed to lookup tree&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="cm">/* Commit time ! */</span>
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_commit_create-7" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_create">git_commit_create</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">commit_oid</span><span class="p">,</span>
+ <span class="n">repo</span><span class="p">,</span> <span class="n"><a name="git_reference_name-25" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_name">git_reference_name</a></span><span class="p">(</span><span class="n">head_ref</span><span class="p">),</span>
+ <span class="n">sign</span><span class="p">,</span> <span class="n">sign</span><span class="p">,</span>
+ <span class="nb">NULL</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span>
+ <span class="n">tree</span><span class="p">,</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">annotated_count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="k">const</span> <span class="n">git_commit</span> <span class="o">**</span><span class="p">)</span><span class="n">parents</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="s">&quot;failed to create commit&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="cm">/* We&#39;re done merging, cleanup the repository state */</span>
+ <span class="n"><a name="git_repository_state_cleanup-34" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_state_cleanup">git_repository_state_cleanup</a></span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">parents</span><span class="p">);</span>
+ <span class="k">return</span> <span class="n">err</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="kt">int</span> <span class="nf">lg2_merge</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="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">merge_options</span> <span class="n">opts</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_repository_state_t</span> <span class="n">state</span><span class="p">;</span>
+ <span class="n">git_merge_analysis_t</span> <span class="n">analysis</span><span class="p">;</span>
+ <span class="n">git_merge_preference_t</span> <span class="n">preference</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span> <span class="o">=</span> <span class="s">&quot;.&quot;</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">err</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="n">merge_options_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">path</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</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="n">state</span> <span class="o">=</span> <span class="n"><a name="git_repository_state-35" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_state">git_repository_state</a></span><span class="p">(</span><span class="n">repo</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">!=</span> <span class="n">GIT_REPOSITORY_STATE_NONE</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;repository is in unexpected state %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">err</span> <span class="o">=</span> <span class="n">resolve_heads</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">err</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
+
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_merge_analysis-15" class="fnlink" href="../../#v1.6.2/group/merge/git_merge_analysis">git_merge_analysis</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">analysis</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">preference</span><span class="p">,</span>
+ <span class="n">repo</span><span class="p">,</span>
+ <span class="p">(</span><span class="k">const</span> <span class="n">git_annotated_commit</span> <span class="o">**</span><span class="p">)</span><span class="n">opts</span><span class="p">.</span><span class="n">annotated</span><span class="p">,</span>
+ <span class="n">opts</span><span class="p">.</span><span class="n">annotated_count</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="s">&quot;merge analysis failed&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_UP_TO_DATE</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Already up-to-date</span><span class="se">\n</span><span class="s">&quot;</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">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_UNBORN</span> <span class="o">||</span>
+ <span class="p">(</span><span class="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_FASTFORWARD</span> <span class="o">&amp;&amp;</span>
+ <span class="o">!</span><span class="p">(</span><span class="n">preference</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_PREFERENCE_NO_FASTFORWARD</span><span class="p">)))</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="n">git_oid</span> <span class="o">*</span><span class="n">target_oid</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_UNBORN</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Unborn</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Fast-forward</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* Since this is a fast-forward, there can be only one merge head */</span>
+ <span class="n">target_oid</span> <span class="o">=</span> <span class="n"><a name="git_annotated_commit_id-3" class="fnlink" href="../../#v1.6.2/group/annotated/git_annotated_commit_id">git_annotated_commit_id</a></span><span class="p">(</span><span class="n">opts</span><span class="p">.</span><span class="n">annotated</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="n">assert</span><span class="p">(</span><span class="n">opts</span><span class="p">.</span><span class="n">annotated_count</span> <span class="o">==</span> <span class="mi">1</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">perform_fastforward</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">target_oid</span><span class="p">,</span> <span class="p">(</span><span class="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_UNBORN</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="n">analysis</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_ANALYSIS_NORMAL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_merge_options</span> <span class="n">merge_opts</span> <span class="o">=</span> <span class="n">GIT_MERGE_OPTIONS_INIT</span><span class="p">;</span>
+ <span class="n">git_checkout_options</span> <span class="n">checkout_opts</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_OPTIONS_INIT</span><span class="p">;</span>
+
+ <span class="n">merge_opts</span><span class="p">.</span><span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">merge_opts</span><span class="p">.</span><span class="n">file_flags</span> <span class="o">=</span> <span class="n">GIT_MERGE_FILE_STYLE_DIFF3</span><span class="p">;</span>
+
+ <span class="n">checkout_opts</span><span class="p">.</span><span class="n">checkout_strategy</span> <span class="o">=</span> <span class="n">GIT_CHECKOUT_FORCE</span><span class="o">|</span><span class="n">GIT_CHECKOUT_ALLOW_CONFLICTS</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">preference</span> <span class="o">&amp;</span> <span class="n">GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Fast-forward is preferred, but only a merge is possible</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">err</span> <span class="o">=</span> <span class="n"><a name="git_merge-16" class="fnlink" href="../../#v1.6.2/group/merge/git_merge">git_merge</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span>
+ <span class="p">(</span><span class="k">const</span> <span class="n">git_annotated_commit</span> <span class="o">**</span><span class="p">)</span><span class="n">opts</span><span class="p">.</span><span class="n">annotated</span><span class="p">,</span> <span class="n">opts</span><span class="p">.</span><span class="n">annotated_count</span><span class="p">,</span>
+ <span class="o">&amp;</span><span class="n">merge_opts</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">checkout_opts</span><span class="p">);</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="s">&quot;merge failed&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="cm">/* If we get here, we actually performed the merge above */</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_index-33" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_index">git_repository_index</a></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="s">&quot;failed to get repository index&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_index_has_conflicts-11" class="fnlink" href="../../#v1.6.2/group/index/git_index_has_conflicts">git_index_has_conflicts</a></span><span class="p">(</span><span class="n">index</span><span class="p">))</span> <span class="p">{</span>
+ <span class="cm">/* Handle conflicts */</span>
+ <span class="n">output_conflicts</span><span class="p">(</span><span class="n">index</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">opts</span><span class="p">.</span><span class="n">no_commit</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">create_merge_commit</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Merge made</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+<span class="nl">cleanup</span><span class="p">:</span>
+ <span class="n">free</span><span class="p">((</span><span class="kt">char</span> <span class="o">**</span><span class="p">)</span><span class="n">opts</span><span class="p">.</span><span class="n">heads</span><span class="p">);</span>
+ <span class="n">free</span><span class="p">(</span><span class="n">opts</span><span class="p">.</span><span class="n">annotated</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>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/push.html b/ex/v1.6.2/push.html
new file mode 100644
index 000000000..3638f993d
--- /dev/null
+++ b/ex/v1.6.2/push.html
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>push.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>push.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;push&quot; example - shows how to push to remote</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the libgit2 push API to roughly
+simulate <code>git push</code>.</p>
+
+<p>This does not have:</p>
+
+<ul>
+<li>Robust error handling</li>
+<li>Any of the <code>git push</code> options</li>
+</ul>
+
+<p>This does have:</p>
+
+<ul>
+<li>Example of push to origin/master</li>
+</ul>
+ </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>Entry point for this command</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="kt">int</span> <span class="nf">lg2_push</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="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_push_options</span> <span class="n">options</span><span class="p">;</span>
+ <span class="n">git_remote</span><span class="o">*</span> <span class="n">remote</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">refspec</span> <span class="o">=</span> <span class="s">&quot;refs/heads/master&quot;</span><span class="p">;</span>
+ <span class="k">const</span> <span class="n">git_strarray</span> <span class="n">refspecs</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="o">&amp;</span><span class="n">refspec</span><span class="p">,</span>
+ <span class="mi">1</span>
+ <span class="p">};</span>
+
+ <span class="cm">/* Validate args */</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;USAGE: %s</span><span class="se">\n\n</span><span class="s">sorry, no arguments supported yet</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_lookup-1" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="s">&quot;origin&quot;</span> <span class="p">),</span> <span class="s">&quot;Unable to lookup remote&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_push_options_init-2" class="fnlink" href="../../#v1.6.2/group/push/git_push_options_init">git_push_options_init</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">options</span><span class="p">,</span> <span class="n">GIT_PUSH_OPTIONS_VERSION</span> <span class="p">),</span> <span class="s">&quot;Error initializing push&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_push-3" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_push">git_remote_push</a></span><span class="p">(</span><span class="n">remote</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">refspecs</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">options</span><span class="p">),</span> <span class="s">&quot;Error pushing&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;pushed</span><span class="se">\n</span><span class="s">&quot;</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>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/remote.html b/ex/v1.6.2/remote.html
new file mode 100644
index 000000000..87bf4069f
--- /dev/null
+++ b/ex/v1.6.2/remote.html
@@ -0,0 +1,334 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>remote.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>remote.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;remote&quot; example - shows how to modify remotes for a 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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 remote&quot;. See the
+documentation for that (try &quot;git help remote&quot;) to understand what this
+program is emulating.</p>
+
+<p>This demonstrates using the libgit2 APIs to modify remotes of a repository.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">enum</span> <span class="n">subcmd</span> <span class="p">{</span>
+ <span class="n">subcmd_add</span><span class="p">,</span>
+ <span class="n">subcmd_remove</span><span class="p">,</span>
+ <span class="n">subcmd_rename</span><span class="p">,</span>
+ <span class="n">subcmd_seturl</span><span class="p">,</span>
+ <span class="n">subcmd_show</span>
+<span class="p">};</span>
+
+<span class="k">struct</span> <span class="n">remote_opts</span> <span class="p">{</span>
+ <span class="k">enum</span> <span class="n">subcmd</span> <span class="n">cmd</span><span class="p">;</span>
+
+ <span class="cm">/* for command-specific args */</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">static</span> <span class="kt">int</span> <span class="nf">cmd_add</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_remove</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_rename</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_seturl</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_show</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_subcmd</span><span class="p">(</span>
+ <span class="k">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">opt</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="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">msg</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="kt">int</span> <span class="nf">lg2_remote</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="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="kt">int</span> <span class="n">retval</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">remote_opts</span> <span class="n">opt</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+
+ <span class="n">parse_subcmd</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opt</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="k">switch</span> <span class="p">(</span><span class="n">opt</span><span class="p">.</span><span class="n">cmd</span><span class="p">)</span>
+ <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">subcmd_add</span><span class="p">:</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n">cmd_add</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">subcmd_remove</span><span class="p">:</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n">cmd_remove</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">subcmd_rename</span><span class="p">:</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n">cmd_rename</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">subcmd_seturl</span><span class="p">:</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n">cmd_seturl</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">subcmd_show</span><span class="p">:</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n">cmd_show</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opt</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="n">retval</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_add</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">url</span><span class="p">;</span>
+ <span class="n">git_remote</span> <span class="o">*</span><span class="n">remote</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</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">argc</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;you need to specify a name and URL&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">name</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_create-1" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_create">git_remote_create</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">url</span><span class="p">),</span>
+ <span class="s">&quot;could not create remote&quot;</span><span class="p">,</span> <span class="nb">NULL</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">int</span> <span class="nf">cmd_remove</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">name</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">argc</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;you need to specify a name&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">name</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_delete-10" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_delete">git_remote_delete</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">),</span>
+ <span class="s">&quot;could not delete remote&quot;</span><span class="p">,</span> <span class="n">name</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">int</span> <span class="nf">cmd_rename</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">retval</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">old</span><span class="p">,</span> <span class="o">*</span><span class="n">new</span><span class="p">;</span>
+ <span class="n">git_strarray</span> <span class="n">problems</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</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">argc</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;you need to specify old and new remote name&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">old</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
+ <span class="n">new</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
+
+ <span class="n">retval</span> <span class="o">=</span> <span class="n"><a name="git_remote_rename-9" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_rename">git_remote_rename</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">problems</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">old</span><span class="p">,</span> <span class="n">new</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">retval</span><span class="p">)</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">problems</span><span class="p">.</span><span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">puts</span><span class="p">(</span><span class="n">problems</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_strarray_dispose-11" class="fnlink" href="../../#v1.6.2/group/strarray/git_strarray_dispose">git_strarray_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">problems</span><span class="p">);</span>
+
+ <span class="k">return</span> <span class="n">retval</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">cmd_seturl</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">retval</span><span class="p">,</span> <span class="n">push</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">name</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">*</span><span class="n">url</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argc</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">arg</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="n">i</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">arg</span><span class="p">,</span> <span class="s">&quot;--push&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">push</span> <span class="o">=</span> <span class="mi">1</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="n">arg</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="o">&amp;&amp;</span> <span class="n">name</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">name</span> <span class="o">=</span> <span class="n">arg</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="n">arg</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="o">&amp;&amp;</span> <span class="n">url</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="n">arg</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;invalid argument to set-url&quot;</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">name</span> <span class="o">==</span> <span class="nb">NULL</span> <span class="o">||</span> <span class="n">url</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;you need to specify remote and the new URL&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">push</span><span class="p">)</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n"><a name="git_remote_set_pushurl-6" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_set_pushurl">git_remote_set_pushurl</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">url</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">retval</span> <span class="o">=</span> <span class="n"><a name="git_remote_set_url-5" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_set_url">git_remote_set_url</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">url</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">retval</span><span class="p">,</span> <span class="s">&quot;could not set URL&quot;</span><span class="p">,</span> <span class="n">url</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">int</span> <span class="nf">cmd_show</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">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="n">i</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="o">*</span><span class="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">fetch</span><span class="p">,</span> <span class="o">*</span><span class="n">push</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">verbose</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">git_strarray</span> <span class="n">remotes</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="n">git_remote</span> <span class="o">*</span><span class="n">remote</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argc</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">arg</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">argv</span><span class="p">[</span><span class="n">i</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">arg</span><span class="p">,</span> <span class="s">&quot;-v&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">arg</span><span class="p">,</span> <span class="s">&quot;--verbose&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">verbose</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_list-8" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_list">git_remote_list</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remotes</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span>
+ <span class="s">&quot;could not retrieve remotes&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">remotes</span><span class="p">.</span><span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">name</span> <span class="o">=</span> <span class="n">remotes</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">verbose</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">puts</span><span class="p">(</span><span class="n">name</span><span class="p">);</span>
+ <span class="k">continue</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_remote_lookup-2" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">),</span>
+ <span class="s">&quot;could not look up remote&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
+
+ <span class="n">fetch</span> <span class="o">=</span> <span class="n"><a name="git_remote_url-3" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_url">git_remote_url</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">fetch</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\t</span><span class="s">%s (fetch)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">fetch</span><span class="p">);</span>
+ <span class="n">push</span> <span class="o">=</span> <span class="n"><a name="git_remote_pushurl-4" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_pushurl">git_remote_pushurl</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="cm">/* use fetch URL if no distinct push URL has been set */</span>
+ <span class="n">push</span> <span class="o">=</span> <span class="n">push</span> <span class="o">?</span> <span class="nl">push</span> <span class="p">:</span> <span class="n">fetch</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">push</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\t</span><span class="s">%s (push)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">push</span><span class="p">);</span>
+
+ <span class="n"><a name="git_remote_free-7" class="fnlink" href="../../#v1.6.2/group/remote/git_remote_free">git_remote_free</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_strarray_dispose-12" class="fnlink" href="../../#v1.6.2/group/strarray/git_strarray_dispose">git_strarray_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">remotes</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_subcmd</span><span class="p">(</span>
+ <span class="k">struct</span> <span class="n">remote_opts</span> <span class="o">*</span><span class="n">opt</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="kt">char</span> <span class="o">*</span><span class="n">arg</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
+ <span class="k">enum</span> <span class="n">subcmd</span> <span class="n">cmd</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">argc</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;no command specified&quot;</span><span class="p">,</span> <span class="nb">NULL</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">arg</span><span class="p">,</span> <span class="s">&quot;add&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">cmd</span> <span class="o">=</span> <span class="n">subcmd_add</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">arg</span><span class="p">,</span> <span class="s">&quot;remove&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">cmd</span> <span class="o">=</span> <span class="n">subcmd_remove</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">arg</span><span class="p">,</span> <span class="s">&quot;rename&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">cmd</span> <span class="o">=</span> <span class="n">subcmd_rename</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">arg</span><span class="p">,</span> <span class="s">&quot;set-url&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">cmd</span> <span class="o">=</span> <span class="n">subcmd_seturl</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">arg</span><span class="p">,</span> <span class="s">&quot;show&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">cmd</span> <span class="o">=</span> <span class="n">subcmd_show</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;command is not valid&quot;</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">cmd</span> <span class="o">=</span> <span class="n">cmd</span><span class="p">;</span>
+
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">argc</span> <span class="o">=</span> <span class="n">argc</span> <span class="o">-</span> <span class="mi">2</span><span class="p">;</span> <span class="cm">/* executable and subcommand are removed */</span>
+ <span class="n">opt</span><span class="o">-&gt;</span><span class="n">argv</span> <span class="o">=</span> <span class="n">argv</span> <span class="o">+</span> <span class="mi">2</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">msg</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">fputs</span><span class="p">(</span><span class="s">&quot;usage: remote add &lt;name&gt; &lt;url&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="s">&quot; remote remove &lt;name&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="s">&quot; remote rename &lt;old&gt; &lt;new&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="s">&quot; remote set-url [--push] &lt;name&gt; &lt;newurl&gt;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
+ <span class="n">fputs</span><span class="p">(</span><span class="s">&quot; remote show [-v|--verbose]</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="o">!</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;</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">msg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">msg</span> <span class="o">&amp;&amp;</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;</span><span class="se">\n</span><span class="s">%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">arg</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>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/rev-list.html b/ex/v1.6.2/rev-list.html
new file mode 100644
index 000000000..792c3cbf2
--- /dev/null
+++ b/ex/v1.6.2/rev-list.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>rev-list.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>rev-list.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/rev-parse.html b/ex/v1.6.2/rev-parse.html
new file mode 100644
index 000000000..695f20cce
--- /dev/null
+++ b/ex/v1.6.2/rev-parse.html
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>rev-parse.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>rev-parse.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;rev-parse&quot; example - shows how to parse revspecs</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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>Forward declarations for helpers.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">parse_state</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">repodir</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">spec</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">not</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">parse_state</span> <span class="o">*</span><span class="n">ps</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="k">static</span> <span class="kt">int</span> <span class="nf">parse_revision</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">struct</span> <span class="n">parse_state</span> <span class="o">*</span><span class="n">ps</span><span class="p">);</span>
+
+<span class="kt">int</span> <span class="nf">lg2_rev_parse</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="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">parse_state</span> <span class="n">ps</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+
+ <span class="n">parse_opts</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ps</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="n">check_lg2</span><span class="p">(</span><span class="n">parse_revision</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ps</span><span class="p">),</span> <span class="s">&quot;Parsing&quot;</span><span class="p">,</span> <span class="nb">NULL</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">usage</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</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="k">if</span> <span class="p">(</span><span class="n">message</span> <span class="o">&amp;&amp;</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;%s: %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">arg</span><span class="p">);</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">message</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;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">message</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: rev-parse [ --option ] &lt;args&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>
+
+<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">parse_state</span> <span class="o">*</span><span class="n">ps</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">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="k">const</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="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</span><span class="p">)</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Too many specs&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</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;--not&quot;</span><span class="p">))</span>
+ <span class="n">ps</span><span class="o">-&gt;</span><span class="n">not</span> <span class="o">=</span> <span class="o">!</span><span class="n">ps</span><span class="o">-&gt;</span><span class="n">not</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">ps</span><span class="o">-&gt;</span><span class="n">repodir</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--git-dir&quot;</span><span class="p">))</span>
+ <span class="n">usage</span><span class="p">(</span><span class="s">&quot;Cannot handle argument&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">parse_revision</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">struct</span> <span class="n">parse_state</span> <span class="o">*</span><span class="n">ps</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">git_revspec</span> <span class="n">rs</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">str</span><span class="p">[</span><span class="n">GIT_OID_SHA1_HEXSIZE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse-14" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">rs</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</span><span class="p">),</span> <span class="s">&quot;Could not parse&quot;</span><span class="p">,</span> <span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">rs</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_SINGLE</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_tostr-10" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">str</span><span class="p">),</span> <span class="n"><a name="git_object_id-2" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">from</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-7" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">from</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="n">rs</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_RANGE</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n"><a name="git_oid_tostr-11" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">str</span><span class="p">),</span> <span class="n"><a name="git_object_id-3" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">to</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-8" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">to</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">((</span><span class="n">rs</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">GIT_REVSPEC_MERGE_BASE</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">git_oid</span> <span class="n">base</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_merge_base-1" class="fnlink" href="../../#v1.6.2/group/merge/git_merge_base">git_merge_base</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">base</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span>
+ <span class="n"><a name="git_object_id-4" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">from</span><span class="p">),</span> <span class="n"><a name="git_object_id-5" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">to</span><span class="p">)),</span>
+ <span class="s">&quot;Could not find merge base&quot;</span><span class="p">,</span> <span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</span><span class="p">);</span>
+
+ <span class="n"><a name="git_oid_tostr-12" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">str</span><span class="p">),</span> <span class="o">&amp;</span><span class="n">base</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_oid_tostr-13" class="fnlink" href="../../#v1.6.2/group/oid/git_oid_tostr">git_oid_tostr</a></span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">str</span><span class="p">),</span> <span class="n"><a name="git_object_id-6" class="fnlink" href="../../#v1.6.2/group/object/git_object_id">git_object_id</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">from</span><span class="p">));</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;^%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-9" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="n">from</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">else</span> <span class="p">{</span>
+ <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Invalid results from <a name="git_revparse-15" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse">git_revparse</a>&quot;</span><span class="p">,</span> <span class="n">ps</span><span class="o">-&gt;</span><span class="n">spec</span><span class="p">);</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>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/show-index.html b/ex/v1.6.2/show-index.html
new file mode 100644
index 000000000..5aceac7ac
--- /dev/null
+++ b/ex/v1.6.2/show-index.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>show-index.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>show-index.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/stash.html b/ex/v1.6.2/stash.html
new file mode 100644
index 000000000..ff0be4f06
--- /dev/null
+++ b/ex/v1.6.2/stash.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>stash.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>stash.c</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/status.html b/ex/v1.6.2/status.html
new file mode 100644
index 000000000..f5e04fe64
--- /dev/null
+++ b/ex/v1.6.2/status.html
@@ -0,0 +1,663 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>status.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>status.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;status&quot; example - shows how to use the status APIs</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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 example demonstrates the use of the libgit2 status APIs,
+particularly the <code>git_status_list</code> object, to roughly simulate the
+output of running <code>git status</code>. It serves as a simple example of
+using those APIs to get basic status information.</p>
+
+<p>This does not have:</p>
+
+<ul>
+<li>Robust error handling</li>
+<li>Colorized or paginated output formatting</li>
+</ul>
+
+<p>This does have:</p>
+
+<ul>
+<li>Examples of translating command line arguments to the status
+options settings to mimic <code>git status</code> results.</li>
+<li>A sample status formatter that matches the default &quot;long&quot; format
+from <code>git status</code></li>
+<li>A sample status formatter that matches the &quot;short&quot; format</li>
+</ul>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">enum</span> <span class="p">{</span>
+ <span class="n">FORMAT_DEFAULT</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+ <span class="n">FORMAT_LONG</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
+ <span class="n">FORMAT_SHORT</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span>
+ <span class="n">FORMAT_PORCELAIN</span> <span class="o">=</span> <span class="mi">3</span>
+<span class="p">};</span>
+
+<span class="cp">#define MAX_PATHSPEC 8</span>
+
+<span class="k">struct</span> <span class="n">status_opts</span> <span class="p">{</span>
+ <span class="n">git_status_options</span> <span class="n">statusopt</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">repodir</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">pathspec</span><span class="p">[</span><span class="n">MAX_PATHSPEC</span><span class="p">];</span>
+ <span class="kt">int</span> <span class="n">npaths</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">format</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">zterm</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">showbranch</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">showsubmod</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">repeat</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">status_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="k">static</span> <span class="kt">void</span> <span class="nf">show_branch</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="kt">int</span> <span class="n">format</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_long</span><span class="p">(</span><span class="n">git_status_list</span> <span class="o">*</span><span class="n">status</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_short</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="n">git_status_list</span> <span class="o">*</span><span class="n">status</span><span class="p">);</span>
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">print_submod</span><span class="p">(</span><span class="n">git_submodule</span> <span class="o">*</span><span class="n">sm</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">);</span>
+
+<span class="kt">int</span> <span class="nf">lg2_status</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="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_status_list</span> <span class="o">*</span><span class="n">status</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">status_opts</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span> <span class="n">GIT_STATUS_OPTIONS_INIT</span><span class="p">,</span> <span class="s">&quot;.&quot;</span> <span class="p">};</span>
+
+ <span class="n">o</span><span class="p">.</span><span class="n">statusopt</span><span class="p">.</span><span class="n">show</span> <span class="o">=</span> <span class="n">GIT_STATUS_SHOW_INDEX_AND_WORKDIR</span><span class="p">;</span>
+ <span class="n">o</span><span class="p">.</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">GIT_STATUS_OPT_INCLUDE_UNTRACKED</span> <span class="o">|</span>
+ <span class="n">GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX</span> <span class="o">|</span>
+ <span class="n">GIT_STATUS_OPT_SORT_CASE_SENSITIVELY</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="k">if</span> <span class="p">(</span><span class="n"><a name="git_repository_is_bare-5" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_is_bare">git_repository_is_bare</a></span><span class="p">(</span><span class="n">repo</span><span class="p">))</span>
+ <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Cannot report status on bare repository&quot;</span><span class="p">,</span>
+ <span class="n"><a name="git_repository_path-4" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_path">git_repository_path</a></span><span class="p">(</span><span class="n">repo</span><span class="p">));</span>
+
+<span class="nl">show_status</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">repeat</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\033</span><span class="s">[H</span><span class="se">\033</span><span class="s">[2J&quot;</span><span class="p">);</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-3'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-3">&#182;</a>
+ </div>
+ <p>Run status on the repository</p>
+
+<p>We use <code><a name="git_status_list_new-8" class="fnlink" href="../../#v1.6.2/group/status/git_status_list_new">git_status_list_new</a>()</code> to generate a list of status
+information which lets us iterate over it at our
+convenience and extract the data we want to show out of
+each entry.</p>
+
+<p>You can use <code><a name="git_status_foreach-6" class="fnlink" href="../../#v1.6.2/group/status/git_status_foreach">git_status_foreach</a>()</code> or
+<code><a name="git_status_foreach_ext-7" class="fnlink" href="../../#v1.6.2/group/status/git_status_foreach_ext">git_status_foreach_ext</a>()</code> if you&#39;d prefer to execute a
+callback for each entry. The latter gives you more control
+about what results are presented.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_status_list_new-9" class="fnlink" href="../../#v1.6.2/group/status/git_status_list_new">git_status_list_new</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">status</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">o</span><span class="p">.</span><span class="n">statusopt</span><span class="p">),</span>
+ <span class="s">&quot;Could not get status&quot;</span><span class="p">,</span> <span class="nb">NULL</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">showbranch</span><span class="p">)</span>
+ <span class="n">show_branch</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">format</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">showsubmod</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">submod_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_submodule_foreach-19" class="fnlink" href="../../#v1.6.2/group/submodule/git_submodule_foreach">git_submodule_foreach</a></span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">print_submod</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">submod_count</span><span class="p">),</span>
+ <span class="s">&quot;Cannot iterate submodules&quot;</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">repodir</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">format</span> <span class="o">==</span> <span class="n">FORMAT_LONG</span><span class="p">)</span>
+ <span class="n">print_long</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">print_short</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">status</span><span class="p">);</span>
+
+ <span class="n"><a name="git_status_list_free-18" class="fnlink" href="../../#v1.6.2/group/status/git_status_list_free">git_status_list_free</a></span><span class="p">(</span><span class="n">status</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">repeat</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">sleep</span><span class="p">(</span><span class="n">o</span><span class="p">.</span><span class="n">repeat</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">show_status</span><span class="p">;</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-4'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-4">&#182;</a>
+ </div>
+ <p>If the user asked for the branch, let&#39;s show the short name of the
+branch.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">show_branch</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="kt">int</span> <span class="n">format</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="n">error</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">branch</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">git_reference</span> <span class="o">*</span><span class="n">head</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_head-3" class="fnlink" href="../../#v1.6.2/group/repository/git_repository_head">git_repository_head</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">head</span><span class="p">,</span> <span class="n">repo</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o">==</span> <span class="n">GIT_EUNBORNBRANCH</span> <span class="o">||</span> <span class="n">error</span> <span class="o">==</span> <span class="n">GIT_ENOTFOUND</span><span class="p">)</span>
+ <span class="n">branch</span> <span class="o">=</span> <span class="nb">NULL</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">error</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">branch</span> <span class="o">=</span> <span class="n"><a name="git_reference_shorthand-2" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_shorthand">git_reference_shorthand</a></span><span class="p">(</span><span class="n">head</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="s">&quot;failed to get current branch&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">format</span> <span class="o">==</span> <span class="n">FORMAT_LONG</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# On branch %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n">branch</span> <span class="o">?</span> <span class="nl">branch</span> <span class="p">:</span> <span class="s">&quot;Not currently on any branch.&quot;</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;## %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">branch</span> <span class="o">?</span> <span class="nl">branch</span> <span class="p">:</span> <span class="s">&quot;HEAD (no branch)&quot;</span><span class="p">);</span>
+
+ <span class="n"><a name="git_reference_free-1" class="fnlink" href="../../#v1.6.2/group/reference/git_reference_free">git_reference_free</a></span><span class="p">(</span><span class="n">head</span><span class="p">);</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>This function print out an output similar to git&#39;s status command
+in long form, including the command-line hints.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_long</span><span class="p">(</span><span class="n">git_status_list</span> <span class="o">*</span><span class="n">status</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">,</span> <span class="n">maxi</span> <span class="o">=</span> <span class="n"><a name="git_status_list_entrycount-10" class="fnlink" href="../../#v1.6.2/group/status/git_status_list_entrycount">git_status_list_entrycount</a></span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
+ <span class="k">const</span> <span class="n">git_status_entry</span> <span class="o">*</span><span class="n">s</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">header</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">changes_in_index</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">changed_in_workdir</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">rm_in_workdir</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">old_path</span><span class="p">,</span> <span class="o">*</span><span class="n">new_path</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>Print index changes.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">istatus</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-12" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_CURRENT</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_DELETED</span><span class="p">)</span>
+ <span class="n">rm_in_workdir</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_NEW</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="s">&quot;new file: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_MODIFIED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="s">&quot;modified: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_DELETED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="s">&quot;deleted: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_RENAMED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="s">&quot;renamed: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_TYPECHANGE</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="s">&quot;typechange:&quot;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">istatus</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# Changes to be committed:</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# (use </span><span class="se">\&quot;</span><span class="s">git reset HEAD &lt;file&gt;...</span><span class="se">\&quot;</span><span class="s"> to unstage)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">old_path</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">head_to_index</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="n">new_path</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">head_to_index</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">old_path</span> <span class="o">&amp;&amp;</span> <span class="n">new_path</span> <span class="o">&amp;&amp;</span> <span class="n">strcmp</span><span class="p">(</span><span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">))</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s %s -&gt; %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">old_path</span> <span class="o">?</span> <span class="nl">old_path</span> <span class="p">:</span> <span class="n">new_path</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">changes_in_index</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">0</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 workdir changes to tracked files.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">wstatus</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-13" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</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>With <code>GIT_STATUS_OPT_INCLUDE_UNMODIFIED</code> (not used in this example)
+<code>index_to_workdir</code> may not be <code>NULL</code> even if there are
+no differences, in which case it will be a <code>GIT_DELTA_UNMODIFIED</code>.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_CURRENT</span> <span class="o">||</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">continue</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>Print out the output since we know the file has some changes</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_MODIFIED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="s">&quot;modified: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_DELETED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="s">&quot;deleted: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_RENAMED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="s">&quot;renamed: &quot;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_TYPECHANGE</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="s">&quot;typechange:&quot;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">wstatus</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# Changes not staged for commit:</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# (use </span><span class="se">\&quot;</span><span class="s">git add%s &lt;file&gt;...</span><span class="se">\&quot;</span><span class="s"> to update what will be committed)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">rm_in_workdir</span> <span class="o">?</span> <span class="s">&quot;/rm&quot;</span> <span class="o">:</span> <span class="s">&quot;&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# (use </span><span class="se">\&quot;</span><span class="s">git checkout -- &lt;file&gt;...</span><span class="se">\&quot;</span><span class="s"> to discard changes in working directory)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">old_path</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="n">new_path</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">old_path</span> <span class="o">&amp;&amp;</span> <span class="n">new_path</span> <span class="o">&amp;&amp;</span> <span class="n">strcmp</span><span class="p">(</span><span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">))</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s %s -&gt; %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">old_path</span> <span class="o">?</span> <span class="nl">old_path</span> <span class="p">:</span> <span class="n">new_path</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">changed_in_workdir</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</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>Print untracked files.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="n">header</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-14" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_WT_NEW</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">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# Untracked files:</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# (use </span><span class="se">\&quot;</span><span class="s">git add &lt;file&gt;...</span><span class="se">\&quot;</span><span class="s"> to include in what will be committed)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">0</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>Print ignored files.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-15" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_IGNORED</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">header</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# Ignored files:</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# (use </span><span class="se">\&quot;</span><span class="s">git add -f &lt;file&gt;...</span><span class="se">\&quot;</span><span class="s"> to include in what will be committed)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="n">header</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;#</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">);</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">changes_in_index</span> <span class="o">&amp;&amp;</span> <span class="n">changed_in_workdir</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;no changes added to commit (use </span><span class="se">\&quot;</span><span class="s">git add</span><span class="se">\&quot;</span><span class="s"> and/or </span><span class="se">\&quot;</span><span class="s">git commit -a</span><span class="se">\&quot;</span><span class="s">)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</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>This version of the output prefixes each path with two status
+columns and shows submodule status information.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_short</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="n">git_status_list</span> <span class="o">*</span><span class="n">status</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">,</span> <span class="n">maxi</span> <span class="o">=</span> <span class="n"><a name="git_status_list_entrycount-11" class="fnlink" href="../../#v1.6.2/group/status/git_status_list_entrycount">git_status_list_entrycount</a></span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
+ <span class="k">const</span> <span class="n">git_status_entry</span> <span class="o">*</span><span class="n">s</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">extra</span><span class="p">,</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="n">b</span><span class="p">,</span> <span class="o">*</span><span class="n">c</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-16" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_CURRENT</span><span class="p">)</span>
+ <span class="k">continue</span><span class="p">;</span>
+
+ <span class="n">a</span> <span class="o">=</span> <span class="n">b</span> <span class="o">=</span> <span class="n">c</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">&#39; &#39;</span><span class="p">;</span>
+ <span class="n">extra</span> <span class="o">=</span> <span class="s">&quot;&quot;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_NEW</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;A&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_MODIFIED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;M&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_DELETED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;D&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_RENAMED</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;R&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_INDEX_TYPECHANGE</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;T&#39;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_NEW</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">istatus</span> <span class="o">==</span> <span class="sc">&#39; &#39;</span><span class="p">)</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;?&#39;</span><span class="p">;</span>
+ <span class="n">wstatus</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">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_MODIFIED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">&#39;M&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_DELETED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">&#39;D&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_RENAMED</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">&#39;R&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_WT_TYPECHANGE</span><span class="p">)</span>
+ <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">&#39;T&#39;</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">&amp;</span> <span class="n">GIT_STATUS_IGNORED</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">istatus</span> <span class="o">=</span> <span class="sc">&#39;!&#39;</span><span class="p">;</span>
+ <span class="n">wstatus</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">istatus</span> <span class="o">==</span> <span class="sc">&#39;?&#39;</span> <span class="o">&amp;&amp;</span> <span class="n">wstatus</span> <span class="o">==</span> <span class="sc">&#39;?&#39;</span><span class="p">)</span>
+ <span class="k">continue</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>A commit in a tree is how submodules are stored, so
+let&#39;s go take a look at its status.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span> <span class="o">&amp;&amp;</span>
+ <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">mode</span> <span class="o">==</span> <span class="n">GIT_FILEMODE_COMMIT</span><span class="p">)</span>
+ <span class="p">{</span>
+ <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">smstatus</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="o">!</span><span class="n"><a name="git_submodule_status-22" class="fnlink" href="../../#v1.6.2/group/submodule/git_submodule_status">git_submodule_status</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">smstatus</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">path</span><span class="p">,</span>
+ <span class="n">GIT_SUBMODULE_IGNORE_UNSPECIFIED</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">smstatus</span> <span class="o">&amp;</span> <span class="n">GIT_SUBMODULE_STATUS_WD_MODIFIED</span><span class="p">)</span>
+ <span class="n">extra</span> <span class="o">=</span> <span class="s">&quot; (new commits)&quot;</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">smstatus</span> <span class="o">&amp;</span> <span class="n">GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED</span><span class="p">)</span>
+ <span class="n">extra</span> <span class="o">=</span> <span class="s">&quot; (modified content)&quot;</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">smstatus</span> <span class="o">&amp;</span> <span class="n">GIT_SUBMODULE_STATUS_WD_WD_MODIFIED</span><span class="p">)</span>
+ <span class="n">extra</span> <span class="o">=</span> <span class="s">&quot; (modified content)&quot;</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">smstatus</span> <span class="o">&amp;</span> <span class="n">GIT_SUBMODULE_STATUS_WD_UNTRACKED</span><span class="p">)</span>
+ <span class="n">extra</span> <span class="o">=</span> <span class="s">&quot; (untracked content)&quot;</span><span class="p">;</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>Now that we have all the information, format the output.</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">head_to_index</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">head_to_index</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">head_to_index</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</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">a</span><span class="p">)</span>
+ <span class="n">a</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">b</span><span class="p">)</span>
+ <span class="n">b</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">new_file</span><span class="p">.</span><span class="n">path</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">istatus</span> <span class="o">==</span> <span class="sc">&#39;R&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">wstatus</span> <span class="o">==</span> <span class="sc">&#39;R&#39;</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c%c %s %s %s%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">extra</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c%c %s %s%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">extra</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">wstatus</span> <span class="o">==</span> <span class="sc">&#39;R&#39;</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c%c %s %s%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">extra</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c%c %s%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">istatus</span><span class="p">,</span> <span class="n">wstatus</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">extra</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">maxi</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">s</span> <span class="o">=</span> <span class="n"><a name="git_status_byindex-17" class="fnlink" href="../../#v1.6.2/group/status/git_status_byindex">git_status_byindex</a></span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-&gt;</span><span class="n">status</span> <span class="o">==</span> <span class="n">GIT_STATUS_WT_NEW</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;?? %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">-&gt;</span><span class="n">index_to_workdir</span><span class="o">-&gt;</span><span class="n">old_file</span><span class="p">.</span><span class="n">path</span><span class="p">);</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">print_submod</span><span class="p">(</span><span class="n">git_submodule</span> <span class="o">*</span><span class="n">sm</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">payload</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="o">*</span><span class="n">count</span> <span class="o">=</span> <span class="n">payload</span><span class="p">;</span>
+ <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">name</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">count</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# Submodules</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">(</span><span class="o">*</span><span class="n">count</span><span class="p">)</span><span class="o">++</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;# - submodule &#39;%s&#39; at %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
+ <span class="n"><a name="git_submodule_name-20" class="fnlink" href="../../#v1.6.2/group/submodule/git_submodule_name">git_submodule_name</a></span><span class="p">(</span><span class="n">sm</span><span class="p">),</span> <span class="n"><a name="git_submodule_path-21" class="fnlink" href="../../#v1.6.2/group/submodule/git_submodule_path">git_submodule_path</a></span><span class="p">(</span><span class="n">sm</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-15'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-15">&#182;</a>
+ </div>
+ <p>Parse options that git&#39;s status command supports.</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><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">status_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">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="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">npaths</span> <span class="o">&lt;</span> <span class="n">MAX_PATHSPEC</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">pathspec</span><span class="p">[</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">npaths</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">fatal</span><span class="p">(</span><span class="s">&quot;Example only supports a limited pathspec&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="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;-s&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;--short&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">FORMAT_SHORT</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;--long&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">FORMAT_LONG</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;--porcelain&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">FORMAT_PORCELAIN</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;-b&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;--branch&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">showbranch</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;-z&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">zterm</span> <span class="o">=</span> <span class="mi">1</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">format</span> <span class="o">==</span> <span class="n">FORMAT_DEFAULT</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">FORMAT_PORCELAIN</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;--ignored&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_STATUS_OPT_INCLUDE_IGNORED</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;-uno&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;--untracked-files=no&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">&amp;=</span> <span class="o">~</span><span class="n">GIT_STATUS_OPT_INCLUDE_UNTRACKED</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;-unormal&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;--untracked-files=normal&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_STATUS_OPT_INCLUDE_UNTRACKED</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;-uall&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;--untracked-files=all&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_STATUS_OPT_INCLUDE_UNTRACKED</span> <span class="o">|</span>
+ <span class="n">GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS</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;--ignore-submodules=all&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">|=</span> <span class="n">GIT_STATUS_OPT_EXCLUDE_SUBMODULES</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">strncmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">&quot;--git-dir=&quot;</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="s">&quot;--git-dir=&quot;</span><span class="p">)))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">repodir</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="n">strlen</span><span class="p">(</span><span class="s">&quot;--git-dir=&quot;</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;--repeat&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">repeat</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">o</span><span class="o">-&gt;</span><span class="n">repeat</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;--repeat&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
+ <span class="cm">/* okay */</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;--list-submodules&quot;</span><span class="p">))</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">showsubmod</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">check_lg2</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="s">&quot;Unsupported 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="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">==</span> <span class="n">FORMAT_DEFAULT</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">format</span> <span class="o">=</span> <span class="n">FORMAT_LONG</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">format</span> <span class="o">==</span> <span class="n">FORMAT_LONG</span><span class="p">)</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">showbranch</span> <span class="o">=</span> <span class="mi">1</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">npaths</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">strings</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">pathspec</span><span class="p">;</span>
+ <span class="n">o</span><span class="o">-&gt;</span><span class="n">statusopt</span><span class="p">.</span><span class="n">pathspec</span><span class="p">.</span><span class="n">count</span> <span class="o">=</span> <span class="n">o</span><span class="o">-&gt;</span><span class="n">npaths</span><span class="p">;</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
diff --git a/ex/v1.6.2/tag.html b/ex/v1.6.2/tag.html
new file mode 100644
index 000000000..205cde076
--- /dev/null
+++ b/ex/v1.6.2/tag.html
@@ -0,0 +1,512 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>tag.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="../../#v1.6.2">API Docs</a>
+ <a class="source" href="add.html">add.c</a>
+ <a class="source" href="args.html">args.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="checkout.html">checkout.c</a>
+ <a class="source" href="clone.html">clone.c</a>
+ <a class="source" href="commit.html">commit.c</a>
+ <a class="source" href="common.html">common.c</a>
+ <a class="source" href="config.html">config.c</a>
+ <a class="source" href="describe.html">describe.c</a>
+ <a class="source" href="diff.html">diff.c</a>
+ <a class="source" href="fetch.html">fetch.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="index-pack.html">index-pack.c</a>
+ <a class="source" href="init.html">init.c</a>
+ <a class="source" href="lg2.html">lg2.c</a>
+ <a class="source" href="log.html">log.c</a>
+ <a class="source" href="ls-files.html">ls-files.c</a>
+ <a class="source" href="ls-remote.html">ls-remote.c</a>
+ <a class="source" href="merge.html">merge.c</a>
+ <a class="source" href="push.html">push.c</a>
+ <a class="source" href="remote.html">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="show-index.html">show-index.c</a>
+ <a class="source" href="stash.html">stash.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>tag.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></span><span class="cm">/*</span>
+<span class="cm"> * libgit2 &quot;tag&quot; example - shows how to list, create and delete tags</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</span> <span class="cpf">&quot;common.h&quot;</span><span class="cp"></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>The following example partially reimplements the <code>git tag</code> command
+and some of its options.</p>
+
+<p>These commands should work:</p>
+
+<ul>
+<li>Tag name listing (<code>tag</code>)</li>
+<li>Filtered tag listing with messages (<code>tag -n3 -l &quot;v0.1*&quot;</code>)</li>
+<li>Lightweight tag creation (<code>tag test v0.18.0</code>)</li>
+<li>Tag creation (<code>tag -a -m &quot;Test message&quot; test v0.18.0</code>)</li>
+<li>Tag deletion (<code>tag -d test</code>)</li>
+</ul>
+
+<p>The command line parsing logic is simplified and doesn&#39;t handle
+all of the use cases.</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>tag_options represents the parsed command line options</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">struct</span> <span class="n">tag_options</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">pattern</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">tag_name</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">target</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">num_lines</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">force</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>tag_state represents the current program state for dragging around</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">typedef</span> <span class="k">struct</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">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">;</span>
+<span class="p">}</span> <span class="n">tag_state</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>An action to execute based on the command line arguments</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">typedef</span> <span class="nf">void</span> <span class="p">(</span><span class="o">*</span><span class="n">tag_action</span><span class="p">)(</span><span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">);</span>
+<span class="k">typedef</span> <span class="k">struct</span> <span class="n">args_info</span> <span class="n">args_info</span><span class="p">;</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">check</span><span class="p">(</span><span class="kt">int</span> <span class="n">result</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="n">fatal</span><span class="p">(</span><span class="n">message</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-6'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-6">&#182;</a>
+ </div>
+ <p>Tag listing: Print individual message lines</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_list_lines</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="k">const</span> <span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">msg</span> <span class="o">=</span> <span class="n">message</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">num</span> <span class="o">=</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">msg</span><span class="p">)</span> <span class="k">return</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>first line - headline</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">while</span><span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">msg</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">msg</span><span class="o">++</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>skip over new lines</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">while</span><span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="n">msg</span><span class="o">++</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</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>print just headline?</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n">num</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="n">msg</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</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>print individual commit/tag lines</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre> <span class="k">while</span> <span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="n">num</span><span class="o">--</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot; &quot;</span><span class="p">);</span>
+
+ <span class="k">while</span> <span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">msg</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%c&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">msg</span><span class="o">++</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>handle consecutive new lines</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">msg</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">&#39;\n&#39;</span> <span class="o">&amp;&amp;</span> <span class="n">msg</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">num</span><span class="o">--</span><span class="p">;</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">while</span><span class="p">(</span><span class="o">*</span><span class="n">msg</span> <span class="o">&amp;&amp;</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="n">msg</span><span class="o">++</span><span class="p">;</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</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>Tag listing: Print an actual tag object</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_tag</span><span class="p">(</span><span class="n">git_tag</span> <span class="o">*</span><span class="n">tag</span><span class="p">,</span> <span class="k">const</span> <span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%-16s&quot;</span><span class="p">,</span> <span class="n"><a name="git_tag_name-16" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_name">git_tag_name</a></span><span class="p">(</span><span class="n">tag</span><span class="p">));</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">msg</span> <span class="o">=</span> <span class="n"><a name="git_tag_message-17" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_message">git_tag_message</a></span><span class="p">(</span><span class="n">tag</span><span class="p">);</span>
+ <span class="n">print_list_lines</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
+ <span class="p">}</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>Tag listing: Print a commit (target of a lightweight tag)</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_commit</span><span class="p">(</span><span class="n">git_commit</span> <span class="o">*</span><span class="n">commit</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span>
+ <span class="k">const</span> <span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%-16s&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">msg</span> <span class="o">=</span> <span class="n"><a name="git_commit_message-2" class="fnlink" href="../../#v1.6.2/group/commit/git_commit_message">git_commit_message</a></span><span class="p">(</span><span class="n">commit</span><span class="p">);</span>
+ <span class="n">print_list_lines</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</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>Tag listing: Fallback, should not happen</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">print_name</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">);</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>Tag listing: Lookup tags based on ref name and dispatch to print</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">each_tag</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="n">tag_state</span> <span class="o">*</span><span class="n">state</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="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-9" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">),</span>
+ <span class="s">&quot;Failed to lookup rev&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
+
+ <span class="k">switch</span> <span class="p">(</span><span class="n"><a name="git_object_type-4" class="fnlink" href="../../#v1.6.2/group/object/git_object_type">git_object_type</a></span><span class="p">(</span><span class="n">obj</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_TAG</span><span class="p">:</span>
+ <span class="n">print_tag</span><span class="p">((</span><span class="n">git_tag</span> <span class="o">*</span><span class="p">)</span> <span class="n">obj</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="nl">GIT_OBJECT_COMMIT</span><span class="p">:</span>
+ <span class="n">print_commit</span><span class="p">((</span><span class="n">git_commit</span> <span class="o">*</span><span class="p">)</span> <span class="n">obj</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="n">print_name</span><span class="p">(</span><span class="n">name</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_object_free-5" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</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">action_list_tags</span><span class="p">(</span><span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">pattern</span> <span class="o">=</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">pattern</span><span class="p">;</span>
+ <span class="n">git_strarray</span> <span class="n">tag_names</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+ <span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tag_list_match-21" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_list_match">git_tag_list_match</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tag_names</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">?</span> <span class="nl">pattern</span> <span class="p">:</span> <span class="s">&quot;*&quot;</span><span class="p">,</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">),</span>
+ <span class="s">&quot;Unable to get list of tags&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="k">for</span><span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">tag_names</span><span class="p">.</span><span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">each_tag</span><span class="p">(</span><span class="n">tag_names</span><span class="p">.</span><span class="n">strings</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">state</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="n"><a name="git_strarray_dispose-15" class="fnlink" href="../../#v1.6.2/group/strarray/git_strarray_dispose">git_strarray_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tag_names</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">action_delete_tag</span><span class="p">(</span><span class="n">tag_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="k">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</span> <span class="o">=</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">obj</span><span class="p">;</span>
+ <span class="n">git_buf</span> <span class="n">abbrev_oid</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
+
+ <span class="n">check</span><span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span> <span class="s">&quot;Name required&quot;</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-10" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">obj</span><span class="p">,</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">),</span>
+ <span class="s">&quot;Failed to lookup rev&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_object_short_id-3" class="fnlink" href="../../#v1.6.2/group/object/git_object_short_id">git_object_short_id</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">abbrev_oid</span><span class="p">,</span> <span class="n">obj</span><span class="p">),</span>
+ <span class="s">&quot;Unable to get abbreviated OID&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tag_delete-20" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_delete">git_tag_delete</a></span><span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">),</span>
+ <span class="s">&quot;Unable to delete tag&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">);</span>
+
+ <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Deleted tag &#39;%s&#39; (was %s)</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span> <span class="n">abbrev_oid</span><span class="p">.</span><span class="n">ptr</span><span class="p">);</span>
+
+ <span class="n"><a name="git_buf_dispose-1" class="fnlink" href="../../#v1.6.2/group/buf/git_buf_dispose">git_buf_dispose</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">abbrev_oid</span><span class="p">);</span>
+ <span class="n"><a name="git_object_free-6" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">obj</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">action_create_lightweight_tag</span><span class="p">(</span><span class="n">tag_state</span> <span class="o">*</span><span class="n">state</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="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</span> <span class="o">=</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">target</span><span class="p">;</span>
+
+ <span class="n">check</span><span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span> <span class="s">&quot;Name required&quot;</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">)</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span> <span class="o">=</span> <span class="s">&quot;HEAD&quot;</span><span class="p">;</span>
+
+ <span class="n">check</span><span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">,</span> <span class="s">&quot;Target required&quot;</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-11" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">),</span>
+ <span class="s">&quot;Unable to resolve spec&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tag_create_lightweight-19" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_create_lightweight">git_tag_create_lightweight</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span>
+ <span class="n">target</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span><span class="p">),</span> <span class="s">&quot;Unable to create tag&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n"><a name="git_object_free-7" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">target</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">action_create_tag</span><span class="p">(</span><span class="n">tag_state</span> <span class="o">*</span><span class="n">state</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="n">state</span><span class="o">-&gt;</span><span class="n">repo</span><span class="p">;</span>
+ <span class="k">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</span> <span class="o">=</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">opts</span><span class="p">;</span>
+ <span class="n">git_signature</span> <span class="o">*</span><span class="n">tagger</span><span class="p">;</span>
+ <span class="n">git_oid</span> <span class="n">oid</span><span class="p">;</span>
+ <span class="n">git_object</span> <span class="o">*</span><span class="n">target</span><span class="p">;</span>
+
+ <span class="n">check</span><span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span> <span class="s">&quot;Name required&quot;</span><span class="p">);</span>
+ <span class="n">check</span><span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">,</span> <span class="s">&quot;Message required&quot;</span><span class="p">);</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">)</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span> <span class="o">=</span> <span class="s">&quot;HEAD&quot;</span><span class="p">;</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-12" class="fnlink" href="../../#v1.6.2/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">target</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">),</span>
+ <span class="s">&quot;Unable to resolve spec&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_signature_default-13" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_default">git_signature_default</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">tagger</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span>
+ <span class="s">&quot;Unable to create signature&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_tag_create-18" class="fnlink" href="../../#v1.6.2/group/tag/git_tag_create">git_tag_create</a></span><span class="p">(</span><span class="o">&amp;</span><span class="n">oid</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span>
+ <span class="n">target</span><span class="p">,</span> <span class="n">tagger</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">,</span> <span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span><span class="p">),</span> <span class="s">&quot;Unable to create tag&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
+
+ <span class="n"><a name="git_object_free-8" class="fnlink" href="../../#v1.6.2/group/object/git_object_free">git_object_free</a></span><span class="p">(</span><span class="n">target</span><span class="p">);</span>
+ <span class="n"><a name="git_signature_free-14" class="fnlink" href="../../#v1.6.2/group/signature/git_signature_free">git_signature_free</a></span><span class="p">(</span><span class="n">tagger</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_usage</span><span class="p">(</span><span class="kt">void</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;usage: see `git help tag`</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-16'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-16">&#182;</a>
+ </div>
+ <p>Parse command line arguments and choose action to run when done</p>
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_options</span><span class="p">(</span><span class="n">tag_action</span> <span class="o">*</span><span class="n">action</span><span class="p">,</span> <span class="k">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</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">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="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_list_tags</span><span class="p">;</span>
+
+ <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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">curr</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">curr</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="o">!</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">)</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span> <span class="o">=</span> <span class="n">curr</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">opts</span><span class="o">-&gt;</span><span class="n">target</span><span class="p">)</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span> <span class="o">=</span> <span class="n">curr</span><span class="p">;</span>
+ <span class="k">else</span>
+ <span class="n">print_usage</span><span class="p">();</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">action</span> <span class="o">!=</span> <span class="o">&amp;</span><span class="n">action_create_tag</span><span class="p">)</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_create_lightweight_tag</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">curr</span><span class="p">,</span> <span class="s">&quot;-n&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_list_tags</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">curr</span><span class="p">,</span> <span class="s">&quot;-a&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_create_tag</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">curr</span><span class="p">,</span> <span class="s">&quot;-f&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span> <span class="o">=</span> <span class="mi">1</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="n">match_int_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-n&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> <span class="p">{</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_list_tags</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="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">pattern</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-l&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_list_tags</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="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-d&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_delete_tag</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="n">match_str_arg</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="o">-&gt;</span><span class="n">message</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">args</span><span class="p">,</span> <span class="s">&quot;-m&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="o">*</span><span class="n">action</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">action_create_tag</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div>
+ </td>
+ </tr>
+ <tr id='section-17'>
+ <td class=docs>
+ <div class="pilwrap">
+ <a class="pilcrow" href="#section-17">&#182;</a>
+ </div>
+ <p>Initialize tag_options struct</p>
+
+ </td>
+ <td class=code>
+ <div class='highlight'><pre><span class="k">static</span> <span class="kt">void</span> <span class="nf">tag_options_init</span><span class="p">(</span><span class="k">struct</span> <span class="n">tag_options</span> <span class="o">*</span><span class="n">opts</span><span class="p">)</span>
+<span class="p">{</span>
+ <span class="n">memset</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">opts</span><span class="p">));</span>
+
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">message</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">pattern</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">tag_name</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">target</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">num_lines</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="n">opts</span><span class="o">-&gt;</span><span class="n">force</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="kt">int</span> <span class="nf">lg2_tag</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="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">tag_options</span> <span class="n">opts</span><span class="p">;</span>
+ <span class="n">tag_action</span> <span class="n">action</span><span class="p">;</span>
+ <span class="n">tag_state</span> <span class="n">state</span><span class="p">;</span>
+
+ <span class="n">tag_options_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">opts</span><span class="p">);</span>
+ <span class="n">parse_options</span><span class="p">(</span><span class="o">&amp;</span><span class="n">action</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">opts</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="n">state</span><span class="p">.</span><span class="n">repo</span> <span class="o">=</span> <span class="n">repo</span><span class="p">;</span>
+ <span class="n">state</span><span class="p">.</span><span class="n">opts</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">opts</span><span class="p">;</span>
+ <span class="n">action</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</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>
+ </table>
+</div>
+</body>