diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2018-03-19 18:31:38 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2018-03-19 18:31:38 +0100 |
commit | 056a4bba17cc002f9ba734a056e25a3faa4f8252 (patch) | |
tree | 24ada3b01f1609db1e7d180fd91e1efec7cc08e8 /ex/v0.26.3 | |
parent | 870476c0d2fbe657b8328faa3e7b5e12bb9c5ad6 (diff) | |
download | libgit2-056a4bba17cc002f9ba734a056e25a3faa4f8252.tar.gz |
generated docs
Diffstat (limited to 'ex/v0.26.3')
-rw-r--r-- | ex/v0.26.3/add.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/blame.html | 343 | ||||
-rw-r--r-- | ex/v0.26.3/cat-file.html | 357 | ||||
-rw-r--r-- | ex/v0.26.3/common.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/describe.html | 283 | ||||
-rw-r--r-- | ex/v0.26.3/diff.html | 476 | ||||
-rw-r--r-- | ex/v0.26.3/for-each-ref.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/general.html | 1141 | ||||
-rw-r--r-- | ex/v0.26.3/init.html | 413 | ||||
-rw-r--r-- | ex/v0.26.3/log.html | 735 | ||||
-rw-r--r-- | ex/v0.26.3/network/clone.html | 203 | ||||
-rw-r--r-- | ex/v0.26.3/network/common.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/network/fetch.html | 222 | ||||
-rw-r--r-- | ex/v0.26.3/network/git2.html | 161 | ||||
-rw-r--r-- | ex/v0.26.3/network/index-pack.html | 162 | ||||
-rw-r--r-- | ex/v0.26.3/network/ls-remote.html | 158 | ||||
-rw-r--r-- | ex/v0.26.3/remote.html | 340 | ||||
-rw-r--r-- | ex/v0.26.3/rev-list.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/rev-parse.html | 188 | ||||
-rw-r--r-- | ex/v0.26.3/showindex.html | 55 | ||||
-rw-r--r-- | ex/v0.26.3/status.html | 681 | ||||
-rw-r--r-- | ex/v0.26.3/tag.html | 514 |
22 files changed, 6707 insertions, 0 deletions
diff --git a/ex/v0.26.3/add.html b/ex/v0.26.3/add.html new file mode 100644 index 000000000..187dfaf81 --- /dev/null +++ b/ex/v0.26.3/add.html @@ -0,0 +1,55 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>add.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/blame.html b/ex/v0.26.3/blame.html new file mode 100644 index 000000000..610907948 --- /dev/null +++ b/ex/v0.26.3/blame.html @@ -0,0 +1,343 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "blame" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span> + +<span class="cp">#ifdef _MSC_VER</span> +<span class="cp">#define snprintf sprintf_s</span> +<span class="cp">#define strcasecmp strcmpi</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">¶</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">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">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[]);</span> + +<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="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="kt">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">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_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + <span class="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"><a name="git_libgit2_init-8" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">parse_opts</span><span class="p">(</span><span class="o">&</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">¶</a> + </div> + <p>Open the repository.</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_open_ext-24" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</span><span class="p">,</span> <span class="s">"."</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">"Couldn't open repository"</span><span class="p">,</span> <span class="nb">NULL</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">¶</a> + </div> + <p>The commit range comes in "commitish" 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-27" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&</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">"Couldn't parse commit spec"</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">&</span> <span class="n">GIT_REVPARSE_SINGLE</span><span class="p">)</span> <span class="p">{</span> + <span class="n"><a name="git_oid_cpy-20" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&</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="../../#v0.26.3/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-14" class="fnlink" href="../../#v0.26.3/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-21" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&</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-11" class="fnlink" href="../../#v0.26.3/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-22" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_cpy">git_oid_cpy</a></span><span class="p">(</span><span class="o">&</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-12" class="fnlink" href="../../#v0.26.3/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-15" class="fnlink" href="../../#v0.26.3/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-16" class="fnlink" href="../../#v0.26.3/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-5'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-5">¶</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="../../#v0.26.3/group/blame/git_blame_file">git_blame_file</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">blameopts</span><span class="p">),</span> <span class="s">"Blame error"</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">¶</a> + </div> + <p>Get the raw data inside the blob for output. We use the +<code>commitish: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_iszero-23" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_iszero">git_oid_iszero</a></span><span class="p">(</span><span class="o">&</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">"HEAD"</span><span class="p">);</span> + <span class="k">else</span> + <span class="n"><a name="git_oid_tostr-18" class="fnlink" href="../../#v0.26.3/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">&</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">":"</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-26" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">"Object lookup error"</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="../../#v0.26.3/group/blob/git_blob_lookup">git_blob_lookup</a></span><span class="p">(</span><span class="o">&</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-13" class="fnlink" href="../../#v0.26.3/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">"Blob lookup error"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="n"><a name="git_object_free-17" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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="../../#v0.26.3/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-7'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-7">¶</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"><</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">'\n'</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="../../#v0.26.3/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">&&</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-19" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">hunk</span><span class="o">-></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">"%s <%s>"</span><span class="p">,</span> <span class="n">hunk</span><span class="o">-></span><span class="n">final_signature</span><span class="o">-></span><span class="n">name</span><span class="p">,</span> <span class="n">hunk</span><span class="o">-></span><span class="n">final_signature</span><span class="o">-></span><span class="n">email</span><span class="p">);</span> + + <span class="n">printf</span><span class="p">(</span><span class="s">"%s ( %-30s %3d) %.*s</span><span class="se">\n</span><span class="s">"</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-8'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-8">¶</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="../../#v0.26.3/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="../../#v0.26.3/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="n"><a name="git_repository_free-25" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-9" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + <tr id='section-9'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-9">¶</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">&&</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">"%s: %s</span><span class="se">\n</span><span class="s">"</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">"%s</span><span class="se">\n</span><span class="s">"</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">"usage: blame [options] [<commit range>] <path></span><span class="se">\n</span><span class="s">"</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">"</span><span class="se">\n</span><span class="s">"</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">" <commit range> example: `HEAD~10..HEAD`, or `1234abcd`</span><span class="se">\n</span><span class="s">"</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">" -L <n,m> process only line range n-m, counting from 1</span><span class="se">\n</span><span class="s">"</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">" -M find line moves within and across files</span><span class="se">\n</span><span class="s">"</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">" -C find line copies within and across files</span><span class="se">\n</span><span class="s">"</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">" -F follow only the first parent commits</span><span class="se">\n</span><span class="s">"</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">"</span><span class="se">\n</span><span class="s">"</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-10'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-10">¶</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">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"><</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"><</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">'-'</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">&&</span> <span class="n">i</span> <span class="o"><</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">>=</span> <span class="mi">3</span><span class="p">)</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"Invalid argument set"</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">"--"</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">"-M"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-C"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-F"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-L"</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">>=</span> <span class="n">argc</span><span class="p">)</span> <span class="n">fatal</span><span class="p">(</span><span class="s">"Not enough arguments to -L"</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">"%d,%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">start_line</span><span class="p">,</span> <span class="o">&</span><span class="n">o</span><span class="o">-></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">"-L format error"</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">-></span><span class="n">commitspec</span><span class="p">)</span> <span class="n">fatal</span><span class="p">(</span><span class="s">"Only one commit spec allowed"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="n">o</span><span class="o">-></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">"Please specify a path"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="n">o</span><span class="o">-></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">/* <commitspec> <path> */</span> + <span class="n">o</span><span class="o">-></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">-></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">/* <oldcommit> <newcommit> <path> */</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">-></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">"%s..%s"</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">-></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/v0.26.3/cat-file.html b/ex/v0.26.3/cat-file.html new file mode 100644 index 000000000..8448dec07 --- /dev/null +++ b/ex/v0.26.3/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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "cat-file" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</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">-></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"><</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">'-'</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">'+'</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">"%s %s <%s> %ld %c%02d%02d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n">header</span><span class="p">,</span> <span class="n">sig</span><span class="o">-></span><span class="n">name</span><span class="p">,</span> <span class="n">sig</span><span class="o">-></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">-></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">¶</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="../../#v0.26.3/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="../../#v0.26.3/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">¶</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-41" class="fnlink" href="../../#v0.26.3/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_HEXSZ</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"><</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-42" class="fnlink" href="../../#v0.26.3/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-26" class="fnlink" href="../../#v0.26.3/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-44" class="fnlink" href="../../#v0.26.3/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">"%06o %s %s</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n"><a name="git_tree_entry_filemode-46" class="fnlink" href="../../#v0.26.3/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-18" class="fnlink" href="../../#v0.26.3/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_tree_entry_type-45" class="fnlink" href="../../#v0.26.3/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-43" class="fnlink" href="../../#v0.26.3/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">¶</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_HEXSZ</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="../../#v0.26.3/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="../../#v0.26.3/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">"tree %s</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/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"><</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-28" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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">"parent %s</span><span class="se">\n</span><span class="s">"</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">"author"</span><span class="p">,</span> <span class="n"><a name="git_commit_author-6" class="fnlink" href="../../#v0.26.3/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">"committer"</span><span class="p">,</span> <span class="n"><a name="git_commit_committer-5" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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">"</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_commit_message-4" class="fnlink" href="../../#v0.26.3/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_HEXSZ</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span> + + <span class="n"><a name="git_oid_tostr-29" class="fnlink" href="../../#v0.26.3/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-35" class="fnlink" href="../../#v0.26.3/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">"object %s</span><span class="se">\n</span><span class="s">"</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">"type %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-19" class="fnlink" href="../../#v0.26.3/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_tag_target_type-36" class="fnlink" href="../../#v0.26.3/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">"tag %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_tag_name-37" class="fnlink" href="../../#v0.26.3/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">"tagger"</span><span class="p">,</span> <span class="n"><a name="git_tag_tagger-38" class="fnlink" href="../../#v0.26.3/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-39" class="fnlink" href="../../#v0.26.3/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">"</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_tag_message-40" class="fnlink" href="../../#v0.26.3/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">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="cm">/* Forward declarations for option-parsing helper */</span> +<span class="k">struct</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">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="kt">int</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">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></pre></div> + </td> + </tr> + <tr id='section-5'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-5">¶</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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">;</span> + <span class="k">struct</span> <span class="n">opts</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span> <span class="s">"."</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_HEXSZ</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span> + + <span class="n"><a name="git_libgit2_init-10" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">parse_opts</span><span class="p">(</span><span class="o">&</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_repository_open_ext-31" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</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="nb">NULL</span><span class="p">),</span> + <span class="s">"Could not open repository"</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_revparse_single-34" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">"Could not resolve"</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_HEXSZ</span> <span class="o">+</span> <span class="mi">1</span><span class="p">];</span> + <span class="n"><a name="git_oid_tostr-30" class="fnlink" href="../../#v0.26.3/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-12" class="fnlink" href="../../#v0.26.3/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">"%s %s</span><span class="se">\n</span><span class="s">--</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n"><a name="git_object_type2string-20" class="fnlink" href="../../#v0.26.3/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_object_type-14" class="fnlink" href="../../#v0.26.3/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="n">SHOW_TYPE</span>: + <span class="n">printf</span><span class="p">(</span><span class="s">"%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-21" class="fnlink" href="../../#v0.26.3/group/object/git_object_type2string">git_object_type2string</a></span><span class="p">(</span><span class="n"><a name="git_object_type-15" class="fnlink" href="../../#v0.26.3/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="n">SHOW_SIZE</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-33" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_odb">git_repository_odb</a></span><span class="p">(</span><span class="o">&</span><span class="n">odb</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">"Could not open ODB"</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-23" class="fnlink" href="../../#v0.26.3/group/odb/git_odb_read">git_odb_read</a></span><span class="p">(</span><span class="o">&</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-13" class="fnlink" href="../../#v0.26.3/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">"Could not find obj"</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">"%ld</span><span class="se">\n</span><span class="s">"</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-25" class="fnlink" href="../../#v0.26.3/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-24" class="fnlink" href="../../#v0.26.3/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-22" class="fnlink" href="../../#v0.26.3/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="n">SHOW_NONE</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="n">SHOW_PRETTY</span>: + + <span class="k">switch</span> <span class="p">(</span><span class="n"><a name="git_object_type-16" class="fnlink" href="../../#v0.26.3/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="n">GIT_OBJ_BLOB</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="n">GIT_OBJ_COMMIT</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="n">GIT_OBJ_TREE</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="n">GIT_OBJ_TAG</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="nl">default:</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"unknown %s</span><span class="se">\n</span><span class="s">"</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-17" class="fnlink" href="../../#v0.26.3/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_repository_free-32" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-11" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + <tr id='section-6'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-6">¶</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">&&</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">"%s: %s</span><span class="se">\n</span><span class="s">"</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">"%s</span><span class="se">\n</span><span class="s">"</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">"usage: cat-file (-t | -s | -e | -p) [-v] [-q] "</span> + <span class="s">"[-h|--help] [--git-dir=<dir>] <object></span><span class="se">\n</span><span class="s">"</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">¶</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">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"><</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">'-'</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">-></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">"Only one rev should be provided"</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">-></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">"-t"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-s"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-e"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-p"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-q"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-v"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--help"</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">"-h"</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">&</span><span class="n">o</span><span class="o">-></span><span class="n">dir</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--git-dir"</span><span class="p">))</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"Unknown option"</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">-></span><span class="n">action</span> <span class="o">||</span> <span class="o">!</span><span class="n">o</span><span class="o">-></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/v0.26.3/common.html b/ex/v0.26.3/common.html new file mode 100644 index 000000000..fc0192799 --- /dev/null +++ b/ex/v0.26.3/common.html @@ -0,0 +1,55 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>common.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/describe.html b/ex/v0.26.3/describe.html new file mode 100644 index 000000000..c6dfc7066 --- /dev/null +++ b/ex/v0.26.3/describe.html @@ -0,0 +1,283 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "describe" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span> +<span class="cp">#include <assert.h></span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</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'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">¶</a> + </div> + <p>describe_options represents the parsed command line options</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="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="n">describe_options</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="o">*</span><span class="nf">xrealloc</span><span class="p">(</span><span class="kt">void</span> <span class="o">*</span><span class="n">oldp</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">newsz</span><span class="p">)</span> +<span class="p">{</span> + <span class="kt">void</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="n">realloc</span><span class="p">(</span><span class="n">oldp</span><span class="p">,</span> <span class="n">newsz</span><span class="p">);</span> + <span class="k">if</span> <span class="p">(</span><span class="n">p</span> <span class="o">==</span> <span class="nb">NULL</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">"Cannot allocate memory, exiting.</span><span class="se">\n</span><span class="s">"</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">return</span> <span class="n">p</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="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">-></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">-></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">-></span><span class="n">commits</span> <span class="o">=</span> <span class="n">xrealloc</span><span class="p">(</span><span class="n">opts</span><span class="o">-></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">-></span><span class="n">commits</span><span class="p">[</span><span class="n">opts</span><span class="o">-></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="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-8" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">"Failed to lookup rev"</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-1" class="fnlink" href="../../#v0.26.3/group/describe/git_describe_commit">git_describe_commit</a></span><span class="p">(</span><span class="o">&</span><span class="n">describe_result</span><span class="p">,</span> <span class="n">commit</span><span class="p">,</span> <span class="o">&</span><span class="n">opts</span><span class="o">-></span><span class="n">describe_options</span><span class="p">),</span> + <span class="s">"Failed to describe rev"</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-2" class="fnlink" href="../../#v0.26.3/group/describe/git_describe_workdir">git_describe_workdir</a></span><span class="p">(</span><span class="o">&</span><span class="n">describe_result</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">opts</span><span class="o">-></span><span class="n">describe_options</span><span class="p">),</span> + <span class="s">"Failed to describe workdir"</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-3" class="fnlink" href="../../#v0.26.3/group/describe/git_describe_format">git_describe_format</a></span><span class="p">(</span><span class="o">&</span><span class="n">buf</span><span class="p">,</span> <span class="n">describe_result</span><span class="p">,</span> <span class="o">&</span><span class="n">opts</span><span class="o">-></span><span class="n">format_options</span><span class="p">),</span> + <span class="s">"Failed to format describe rev"</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">"%s</span><span class="se">\n</span><span class="s">"</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="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">-></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"><</span> <span class="n">opts</span><span class="o">-></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">-></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">"usage: see `git help describe`</span><span class="se">\n</span><span class="s">"</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">¶</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="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="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"><</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">'-'</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">"--all"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">"--tags"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">"--exact-match"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">"--long"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">"--always"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">"--first-parent"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">format_options</span><span class="p">.</span><span class="n">dirty_suffix</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--dirty"</span><span class="p">,</span> <span class="s">"-dirty"</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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">format_options</span><span class="p">.</span><span class="n">abbreviated_size</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--abbrev"</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">&</span><span class="n">opts</span><span class="o">-></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">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--candidates"</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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">describe_options</span><span class="p">.</span><span class="n">pattern</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--match"</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">-></span><span class="n">commit_count</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">opts</span><span class="o">-></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">"--dirty is incompatible with commit-ishes"</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">-></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">-></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">"HEAD"</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">¶</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="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">-></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">-></span><span class="n">commit_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> + <span class="n">git_describe_init_options</span><span class="p">(</span><span class="o">&</span><span class="n">opts</span><span class="o">-></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">git_describe_init_format_options</span><span class="p">(</span><span class="o">&</span><span class="n">opts</span><span class="o">-></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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">;</span> + <span class="n">describe_options</span> <span class="n">opts</span><span class="p">;</span> + + <span class="n"><a name="git_libgit2_init-4" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-6" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</span><span class="p">,</span> <span class="s">"."</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">"Could not open repository"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n">describe_options_init</span><span class="p">(</span><span class="o">&</span><span class="n">opts</span><span class="p">);</span> + <span class="n">parse_options</span><span class="p">(</span><span class="o">&</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">&</span><span class="n">opts</span><span class="p">);</span> + + <span class="n"><a name="git_repository_free-7" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-5" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + </table> +</div> +</body> diff --git a/ex/v0.26.3/diff.html b/ex/v0.26.3/diff.html new file mode 100644 index 000000000..cfc989024 --- /dev/null +++ b/ex/v0.26.3/diff.html @@ -0,0 +1,476 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "diff" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</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'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">"</span><span class="se">\033</span><span class="s">[m"</span><span class="p">,</span> <span class="cm">/* reset */</span> + <span class="s">"</span><span class="se">\033</span><span class="s">[1m"</span><span class="p">,</span> <span class="cm">/* bold */</span> + <span class="s">"</span><span class="se">\033</span><span class="s">[31m"</span><span class="p">,</span> <span class="cm">/* red */</span> + <span class="s">"</span><span class="se">\033</span><span class="s">[32m"</span><span class="p">,</span> <span class="cm">/* green */</span> + <span class="s">"</span><span class="se">\033</span><span class="s">[36m"</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"><<</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"><<</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"><<</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"><<</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"><<</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">¶</a> + </div> + <p>The 'opts' 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">opts</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">cache</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">output</span><span class="p">;</span> + <span class="kt">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">¶</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">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">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">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">);</span> + +<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + <span class="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">opts</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="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">"."</span> + <span class="p">};</span> + + <span class="n"><a name="git_libgit2_init-13" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">parse_opts</span><span class="p">(</span><span class="o">&</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_repository_open_ext-15" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</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="nb">NULL</span><span class="p">),</span> + <span class="s">"Could not open repository"</span><span class="p">,</span> <span class="n">o</span><span class="p">.</span><span class="n">dir</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">¶</a> + </div> + <p>Possible argument patterns:</p> + +<ul> +<li><sha1> <sha2></li> +<li><sha1> --cached</li> +<li><sha1></li> +<li>--cached</li> +<li>--nocache (don't use index data in diff at all)</li> +<li>nothing</li> +</ul> + +<p>Currently ranged arguments like <sha1>..<sha2> and <sha1>...<sha2> +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">treeish1</span><span class="p">)</span> + <span class="n">treeish_to_tree</span><span class="p">(</span><span class="o">&</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">&</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">&&</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-3" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"diff trees"</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">&</span><span class="n">t1</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="s">"HEAD"</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-6" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_tree_to_workdir">git_diff_tree_to_workdir</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"diff tree to working directory"</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-4" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_tree_to_index">git_diff_tree_to_index</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"diff tree to index"</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-7" class="fnlink" href="../../#v0.26.3/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">&</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">&</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"diff tree to working directory"</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-5" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_index_to_workdir">git_diff_index_to_workdir</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">o</span><span class="p">.</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"diff index to working directory"</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">¶</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">&</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-8" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">o</span><span class="p">.</span><span class="n">findopts</span><span class="p">),</span> + <span class="s">"finding renames and copies"</span><span class="p">,</span> <span class="nb">NULL</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">¶</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">&</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">&</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">>=</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-9" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">o</span><span class="p">.</span><span class="n">color</span><span class="p">),</span> + <span class="s">"displaying diff"</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">>=</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">¶</a> + </div> + <p>Cleanup before exiting.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n"><a name="git_diff_free-2" class="fnlink" href="../../#v0.26.3/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-17" class="fnlink" href="../../#v0.26.3/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-18" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_repository_free-16" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-14" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span> + +<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">&&</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">"%s: %s</span><span class="se">\n</span><span class="s">"</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">"%s</span><span class="se">\n</span><span class="s">"</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">"usage: diff [<tree-oid> [<tree-oid>]]</span><span class="se">\n</span><span class="s">"</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">¶</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">>=</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">-></span><span class="n">origin</span><span class="p">)</span> <span class="p">{</span> + <span class="k">case</span> <span class="n">GIT_DIFF_LINE_ADDITION</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="n">GIT_DIFF_LINE_DELETION</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="n">GIT_DIFF_LINE_ADD_EOFNL</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="n">GIT_DIFF_LINE_DEL_EOFNL</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="n">GIT_DIFF_LINE_FILE_HDR</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="n">GIT_DIFF_LINE_HUNK_HDR</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="nl">default:</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">¶</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">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"><</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">'-'</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">-></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">-></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">-></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">-></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">"Only one or two tree identifiers can be provided"</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">"-p"</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">"-u"</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">"--patch"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">o</span><span class="o">-></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">-></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">"--cached"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></span><span class="n">cache</span> <span class="o">=</span> <span class="n">CACHE_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">"--nocache"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--name-only"</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">"--format=name"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--name-status"</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">"--format=name-status"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--raw"</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">"--format=raw"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--format=diff-index"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">o</span><span class="o">-></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">-></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">"--color"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--no-color"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-R"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-a"</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">"--text"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--ignore-space-at-eol"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-b"</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">"--ignore-space-change"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-w"</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">"--ignore-all-space"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--ignored"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--untracked"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--patience"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--minimal"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--stat"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--numstat"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--shortstat"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--summary"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">o</span><span class="o">-></span><span class="n">findopts</span><span class="p">.</span><span class="n">rename_threshold</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-M"</span><span class="p">)</span> <span class="o">||</span> + <span class="n">match_uint16_arg</span><span class="p">(</span> + <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">findopts</span><span class="p">.</span><span class="n">rename_threshold</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--find-renames"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">o</span><span class="o">-></span><span class="n">findopts</span><span class="p">.</span><span class="n">copy_threshold</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-C"</span><span class="p">)</span> <span class="o">||</span> + <span class="n">match_uint16_arg</span><span class="p">(</span> + <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">findopts</span><span class="p">.</span><span class="n">copy_threshold</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--find-copies"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--find-copies-harder"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-B"</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">"--break-rewrites"</span><span class="p">))</span> + <span class="cm">/* TODO: parse thresholds */</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">context_lines</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-U"</span><span class="p">)</span> <span class="o">&&</span> + <span class="o">!</span><span class="n">match_uint32_arg</span><span class="p">(</span> + <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">context_lines</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--unified"</span><span class="p">)</span> <span class="o">&&</span> + <span class="o">!</span><span class="n">match_uint32_arg</span><span class="p">(</span> + <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">interhunk_lines</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--inter-hunk-context"</span><span class="p">)</span> <span class="o">&&</span> + <span class="o">!</span><span class="n">match_uint16_arg</span><span class="p">(</span> + <span class="o">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">id_abbrev</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--abbrev"</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">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">old_prefix</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--src-prefix"</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">&</span><span class="n">o</span><span class="o">-></span><span class="n">diffopts</span><span class="p">.</span><span class="n">new_prefix</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--dst-prefix"</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">&</span><span class="n">o</span><span class="o">-></span><span class="n">dir</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--git-dir"</span><span class="p">))</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"Unknown command line argument"</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">¶</a> + </div> + <p>Display diff output with "--stat", "--numstat", or "--shortstat"</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">opts</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_CONST</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="kt">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-10" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_get_stats">git_diff_get_stats</a></span><span class="p">(</span><span class="o">&</span><span class="n">stats</span><span class="p">,</span> <span class="n">diff</span><span class="p">),</span> <span class="s">"generating stats for diff"</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">-></span><span class="n">output</span> <span class="o">&</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">-></span><span class="n">output</span> <span class="o">&</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">-></span><span class="n">output</span> <span class="o">&</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">-></span><span class="n">output</span> <span class="o">&</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-11" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_stats_to_buf">git_diff_stats_to_buf</a></span><span class="p">(</span><span class="o">&</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">"formatting stats"</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_free-1" class="fnlink" href="../../#v0.26.3/group/buf/git_buf_free">git_buf_free</a></span><span class="p">(</span><span class="o">&</span><span class="n">b</span><span class="p">);</span> + <span class="n"><a name="git_diff_stats_free-12" class="fnlink" href="../../#v0.26.3/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/v0.26.3/for-each-ref.html b/ex/v0.26.3/for-each-ref.html new file mode 100644 index 000000000..60c023a30 --- /dev/null +++ b/ex/v0.26.3/for-each-ref.html @@ -0,0 +1,55 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>for-each-ref.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/general.html b/ex/v0.26.3/general.html new file mode 100644 index 000000000..104d2f247 --- /dev/null +++ b/ex/v0.26.3/general.html @@ -0,0 +1,1141 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "general" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</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">¶</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'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></pre></div> + </td> + </tr> + <tr id='section-Includes'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-Includes">¶</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 <git2.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <string.h></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">¶</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="giterr_last-31" class="fnlink" href="../../#v0.26.3/group/giterr/giterr_last">giterr_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">"Error %d %s - %s</span><span class="se">\n</span><span class="s">"</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">&&</span> <span class="n">error</span><span class="o">-></span><span class="n">message</span><span class="p">)</span> <span class="o">?</span> <span class="n">error</span><span class="o">-></span><span class="n">message</span> <span class="o">:</span> <span class="s">"???"</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">main</span> <span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span><span class="o">**</span> <span class="n">argv</span><span class="p">)</span> +<span class="p">{</span> + <span class="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> + <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-5'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-5">¶</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-32" class="fnlink" href="../../#v0.26.3/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">¶</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">></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">"/opt/libgit2-test/.git"</span><span class="p">;</span> + + <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_open-66" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open">git_repository_open</a></span><span class="p">(</span><span class="o">&</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">"opening repository"</span><span class="p">);</span> + + <span class="n">oid_parsing</span><span class="p">(</span><span class="o">&</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">&</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">¶</a> + </div> + <p>Finally, when you'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-67" class="fnlink" href="../../#v0.26.3/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">¶</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_HEXSZ</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">"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"</span><span class="p">;</span> + + <span class="n">printf</span><span class="p">(</span><span class="s">"*Hex to Raw*</span><span class="se">\n</span><span class="s">"</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">¶</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're working with.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n"><a name="git_oid_fromstr-46" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="n">hex</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">¶</a> + </div> + <p>Once we've converted the string into the oid value, we can get the raw +value of the SHA by accessing <code>oid.id</code></p> + </td> + <td class=code> + <div class='highlight'><pre></pre></div> + </td> + </tr> + <tr id='section-11'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-11">¶</a> + </div> + <p>Next we will convert the 20 byte raw SHA1 value to a human readable 40 +char hex value.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">*Raw to Hex*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">out</span><span class="p">[</span><span class="n">GIT_OID_HEXSZ</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'\0'</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">¶</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-54" class="fnlink" href="../../#v0.26.3/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></pre></div> + </td> + </tr> + <tr id='section-13'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-13">¶</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-55" class="fnlink" href="../../#v0.26.3/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">"SHA hex string: %s</span><span class="se">\n</span><span class="s">"</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">¶</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'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_HEXSZ</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_otype</span> <span class="n">otype</span><span class="p">;</span> + + <span class="n"><a name="git_repository_odb-69" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_odb">git_repository_odb</a></span><span class="p">(</span><span class="o">&</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">¶</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">"</span><span class="se">\n</span><span class="s">*Raw Object Read*</span><span class="se">\n</span><span class="s">"</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">¶</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-40" class="fnlink" href="../../#v0.26.3/group/odb/git_odb_read">git_odb_read</a></span><span class="p">(</span><span class="o">&</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">"finding object in repository"</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">¶</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'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-43" class="fnlink" href="../../#v0.26.3/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-45" class="fnlink" href="../../#v0.26.3/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-18'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-18">¶</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-37" class="fnlink" href="../../#v0.26.3/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">"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">"</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-44" class="fnlink" href="../../#v0.26.3/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-19'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-19">¶</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-42" class="fnlink" href="../../#v0.26.3/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">¶</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">"</span><span class="se">\n</span><span class="s">*Raw Object Write*</span><span class="se">\n</span><span class="s">"</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">¶</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'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-41" class="fnlink" href="../../#v0.26.3/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">"test data"</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="s">"test data"</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">GIT_OBJ_BLOB</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">¶</a> + </div> + <p>Now that we'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-56" class="fnlink" href="../../#v0.26.3/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">"Written Object: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">oid_hex</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">¶</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-39" class="fnlink" href="../../#v0.26.3/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">¶</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'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_HEXSZ</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">"</span><span class="se">\n</span><span class="s">*Commit Writing*</span><span class="se">\n</span><span class="s">"</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">¶</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-76" class="fnlink" href="../../#v0.26.3/group/signature/git_signature_new">git_signature_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">author</span><span class="p">,</span> + <span class="s">"Scott Chacon"</span><span class="p">,</span> <span class="s">"schacon@gmail.com"</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-77" class="fnlink" href="../../#v0.26.3/group/signature/git_signature_new">git_signature_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">committer</span><span class="p">,</span> + <span class="s">"Scott A Chacon"</span><span class="p">,</span> <span class="s">"scott@github.com"</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-26'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-26">¶</a> + </div> + <p>Commit objects need a tree to point to and optionally one or more +parents. Here we'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="n"><a name="git_oid_fromstr-47" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree_id</span><span class="p">,</span> <span class="s">"f60079018b664e4e79329a7ef9559c8d9e0378d1"</span><span class="p">);</span> + <span class="n"><a name="git_tree_lookup-87" class="fnlink" href="../../#v0.26.3/group/tree/git_tree_lookup">git_tree_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">tree_id</span><span class="p">);</span> + <span class="n"><a name="git_oid_fromstr-48" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">parent_id</span><span class="p">,</span> <span class="s">"5b5b025afb0b4c913b4c338a42934a3863bf3644"</span><span class="p">);</span> + <span class="n"><a name="git_commit_lookup-6" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">parent</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">parent_id</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">¶</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="../../#v0.26.3/group/commit/git_commit_create_v">git_commit_create_v</a></span><span class="p">(</span> + <span class="o">&</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">"example commit"</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-28'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-28">¶</a> + </div> + <p>Now we can take a look at the commit SHA we've generated.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n"><a name="git_oid_fmt-57" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">commit_id</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"New Commit: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">oid_hex</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">¶</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-89" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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-78" class="fnlink" href="../../#v0.26.3/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-79" class="fnlink" href="../../#v0.26.3/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">¶</a> + </div> + <h3>Object Parsing</h3> + +<p>libgit2 has methods to parse every object type in Git so you don'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">¶</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_HEXSZ</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">"</span><span class="se">\n</span><span class="s">*Commit Parsing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + + <span class="n"><a name="git_oid_fromstr-49" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">oid</span><span class="p">,</span> <span class="s">"8496071c1b46c854b31185ea97743be6a8774479"</span><span class="p">);</span> + + <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_commit_lookup-7" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">commit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</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">"looking up commit"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-32'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-32">¶</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="../../#v0.26.3/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="../../#v0.26.3/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="../../#v0.26.3/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="../../#v0.26.3/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="../../#v0.26.3/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="../../#v0.26.3/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-33'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-33">¶</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">"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">"</span><span class="p">,</span> + <span class="n">author</span><span class="o">-></span><span class="n">name</span><span class="p">,</span> <span class="n">author</span><span class="o">-></span><span class="n">email</span><span class="p">,</span> + <span class="n">cmtter</span><span class="o">-></span><span class="n">name</span><span class="p">,</span> <span class="n">cmtter</span><span class="o">-></span><span class="n">email</span><span class="p">,</span> + <span class="n">ctime</span><span class="p">(</span><span class="o">&</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-34'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-34">¶</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'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="../../#v0.26.3/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"><</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="../../#v0.26.3/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&</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-58" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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">"Parent: %s</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/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="../../#v0.26.3/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">¶</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_otype</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">"</span><span class="se">\n</span><span class="s">*Tag Parsing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-36'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-36">¶</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="n"><a name="git_oid_fromstr-50" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">oid</span><span class="p">,</span> <span class="s">"b25fa35b38051e4ae45d4222e795f9df2e43f1d1"</span><span class="p">);</span> + + <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_tag_lookup-81" class="fnlink" href="../../#v0.26.3/group/tag/git_tag_lookup">git_tag_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">tag</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</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">"looking up tag"</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">¶</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 'commit'), the name ('v1.0'), 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-83" class="fnlink" href="../../#v0.26.3/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">&</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-85" class="fnlink" href="../../#v0.26.3/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">/* "test" */</span> + <span class="n">type</span> <span class="o">=</span> <span class="n"><a name="git_tag_target_type-84" class="fnlink" href="../../#v0.26.3/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_OBJ_COMMIT (otype enum) */</span> + <span class="n">message</span> <span class="o">=</span> <span class="n"><a name="git_tag_message-86" class="fnlink" href="../../#v0.26.3/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">/* "tag message\n" */</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"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">"</span><span class="p">,</span> + <span class="n">name</span><span class="p">,</span> <span class="n"><a name="git_object_type2string-38" class="fnlink" href="../../#v0.26.3/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-38'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-38">¶</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="../../#v0.26.3/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-82" class="fnlink" href="../../#v0.26.3/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">¶</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">"</span><span class="se">\n</span><span class="s">*Tree Parsing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-40'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-40">¶</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="n"><a name="git_oid_fromstr-51" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">oid</span><span class="p">,</span> <span class="s">"f60079018b664e4e79329a7ef9559c8d9e0378d1"</span><span class="p">);</span> + <span class="n"><a name="git_tree_lookup-88" class="fnlink" href="../../#v0.26.3/group/tree/git_tree_lookup">git_tree_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">oid</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-41'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-41">¶</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-91" class="fnlink" href="../../#v0.26.3/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">"tree entries: %d</span><span class="se">\n</span><span class="s">"</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-93" class="fnlink" href="../../#v0.26.3/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">"Entry name: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="git_tree_entry_name-94" class="fnlink" href="../../#v0.26.3/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">/* "README" */</span></pre></div> + </td> + </tr> + <tr id='section-42'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-42">¶</a> + </div> + <p>You can also access tree entries by name if you know the name of the +entry you'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-92" class="fnlink" href="../../#v0.26.3/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">"README"</span><span class="p">);</span> + <span class="n"><a name="git_tree_entry_name-95" class="fnlink" href="../../#v0.26.3/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">/* "README" */</span></pre></div> + </td> + </tr> + <tr id='section-43'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-43">¶</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-96" class="fnlink" href="../../#v0.26.3/group/tree/git_tree_entry_to_object">git_tree_entry_to_object</a></span><span class="p">(</span><span class="o">&</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-44'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-44">¶</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-36" class="fnlink" href="../../#v0.26.3/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-90" class="fnlink" href="../../#v0.26.3/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">¶</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're creating blobs you don'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'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">"</span><span class="se">\n</span><span class="s">*Blob Parsing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + + <span class="n"><a name="git_oid_fromstr-52" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">oid</span><span class="p">,</span> <span class="s">"1385f264afb75a56a5bec74243be9b367ba4ca08"</span><span class="p">);</span> + <span class="n"><a name="git_blob_lookup-1" class="fnlink" href="../../#v0.26.3/group/blob/git_blob_lookup">git_blob_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">blob</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">oid</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-46'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-46">¶</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="../../#v0.26.3/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">"Blob Size: %ld</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/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="../../#v0.26.3/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">/* "content" */</span></pre></div> + </td> + </tr> + <tr id='section-47'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-47">¶</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="../../#v0.26.3/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">¶</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">"</span><span class="se">\n</span><span class="s">*Revwalking*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + + <span class="n"><a name="git_oid_fromstr-53" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fromstr">git_oid_fromstr</a></span><span class="p">(</span><span class="o">&</span><span class="n">oid</span><span class="p">,</span> <span class="s">"5b5b025afb0b4c913b4c338a42934a3863bf3644"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-49'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-49">¶</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 'hide' 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-71" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&</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-74" class="fnlink" href="../../#v0.26.3/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-72" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">oid</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">¶</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-73" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_next">git_revwalk_next</a></span><span class="p">(</span><span class="o">&</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="../../#v0.26.3/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">wcommit</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</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">"looking up commit during revwalk"</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="../../#v0.26.3/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="../../#v0.26.3/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">"%s (%s)</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">cmsg</span><span class="p">,</span> <span class="n">cauth</span><span class="o">-></span><span class="n">email</span><span class="p">);</span> + + <span class="n"><a name="git_commit_free-13" class="fnlink" href="../../#v0.26.3/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-51'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-51">¶</a> + </div> + <p>Like the other objects, be sure to free the revwalker when you'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-75" class="fnlink" href="../../#v0.26.3/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_*">¶</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">unsigned</span> <span class="kt">int</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">"</span><span class="se">\n</span><span class="s">*Index Walking*</span><span class="se">\n</span><span class="s">"</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">¶</a> + </div> + <p>You can either open the index from the standard location in an open +repository, as we'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-70" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_index">git_repository_index</a></span><span class="p">(</span><span class="o">&</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-54'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-54">¶</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-34" class="fnlink" href="../../#v0.26.3/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"><</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-35" class="fnlink" href="../../#v0.26.3/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">"path: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">e</span><span class="o">-></span><span class="n">path</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"mtime: %d</span><span class="se">\n</span><span class="s">"</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">-></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">"fs: %d</span><span class="se">\n</span><span class="s">"</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">-></span><span class="n">file_size</span><span class="p">);</span> + <span class="p">}</span> + + <span class="n"><a name="git_index_free-33" class="fnlink" href="../../#v0.26.3/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">¶</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">"</span><span class="se">\n</span><span class="s">*Reference Listing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-56'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-56">¶</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-64" class="fnlink" href="../../#v0.26.3/group/reference/git_reference_list">git_reference_list</a></span><span class="p">(</span><span class="o">&</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"><</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_HEXSZ</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">GIT_OID_HEX_ZERO</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-60" class="fnlink" href="../../#v0.26.3/group/reference/git_reference_lookup">git_reference_lookup</a></span><span class="p">(</span><span class="o">&</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-63" class="fnlink" href="../../#v0.26.3/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="n">GIT_REF_OID</span>: + <span class="n"><a name="git_oid_fmt-59" class="fnlink" href="../../#v0.26.3/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-61" class="fnlink" href="../../#v0.26.3/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">"%s [%s]</span><span class="se">\n</span><span class="s">"</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="n">GIT_REF_SYMBOLIC</span>: + <span class="n">printf</span><span class="p">(</span><span class="s">"%s => %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">refname</span><span class="p">,</span> <span class="n"><a name="git_reference_symbolic_target-62" class="fnlink" href="../../#v0.26.3/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="nl">default:</span> + <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"Unexpected reference type</span><span class="se">\n</span><span class="s">"</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-65" class="fnlink" href="../../#v0.26.3/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_free-80" class="fnlink" href="../../#v0.26.3/group/strarray/git_strarray_free">git_strarray_free</a></span><span class="p">(</span><span class="o">&</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">¶</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 updatee 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="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">*Config Listing*</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-58'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-58">¶</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">"%s/config"</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="../../#v0.26.3/group/config/git_config_open_ondisk">git_config_open_ondisk</a></span><span class="p">(</span><span class="o">&</span><span class="n">cfg</span><span class="p">,</span> <span class="n">config_path</span><span class="p">),</span> <span class="s">"opening config"</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="../../#v0.26.3/group/config/git_config_get_int32">git_config_get_int32</a></span><span class="p">(</span><span class="o">&</span><span class="n">autocorrect</span><span class="p">,</span> <span class="n">cfg</span><span class="p">,</span> <span class="s">"help.autocorrect"</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">"Autocorrect: %d</span><span class="se">\n</span><span class="s">"</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-68" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_config_snapshot">git_repository_config_snapshot</a></span><span class="p">(</span><span class="o">&</span><span class="n">snap_cfg</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> <span class="s">"config snapshot"</span><span class="p">);</span> + <span class="n"><a name="git_config_get_string-30" class="fnlink" href="../../#v0.26.3/group/config/git_config_get_string">git_config_get_string</a></span><span class="p">(</span><span class="o">&</span><span class="n">email</span><span class="p">,</span> <span class="n">snap_cfg</span><span class="p">,</span> <span class="s">"user.email"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"Email: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">email</span><span class="p">);</span></pre></div> + </td> + </tr> + <tr id='section-59'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-59">¶</a> + </div> + <p>Remember to free the configurations after usage.</p> + + </td> + <td class=code> + <div class='highlight'><pre> <span class="n"><a name="git_config_free-27" class="fnlink" href="../../#v0.26.3/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"><a name="git_config_free-28" class="fnlink" href="../../#v0.26.3/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/v0.26.3/init.html b/ex/v0.26.3/init.html new file mode 100644 index 000000000..f44625cff --- /dev/null +++ b/ex/v0.26.3/init.html @@ -0,0 +1,413 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>init.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + <tr id='section-1'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-1">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "init" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>This is a sample program that is similar to "git init". See the +documentation for that (try "git help init") 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 "git init" +does not support which is "--initial-commit" to make a first empty commit. +That is demonstrated in the "create<em>initial</em>commit" 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">¶</a> + </div> + <p>Forward declarations of helpers</p> + </td> + <td class=code> + <div class='highlight'><pre><span class="k">struct</span> <span class="n">opts</span> <span class="p">{</span> + <span class="kt">int</span> <span class="n">no_options</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">quiet</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">bare</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">initial_commit</span><span class="p">;</span> + <span class="kt">uint32_t</span> <span class="n">shared</span><span class="p">;</span> + <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">template</span><span class="p">;</span> + <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">gitdir</span><span class="p">;</span> + <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">dir</span><span class="p">;</span> +<span class="p">};</span> +<span class="k">static</span> <span class="kt">void</span> <span class="nf">create_initial_commit</span><span class="p">(</span><span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">);</span> +<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">struct</span> <span class="n">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[]);</span> + + +<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + <span class="k">struct</span> <span class="n">opts</span> <span class="n">o</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">GIT_REPOSITORY_INIT_SHARED_UMASK</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> <span class="p">};</span> + + <span class="n"><a name="git_libgit2_init-2" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">parse_opts</span><span class="p">(</span><span class="o">&</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">¶</a> + </div> + <p>No options were specified, so let'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-7" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_init">git_repository_init</a></span><span class="p">(</span><span class="o">&</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">"Could not initialize repository"</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">¶</a> + </div> + <p>Some command line options were specified, so we'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">¶</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-8" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_init_ext">git_repository_init_ext</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">initopts</span><span class="p">),</span> + <span class="s">"Could not initialize repository"</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">¶</a> + </div> + <p>Print a message to stdout like "git init" 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-9" class="fnlink" href="../../#v0.26.3/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-10" class="fnlink" href="../../#v0.26.3/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">"Initialized empty Git repository in %s</span><span class="se">\n</span><span class="s">"</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">¶</a> + </div> + <p>As an extension to the basic "git init" 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">"Created empty initial commit</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="p">}</span> + + <span class="n"><a name="git_repository_free-6" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-3" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + <tr id='section-9'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-9">¶</a> + </div> + <p>Unlike regular "git init", 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">¶</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-12" class="fnlink" href="../../#v0.26.3/group/signature/git_signature_default">git_signature_default</a></span><span class="p">(</span><span class="o">&</span><span class="n">sig</span><span class="p">,</span> <span class="n">repo</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">fatal</span><span class="p">(</span><span class="s">"Unable to create a commit signature."</span><span class="p">,</span> + <span class="s">"Perhaps 'user.name' and 'user.email' are not set"</span><span class="p">);</span> + + <span class="cm">/* Now let'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-11" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_index">git_repository_index</a></span><span class="p">(</span><span class="o">&</span><span class="n">index</span><span class="p">,</span> <span class="n">repo</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">fatal</span><span class="p">(</span><span class="s">"Could not open repository index"</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">¶</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'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-5" class="fnlink" href="../../#v0.26.3/group/index/git_index_write_tree">git_index_write_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree_id</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">fatal</span><span class="p">(</span><span class="s">"Unable to write initial tree from index"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_index_free-4" class="fnlink" href="../../#v0.26.3/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-14" class="fnlink" href="../../#v0.26.3/group/tree/git_tree_lookup">git_tree_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">tree_id</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">fatal</span><span class="p">(</span><span class="s">"Could not look up initial tree"</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">¶</a> + </div> + <p>Ready to create the initial commit.</p> + +<p>Normally creating a commit would involve looking up the current +HEAD commit and making that be the parent of the initial commit, +but here this is the first commit so there will be no parent.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_commit_create_v-1" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_create_v">git_commit_create_v</a></span><span class="p">(</span> + <span class="o">&</span><span class="n">commit_id</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="s">"HEAD"</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">"Initial commit"</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"><</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">fatal</span><span class="p">(</span><span class="s">"Could not create the initial commit"</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">¶</a> + </div> + <p>Clean up so we don't leak memory.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n"><a name="git_tree_free-15" class="fnlink" href="../../#v0.26.3/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-13" class="fnlink" href="../../#v0.26.3/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">"error: %s '%s'</span><span class="se">\n</span><span class="s">"</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">"usage: init [-q | --quiet] [--bare] [--template=<dir>]</span><span class="se">\n</span><span class="s">"</span> + <span class="s">" [--shared[=perms]] [--initial-commit]</span><span class="se">\n</span><span class="s">"</span> + <span class="s">" [--separate-git-dir] <directory></span><span class="se">\n</span><span class="s">"</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">¶</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">"false"</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">"umask"</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">"true"</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">"group"</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">"all"</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">"world"</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">"everybody"</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">'0'</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">&</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">"invalid octal value for --shared"</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">"unknown value for --shared"</span><span class="p">,</span> <span class="n">shared</span><span class="p">);</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span> + +<span class="k">static</span> <span class="kt">void</span> <span class="nf">parse_opts</span><span class="p">(</span><span class="k">struct</span> <span class="n">opts</span> <span class="o">*</span><span class="n">o</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="k">struct</span> <span class="n">args_info</span> <span class="n">args</span> <span class="o">=</span> <span class="n">ARGS_INFO_INIT</span><span class="p">;</span> + <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">sharedarg</span><span class="p">;</span></pre></div> + </td> + </tr> + <tr id='section-15'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-15">¶</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"><</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">'-'</span><span class="p">)</span> + <span class="n">o</span><span class="o">-></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">'-'</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">-></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">"extra argument"</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span> + <span class="n">o</span><span class="o">-></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">"-q"</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">"--quiet"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--bare"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--shared"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--initial-commit"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">sharedarg</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--shared"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">o</span><span class="o">-></span><span class="n">template</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--template"</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">&</span><span class="n">o</span><span class="o">-></span><span class="n">gitdir</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--separate-git-dir"</span><span class="p">))</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"unknown option"</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">-></span><span class="n">dir</span><span class="p">)</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"must specify directory to init"</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/v0.26.3/log.html b/ex/v0.26.3/log.html new file mode 100644 index 000000000..b74c2a72d --- /dev/null +++ b/ex/v0.26.3/log.html @@ -0,0 +1,735 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "log" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</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">¶</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">¶</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">¶</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">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="kt">git_time_t</span> <span class="n">before</span><span class="p">;</span> + <span class="kt">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">¶</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">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">¶</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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="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> + + <span class="n"><a name="git_libgit2_init-30" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></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">¶</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">&</span><span class="n">s</span><span class="p">,</span> <span class="o">&</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">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">&</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">></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-41" class="fnlink" href="../../#v0.26.3/group/pathspec/git_pathspec_new">git_pathspec_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">ps</span><span class="p">,</span> <span class="o">&</span><span class="n">diffopts</span><span class="p">.</span><span class="n">pathspec</span><span class="p">),</span> + <span class="s">"Building pathspec"</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">&</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">¶</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-54" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_next">git_revwalk_next</a></span><span class="p">(</span><span class="o">&</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="../../#v0.26.3/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="../../#v0.26.3/group/commit/git_commit_lookup">git_commit_lookup</a></span><span class="p">(</span><span class="o">&</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">&</span><span class="n">oid</span><span class="p">),</span> + <span class="s">"Failed to look up commit"</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-19" class="fnlink" href="../../#v0.26.3/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"><</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">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">parents</span> <span class="o">></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">></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-14" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">tree</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">"Get tree"</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-43" class="fnlink" href="../../#v0.26.3/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-58" class="fnlink" href="../../#v0.26.3/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">&</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"><</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">&</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">></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-12" class="fnlink" href="../../#v0.26.3/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-11" class="fnlink" href="../../#v0.26.3/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"><</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">&&</span> <span class="n">printed</span><span class="o">++</span> <span class="o">>=</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="../../#v0.26.3/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="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">></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-15" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">b</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">"Get tree"</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-21" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&</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">"Get parent"</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-16" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">a</span><span class="p">,</span> <span class="n">parent</span><span class="p">),</span> <span class="s">"Tree for parent"</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="../../#v0.26.3/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-26" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span> + <span class="o">&</span><span class="n">diff</span><span class="p">,</span> <span class="n"><a name="git_commit_owner-7" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">diffopts</span><span class="p">),</span> + <span class="s">"Diff commit with parent"</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-29" class="fnlink" href="../../#v0.26.3/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">"Displaying diff"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_diff_free-24" class="fnlink" href="../../#v0.26.3/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-59" class="fnlink" href="../../#v0.26.3/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-60" class="fnlink" href="../../#v0.26.3/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-42" class="fnlink" href="../../#v0.26.3/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-57" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_repository_free-46" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_free">git_repository_free</a></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="n"><a name="git_libgit2_shutdown-31" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + <tr id='section-10'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-10">¶</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">&&</span> + <span class="p">(</span><span class="n">strstr</span><span class="p">(</span><span class="n">sig</span><span class="o">-></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">-></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="../../#v0.26.3/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">&&</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">¶</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">-></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">¶</a> + </div> + <p>Create revwalker on demand if it doesn'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">-></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-49" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">),</span> + <span class="s">"Could not create revision walker"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="n"><a name="git_revwalk_sorting-55" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_sorting">git_revwalk_sorting</a></span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-></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-52" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_push_head">git_revwalk_push_head</a></span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">),</span> + <span class="s">"Could not find repository HEAD"</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-53" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_hide">git_revwalk_hide</a></span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n"><a name="git_object_id-34" class="fnlink" href="../../#v0.26.3/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">"Reference does not refer to a commit"</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-51" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_push">git_revwalk_push</a></span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n"><a name="git_object_id-35" class="fnlink" href="../../#v0.26.3/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">"Reference does not refer to a commit"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_object_free-38" class="fnlink" href="../../#v0.26.3/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">¶</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></pre></div> + </td> + </tr> + <tr id='section-14'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-14">¶</a> + </div> + <p>Open repo on demand if it isn'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">-></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">-></span><span class="n">repodir</span><span class="p">)</span> <span class="n">s</span><span class="o">-></span><span class="n">repodir</span> <span class="o">=</span> <span class="s">"."</span><span class="p">;</span> + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-44" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">s</span><span class="o">-></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">"Could not open repository"</span><span class="p">,</span> <span class="n">s</span><span class="o">-></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="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">'^'</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_REVPARSE_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-47" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">-></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"><</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-48" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&</span><span class="n">revs</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">revstr</span><span class="p">)</span> <span class="o"><</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">&</span> <span class="n">GIT_REVPARSE_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">&</span> <span class="n">GIT_REVPARSE_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-32" class="fnlink" href="../../#v0.26.3/group/merge/git_merge_base">git_merge_base</a></span><span class="p">(</span><span class="o">&</span><span class="n">base</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> + <span class="n"><a name="git_object_id-36" class="fnlink" href="../../#v0.26.3/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-37" class="fnlink" href="../../#v0.26.3/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">"Could not find merge base"</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-33" class="fnlink" href="../../#v0.26.3/group/object/git_object_lookup">git_object_lookup</a></span><span class="p">(</span><span class="o">&</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">-></span><span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">base</span><span class="p">,</span> <span class="n">GIT_OBJ_COMMIT</span><span class="p">),</span> + <span class="s">"Could not find merge base commit"</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-15'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-15">¶</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-16'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-16">¶</a> + </div> + <p>Open repo on demand if it isn'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">-></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">-></span><span class="n">repodir</span><span class="p">)</span> <span class="n">s</span><span class="o">-></span><span class="n">repodir</span> <span class="o">=</span> <span class="s">"."</span><span class="p">;</span> + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-45" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">s</span><span class="o">-></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">"Could not open repository"</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">repodir</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">¶</a> + </div> + <p>Create revwalker on demand if it doesn'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">-></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-50" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_new">git_revwalk_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">repo</span><span class="p">),</span> + <span class="s">"Could not create revision walker"</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">-></span><span class="n">sorting</span> <span class="o">=</span> <span class="n">s</span><span class="o">-></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">-></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">-></span><span class="n">sorting</span> <span class="o">&</span> <span class="n">GIT_SORT_REVERSE</span><span class="p">);</span> + + <span class="n"><a name="git_revwalk_sorting-56" class="fnlink" href="../../#v0.26.3/group/revwalk/git_revwalk_sorting">git_revwalk_sorting</a></span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">walker</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">sorting</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">¶</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">-></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"><</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">'-'</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">'+'</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">-></span><span class="n">time</span> <span class="o">+</span> <span class="p">(</span><span class="n">intime</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">intm</span> <span class="o">=</span> <span class="n">gmtime</span><span class="p">(</span><span class="o">&</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">"%a %b %e %T %Y"</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">"%s%s %c%02d%02d</span><span class="se">\n</span><span class="s">"</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-19'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-19">¶</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="p">{</span> + <span class="kt">char</span> <span class="n">buf</span><span class="p">[</span><span class="n">GIT_OID_HEXSZ</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-39" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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">"commit %s</span><span class="se">\n</span><span class="s">"</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">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-20" class="fnlink" href="../../#v0.26.3/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">></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">"Merge:"</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"><</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-40" class="fnlink" href="../../#v0.26.3/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-23" class="fnlink" href="../../#v0.26.3/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">" %s"</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">"</span><span class="se">\n</span><span class="s">"</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-13" class="fnlink" href="../../#v0.26.3/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">"Author: %s <%s></span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">sig</span><span class="o">-></span><span class="n">name</span><span class="p">,</span> <span class="n">sig</span><span class="o">-></span><span class="n">email</span><span class="p">);</span> + <span class="n">print_time</span><span class="p">(</span><span class="o">&</span><span class="n">sig</span><span class="o">-></span><span class="n">when</span><span class="p">,</span> <span class="s">"Date: "</span><span class="p">);</span> + <span class="p">}</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</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-10" class="fnlink" href="../../#v0.26.3/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">&&</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">&&</span> <span class="o">*</span><span class="n">eol</span> <span class="o">!=</span> <span class="sc">'\n'</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">" %.*s</span><span class="se">\n</span><span class="s">"</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">"</span><span class="se">\n</span><span class="s">"</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">¶</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-22" class="fnlink" href="../../#v0.26.3/group/commit/git_commit_parent">git_commit_parent</a></span><span class="p">(</span><span class="o">&</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">"Get parent"</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="../../#v0.26.3/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">a</span><span class="p">,</span> <span class="n">parent</span><span class="p">),</span> <span class="s">"Tree for parent"</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="../../#v0.26.3/group/commit/git_commit_tree">git_commit_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">b</span><span class="p">,</span> <span class="n">commit</span><span class="p">),</span> <span class="s">"Tree for commit"</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-27" class="fnlink" href="../../#v0.26.3/group/diff/git_diff_tree_to_tree">git_diff_tree_to_tree</a></span><span class="p">(</span><span class="o">&</span><span class="n">diff</span><span class="p">,</span> <span class="n"><a name="git_commit_owner-8" class="fnlink" href="../../#v0.26.3/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">"Checking diff between parent and commit"</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-28" class="fnlink" href="../../#v0.26.3/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-25" class="fnlink" href="../../#v0.26.3/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-61" class="fnlink" href="../../#v0.26.3/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-62" class="fnlink" href="../../#v0.26.3/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="../../#v0.26.3/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">></span> <span class="mi">0</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">¶</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">&&</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">"%s: %s</span><span class="se">\n</span><span class="s">"</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">"%s</span><span class="se">\n</span><span class="s">"</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">"usage: log [<options>]</span><span class="se">\n</span><span class="s">"</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-22'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-22">¶</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">-></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">-></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">-></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"><</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">'-'</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">-></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-23'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-23">¶</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">strcmp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s">"--"</span><span class="p">))</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="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">"--date-order"</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">"--topo-order"</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">"--reverse"</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">&</span><span class="n">opt</span><span class="o">-></span><span class="n">author</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--author"</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">¶</a> + </div> + <p>Found valid --author <em>/; + else if (match<em>str</em>arg(&opt->committer, &args, "--committer")) + /</em>* Found valid --committer <em>/; + else if (match<em>str</em>arg(&opt->grep, &args, "--grep")) + /</em>* Found valid --grep <em>/; + else if (match<em>str</em>arg(&s->repodir, &args, "--git-dir")) + /</em>* Found git-dir. <em>/; + else if (match<em>int</em>arg(&opt->skip, &args, "--skip", 0)) + /</em>* Found valid --skip. <em>/; + else if (match<em>int</em>arg(&opt->limit, &args, "--max-count", 0)) + /</em>* Found valid --max-count. <em>/; + else if (a[1] >= '0' && a[1] <= '9') + is<em>integer(&opt->limit, a + 1, 0); + else if (match</em>int_arg(&opt->limit, &args, "-n", 0)) + /</em>* Found valid -n. <em>/; + else if (!strcmp(a, "--merges")) + opt->min<em>parents = 2; + else if (!strcmp(a, "--no-merges")) + opt->max</em>parents = 1; + else if (!strcmp(a, "--no-min-parents")) + opt->min<em>parents = 0; + else if (!strcmp(a, "--no-max-parents")) + opt->max</em>parents = -1; + else if (match<em>int</em>arg(&opt->max_parents, &args, "--max-parents=", 1)) + /</em>* Found valid --max-parents. <em>/; + else if (match<em>int</em>arg(&opt->min_parents, &args, "--min-parents=", 0)) + /</em>* Found valid --min<em>parents. */; + else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch")) + opt->show</em>diff = 1; + else + usage("Unsupported argument", a); + }</p> + +<pre><code>return args.pos; +</code></pre> + +<p>}</p> + + </td> + <td class=code> + <div class='highlight'><pre></pre></div> + </td> + </tr> + </table> +</div> +</body> diff --git a/ex/v0.26.3/network/clone.html b/ex/v0.26.3/network/clone.html new file mode 100644 index 000000000..5a02ee1d7 --- /dev/null +++ b/ex/v0.26.3/network/clone.html @@ -0,0 +1,203 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>clone.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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cp">#include "common.h"</span> +<span class="cp">#include <git2.h></span> +<span class="cp">#include <git2/clone.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <stdlib.h></span> +<span class="cp">#include <string.h></span> +<span class="cp">#ifndef _WIN32</span> +<span class="cp"># include <pthread.h></span> +<span class="cp"># include <unistd.h></span> +<span class="cp">#endif</span> + +<span class="k">typedef</span> <span class="k">struct</span> <span class="n">progress_data</span> <span class="p">{</span> + <span class="n">git_transfer_progress</span> <span class="n">fetch_progress</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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">;</span> +<span class="p">}</span> <span class="n">progress_data</span><span class="p">;</span> + +<span class="k">static</span> <span class="kt">void</span> <span class="nf">print_progress</span><span class="p">(</span><span class="k">const</span> <span class="n">progress_data</span> <span class="o">*</span><span class="n">pd</span><span class="p">)</span> +<span class="p">{</span> + <span class="kt">int</span> <span class="n">network_percent</span> <span class="o">=</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span> <span class="o">></span> <span class="mi">0</span> <span class="o">?</span> + <span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">received_objects</span><span class="p">)</span> <span class="o">/</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span> <span class="o">:</span> + <span class="mi">0</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">index_percent</span> <span class="o">=</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span> <span class="o">></span> <span class="mi">0</span> <span class="o">?</span> + <span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">indexed_objects</span><span class="p">)</span> <span class="o">/</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span> <span class="o">:</span> + <span class="mi">0</span><span class="p">;</span> + + <span class="kt">int</span> <span class="n">checkout_percent</span> <span class="o">=</span> <span class="n">pd</span><span class="o">-></span><span class="n">total_steps</span> <span class="o">></span> <span class="mi">0</span> + <span class="o">?</span> <span class="p">(</span><span class="mi">100</span> <span class="o">*</span> <span class="n">pd</span><span class="o">-></span><span class="n">completed_steps</span><span class="p">)</span> <span class="o">/</span> <span class="n">pd</span><span class="o">-></span><span class="n">total_steps</span> + <span class="o">:</span> <span class="mi">0</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">kbytes</span> <span class="o">=</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">received_bytes</span> <span class="o">/</span> <span class="mi">1024</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span> <span class="o">&&</span> + <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">received_objects</span> <span class="o">==</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</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">"Resolving deltas %d/%d</span><span class="se">\r</span><span class="s">"</span><span class="p">,</span> + <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">indexed_deltas</span><span class="p">,</span> + <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_deltas</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">"net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4"</span> <span class="n">PRIuZ</span> <span class="s">"/%4"</span> <span class="n">PRIuZ</span> <span class="s">") %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n">network_percent</span><span class="p">,</span> <span class="n">kbytes</span><span class="p">,</span> + <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">received_objects</span><span class="p">,</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span><span class="p">,</span> + <span class="n">index_percent</span><span class="p">,</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span><span class="p">.</span><span class="n">total_objects</span><span class="p">,</span> + <span class="n">checkout_percent</span><span class="p">,</span> + <span class="n">pd</span><span class="o">-></span><span class="n">completed_steps</span><span class="p">,</span> <span class="n">pd</span><span class="o">-></span><span class="n">total_steps</span><span class="p">,</span> + <span class="n">pd</span><span class="o">-></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">sideband_progress</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">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="c1">// unused</span> + + <span class="n">printf</span><span class="p">(</span><span class="s">"remote: %.*s"</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="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">fetch_progress</span><span class="p">(</span><span class="k">const</span> <span class="n">git_transfer_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="n">progress_data</span> <span class="o">*</span><span class="n">pd</span> <span class="o">=</span> <span class="p">(</span><span class="n">progress_data</span><span class="o">*</span><span class="p">)</span><span class="n">payload</span><span class="p">;</span> + <span class="n">pd</span><span class="o">-></span><span class="n">fetch_progress</span> <span class="o">=</span> <span class="o">*</span><span class="n">stats</span><span class="p">;</span> + <span class="n">print_progress</span><span class="p">(</span><span class="n">pd</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">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">cur</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">tot</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="n">progress_data</span> <span class="o">*</span><span class="n">pd</span> <span class="o">=</span> <span class="p">(</span><span class="n">progress_data</span><span class="o">*</span><span class="p">)</span><span class="n">payload</span><span class="p">;</span> + <span class="n">pd</span><span class="o">-></span><span class="n">completed_steps</span> <span class="o">=</span> <span class="n">cur</span><span class="p">;</span> + <span class="n">pd</span><span class="o">-></span><span class="n">total_steps</span> <span class="o">=</span> <span class="n">tot</span><span class="p">;</span> + <span class="n">pd</span><span class="o">-></span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">;</span> + <span class="n">print_progress</span><span class="p">(</span><span class="n">pd</span><span class="p">);</span> +<span class="p">}</span> + + +<span class="kt">int</span> <span class="nf">do_clone</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">progress_data</span> <span class="n">pd</span> <span class="o">=</span> <span class="p">{{</span><span class="mi">0</span><span class="p">}};</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">cloned_repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + <span class="n">git_clone_options</span> <span class="n">clone_opts</span> <span class="o">=</span> <span class="n">GIT_CLONE_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="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">url</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">path</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="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">repo</span><span class="p">;</span> <span class="c1">// unused</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>Validate args</p> + </td> + <td class=code> + <div class='highlight'><pre> <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">printf</span> <span class="p">(</span><span class="s">"USAGE: %s <url> <path></span><span class="se">\n</span><span class="s">"</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></pre></div> + </td> + </tr> + <tr id='section-3'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-3">¶</a> + </div> + <p>Set up 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="n">checkout_opts</span><span class="p">.</span><span class="n">progress_cb</span> <span class="o">=</span> <span class="n">checkout_progress</span><span class="p">;</span> + <span class="n">checkout_opts</span><span class="p">.</span><span class="n">progress_payload</span> <span class="o">=</span> <span class="o">&</span><span class="n">pd</span><span class="p">;</span> + <span class="n">clone_opts</span><span class="p">.</span><span class="n">checkout_opts</span> <span class="o">=</span> <span class="n">checkout_opts</span><span class="p">;</span> + <span class="n">clone_opts</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="n">sideband_progress</span><span class="p">;</span> + <span class="n">clone_opts</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="o">&</span><span class="n">fetch_progress</span><span class="p">;</span> + <span class="n">clone_opts</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> + <span class="n">clone_opts</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">payload</span> <span class="o">=</span> <span class="o">&</span><span class="n">pd</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">¶</a> + </div> + <p>Do the clone</p> + + </td> + <td class=code> + <div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_clone-1" class="fnlink" href="../../#v0.26.3/group/clone/git_clone">git_clone</a></span><span class="p">(</span><span class="o">&</span><span class="n">cloned_repo</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="o">&</span><span class="n">clone_opts</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</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="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="giterr_last-2" class="fnlink" href="../../#v0.26.3/group/giterr/giterr_last">giterr_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">"ERROR %d: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">err</span><span class="o">-></span><span class="n">klass</span><span class="p">,</span> <span class="n">err</span><span class="o">-></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">"ERROR %d: no detailed info</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">error</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">cloned_repo</span><span class="p">)</span> <span class="n"><a name="git_repository_free-3" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_free">git_repository_free</a></span><span class="p">(</span><span class="n">cloned_repo</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/v0.26.3/network/common.html b/ex/v0.26.3/network/common.html new file mode 100644 index 000000000..4bc570b46 --- /dev/null +++ b/ex/v0.26.3/network/common.html @@ -0,0 +1,55 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>common.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/network/fetch.html b/ex/v0.26.3/network/fetch.html new file mode 100644 index 000000000..2d5a58c2f --- /dev/null +++ b/ex/v0.26.3/network/fetch.html @@ -0,0 +1,222 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cp">#include "common.h"</span> +<span class="cp">#include <git2.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <stdlib.h></span> +<span class="cp">#include <string.h></span> +<span class="cp">#ifndef _WIN32</span> +<span class="cp"># include <pthread.h></span> +<span class="cp"># include <unistd.h></span> +<span class="cp">#endif</span> + +<span class="k">struct</span> <span class="n">dl_data</span> <span class="p">{</span> + <span class="n">git_remote</span> <span class="o">*</span><span class="n">remote</span><span class="p">;</span> + <span class="n">git_fetch_options</span> <span class="o">*</span><span class="n">fetch_opts</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">ret</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">finished</span><span class="p">;</span> +<span class="p">};</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">"remote: %.*s"</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'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">¶</a> + </div> + <p>This function gets called for each remote-tracking branch that gets +updated. The message we output depends on whether it'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_HEXSZ</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_HEXSZ</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="../../#v0.26.3/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_HEXSZ</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'\0'</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_oid_iszero-3" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_iszero">git_oid_iszero</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">"[new] %.20s %s</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/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_HEXSZ</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'\0'</span><span class="p">;</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"[updated] %.10s..%.10s %s</span><span class="se">\n</span><span class="s">"</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">¶</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_transfer_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">-></span><span class="n">received_objects</span> <span class="o">==</span> <span class="n">stats</span><span class="o">-></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">"Resolving deltas %d/%d</span><span class="se">\r</span><span class="s">"</span><span class="p">,</span> + <span class="n">stats</span><span class="o">-></span><span class="n">indexed_deltas</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></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">-></span><span class="n">total_objects</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">"Received %d/%d objects (%d) in %"</span> <span class="n">PRIuZ</span> <span class="s">" bytes</span><span class="se">\r</span><span class="s">"</span><span class="p">,</span> + <span class="n">stats</span><span class="o">-></span><span class="n">received_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">total_objects</span><span class="p">,</span> + <span class="n">stats</span><span class="o">-></span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></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">¶</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">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_transfer_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"><</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">"usage: %s fetch <repo></span><span class="se">\n</span><span class="s">"</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's a named remote or a URL */</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"Fetching %s for repo %p</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&</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"><</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="../../#v0.26.3/group/remote/git_remote_create_anonymous">git_remote_create_anonymous</a></span><span class="p">(</span><span class="o">&</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"><</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">&</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">&</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">¶</a> + </div> + <p>Perform the fetch with the configured refspecs from the +config. Update the reflog for the updated references with +"fetch".</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="../../#v0.26.3/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">&</span><span class="n">fetch_opts</span><span class="p">,</span> <span class="s">"fetch"</span><span class="p">)</span> <span class="o"><</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">¶</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="../../#v0.26.3/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">-></span><span class="n">local_objects</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">"</span><span class="se">\r</span><span class="s">Received %d/%d objects in %"</span> <span class="n">PRIuZ</span> <span class="s">" bytes (used %d local objects)</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n">stats</span><span class="o">-></span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">total_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">received_bytes</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></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">"</span><span class="se">\r</span><span class="s">Received %d/%d objects in %"</span> <span class="n">PRIuZ</span> <span class="s">"bytes</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n">stats</span><span class="o">-></span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">total_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></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="../../#v0.26.3/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="n"><a name="git_remote_free-7" class="fnlink" href="../../#v0.26.3/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/v0.26.3/network/git2.html b/ex/v0.26.3/network/git2.html new file mode 100644 index 000000000..61459dde9 --- /dev/null +++ b/ex/v0.26.3/network/git2.html @@ -0,0 +1,161 @@ +<!DOCTYPE html> +<html> +<head> + <meta http-equiv="content-type" content="text/html;charset=utf-8"> + <title>git2.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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>git2.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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cp">#include <stdlib.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <string.h></span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>This part is not strictly libgit2-dependent, but you can use this +as a starting point for a git-like tool</p> + </td> + <td class=code> + <div class='highlight'><pre><span class="k">struct</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="n">git_cb</span> <span class="n">fn</span><span class="p">;</span> +<span class="p">}</span> <span class="n">commands</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span> + <span class="p">{</span><span class="s">"ls-remote"</span><span class="p">,</span> <span class="n">ls_remote</span><span class="p">},</span> + <span class="p">{</span><span class="s">"fetch"</span><span class="p">,</span> <span class="n">fetch</span><span class="p">},</span> + <span class="p">{</span><span class="s">"clone"</span><span class="p">,</span> <span class="n">do_clone</span><span class="p">},</span> + <span class="p">{</span><span class="s">"index-pack"</span><span class="p">,</span> <span class="n">index_pack</span><span class="p">},</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> + +<span class="k">static</span> <span class="kt">int</span> <span class="nf">run_command</span><span class="p">(</span><span class="n">git_cb</span> <span class="n">fn</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_repository</span> <span class="o">*</span><span class="n">repo</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">¶</a> + </div> + <p>Before running the actual command, create an instance of the local +repository and pass it to the function.</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_repository_open-5" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open">git_repository_open</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</span><span class="p">,</span> <span class="s">".git"</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="mi">0</span><span class="p">)</span> + <span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</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">¶</a> + </div> + <p>Run the command. If something goes wrong, print the error message to stderr</p> + + </td> + <td class=code> + <div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n">fn</span><span class="p">(</span><span class="n">repo</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">error</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"><a name="giterr_last-1" class="fnlink" href="../../#v0.26.3/group/giterr/giterr_last">giterr_last</a></span><span class="p">()</span> <span class="o">==</span> <span class="nb">NULL</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">"Error without message"</span><span class="p">);</span> + <span class="k">else</span> + <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"Bad news:</span><span class="se">\n</span><span class="s"> %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n"><a name="giterr_last-2" class="fnlink" href="../../#v0.26.3/group/giterr/giterr_last">giterr_last</a></span><span class="p">()</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">repo</span><span class="p">)</span> + <span class="n"><a name="git_repository_free-6" class="fnlink" href="../../#v0.26.3/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="o">!!</span><span class="n">error</span><span class="p">;</span> +<span class="p">}</span> + +<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> +<span class="p">{</span> + <span class="kt">int</span> <span class="n">i</span><span class="p">;</span> + <span class="kt">int</span> <span class="n">return_code</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">argc</span> <span class="o"><</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">"usage: %s <cmd> [repo]</span><span class="se">\n</span><span class="s">"</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">exit</span><span class="p">(</span><span class="n">EXIT_FAILURE</span><span class="p">);</span> + <span class="p">}</span> + + <span class="n"><a name="git_libgit2_init-3" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></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">commands</span><span class="p">[</span><span class="n">i</span><span class="p">].</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">i</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">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">commands</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">name</span><span class="p">))</span> <span class="p">{</span> + <span class="n">return_code</span> <span class="o">=</span> <span class="n">run_command</span><span class="p">(</span><span class="n">commands</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">fn</span><span class="p">,</span> <span class="o">--</span><span class="n">argc</span><span class="p">,</span> <span class="o">++</span><span class="n">argv</span><span class="p">);</span> + <span class="k">goto</span> <span class="n">shutdown</span><span class="p">;</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">"Command not found: %s</span><span class="se">\n</span><span class="s">"</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="nl">shutdown:</span> + <span class="n"><a name="git_libgit2_shutdown-4" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="n">return_code</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + </table> +</div> +</body> diff --git a/ex/v0.26.3/network/index-pack.html b/ex/v0.26.3/network/index-pack.html new file mode 100644 index 000000000..faa9215fe --- /dev/null +++ b/ex/v0.26.3/network/index-pack.html @@ -0,0 +1,162 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>index-pack.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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cp">#include <git2.h></span> +<span class="cp">#include <stdlib.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <string.h></span> +<span class="cp">#include <sys/types.h></span> +<span class="cp">#include <sys/stat.h></span> +<span class="cp">#include <fcntl.h></span> +<span class="cp">#ifdef _WIN32</span> +<span class="cp"># include <io.h></span> +<span class="cp"># include <Windows.h></span> + +<span class="cp"># define open _open</span> +<span class="cp"># define read _read</span> +<span class="cp"># define close _close</span> + +<span class="cp">#define ssize_t unsigned int</span> +<span class="cp">#else</span> +<span class="cp"># include <unistd.h></span> +<span class="cp">#endif</span> +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>This could be run in the main loop whilst the application waits for +the indexing to finish in a worker thread</p> + + </td> + <td class=code> + <div class='highlight'><pre><span class="k">static</span> <span class="kt">int</span> <span class="nf">index_cb</span><span class="p">(</span><span class="k">const</span> <span class="n">git_transfer_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">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">"</span><span class="se">\r</span><span class="s">Processing %d of %d"</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="o">-></span><span class="n">total_objects</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">index_pack</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_indexer</span> <span class="o">*</span><span class="n">idx</span><span class="p">;</span> + <span class="n">git_transfer_progress</span> <span class="n">stats</span> <span class="o">=</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="kt">int</span> <span class="n">error</span><span class="p">;</span> + <span class="kt">char</span> <span class="n">hash</span><span class="p">[</span><span class="n">GIT_OID_HEXSZ</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="kt">int</span> <span class="n">fd</span><span class="p">;</span> + <span class="kt">ssize_t</span> <span class="n">read_bytes</span><span class="p">;</span> + <span class="kt">char</span> <span class="n">buf</span><span class="p">[</span><span class="mi">512</span><span class="p">];</span> + + <span class="p">(</span><span class="kt">void</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">argc</span> <span class="o"><</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">"usage: %s index-pack <packfile></span><span class="se">\n</span><span class="s">"</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="k">if</span> <span class="p">(</span><span class="n"><a name="git_indexer_new-1" class="fnlink" href="../../#v0.26.3/group/indexer/git_indexer_new">git_indexer_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">idx</span><span class="p">,</span> <span class="s">"."</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="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</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">puts</span><span class="p">(</span><span class="s">"bad idx"</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">if</span> <span class="p">((</span><span class="n">fd</span> <span class="o">=</span> <span class="n">open</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="mi">0</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">perror</span><span class="p">(</span><span class="s">"open"</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">do</span> <span class="p">{</span> + <span class="n">read_bytes</span> <span class="o">=</span> <span class="n">read</span><span class="p">(</span><span class="n">fd</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="k">if</span> <span class="p">(</span><span class="n">read_bytes</span> <span class="o"><</span> <span class="mi">0</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">error</span> <span class="o">=</span> <span class="n"><a name="git_indexer_append-2" class="fnlink" href="../../#v0.26.3/group/indexer/git_indexer_append">git_indexer_append</a></span><span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">buf</span><span class="p">,</span> <span class="n">read_bytes</span><span class="p">,</span> <span class="o">&</span><span class="n">stats</span><span class="p">))</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">index_cb</span><span class="p">(</span><span class="o">&</span><span class="n">stats</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="p">}</span> <span class="k">while</span> <span class="p">(</span><span class="n">read_bytes</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">read_bytes</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="o">-</span><span class="mi">1</span><span class="p">;</span> + <span class="n">perror</span><span class="p">(</span><span class="s">"failed reading"</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">error</span> <span class="o">=</span> <span class="n"><a name="git_indexer_commit-3" class="fnlink" href="../../#v0.26.3/group/indexer/git_indexer_commit">git_indexer_commit</a></span><span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="o">&</span><span class="n">stats</span><span class="p">))</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">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\r</span><span class="s">Indexing %d of %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">stats</span><span class="p">.</span><span class="n">indexed_objects</span><span class="p">,</span> <span class="n">stats</span><span class="p">.</span><span class="n">total_objects</span><span class="p">);</span> + + <span class="n"><a name="git_oid_fmt-6" class="fnlink" href="../../#v0.26.3/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">hash</span><span class="p">,</span> <span class="n"><a name="git_indexer_hash-4" class="fnlink" href="../../#v0.26.3/group/indexer/git_indexer_hash">git_indexer_hash</a></span><span class="p">(</span><span class="n">idx</span><span class="p">));</span> + <span class="n">puts</span><span class="p">(</span><span class="n">hash</span><span class="p">);</span> + + <span class="nl">cleanup:</span> + <span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> + <span class="n"><a name="git_indexer_free-5" class="fnlink" href="../../#v0.26.3/group/indexer/git_indexer_free">git_indexer_free</a></span><span class="p">(</span><span class="n">idx</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/v0.26.3/network/ls-remote.html b/ex/v0.26.3/network/ls-remote.html new file mode 100644 index 000000000..2a619478c --- /dev/null +++ b/ex/v0.26.3/network/ls-remote.html @@ -0,0 +1,158 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="../add.html">add.c</a> + <a class="source" href="../blame.html">blame.c</a> + <a class="source" href="../cat-file.html">cat-file.c</a> + <a class="source" href="../common.html">common.c</a> + <a class="source" href="../describe.html">describe.c</a> + <a class="source" href="../diff.html">diff.c</a> + <a class="source" href="../for-each-ref.html">for-each-ref.c</a> + <a class="source" href="../general.html">general.c</a> + <a class="source" href="../init.html">init.c</a> + <a class="source" href="../log.html">log.c</a> + <a class="source" href="clone.html">clone.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="fetch.html">fetch.c</a> + <a class="source" href="git2.html">git2.c</a> + <a class="source" href="index-pack.html">index-pack.c</a> + <a class="source" href="ls-remote.html">ls-remote.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="../showindex.html">showindex.c</a> + <a class="source" href="../status.html">status.c</a> + <a class="source" href="../tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cp">#include <git2.h></span> +<span class="cp">#include <stdlib.h></span> +<span class="cp">#include <stdio.h></span> +<span class="cp">#include <string.h></span> +<span class="cp">#include "common.h"</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></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>Find the remote by name</p> + </td> + <td class=code> + <div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_lookup-3" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&</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"><</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="../../#v0.26.3/group/remote/git_remote_create_anonymous">git_remote_create_anonymous</a></span><span class="p">(</span><span class="o">&</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"><</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-3'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-3">¶</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-4" class="fnlink" href="../../#v0.26.3/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">&</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"><</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-4'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-4">¶</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-5" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_ls">git_remote_ls</a></span><span class="p">(</span><span class="o">&</span><span class="n">refs</span><span class="p">,</span> <span class="o">&</span><span class="n">refs_len</span><span class="p">,</span> <span class="n">remote</span><span class="p">)</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="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"><</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_HEXSZ</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="../../#v0.26.3/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">&</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">oid</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"%s</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</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">-></span><span class="n">name</span><span class="p">);</span> + <span class="p">}</span> + +<span class="nl">cleanup:</span> + <span class="n"><a name="git_remote_free-6" class="fnlink" href="../../#v0.26.3/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-5'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-5">¶</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">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"><</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">"usage: %s ls-remote <remote></span><span class="se">\n</span><span class="s">"</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/v0.26.3/remote.html b/ex/v0.26.3/remote.html new file mode 100644 index 000000000..c86f353e2 --- /dev/null +++ b/ex/v0.26.3/remote.html @@ -0,0 +1,340 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "remote" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <p>This is a sample program that is similar to "git remote". See the +documentation for that (try "git help remote") 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="p">};</span> + +<span class="k">struct</span> <span class="n">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">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">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">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">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">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">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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="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">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">git_buf</span> <span class="n">buf</span> <span class="o">=</span> <span class="n">GIT_BUF_INIT_CONST</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_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + + <span class="n">parse_subcmd</span><span class="p">(</span><span class="o">&</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"><a name="git_libgit2_init-2" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_discover-15" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_discover">git_repository_discover</a></span><span class="p">(</span><span class="o">&</span><span class="n">buf</span><span class="p">,</span> <span class="s">"."</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">"Could not find repository"</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_repository_open-14" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open">git_repository_open</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</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="s">"Could not open repository"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + <span class="n"><a name="git_buf_free-1" class="fnlink" href="../../#v0.26.3/group/buf/git_buf_free">git_buf_free</a></span><span class="p">(</span><span class="o">&</span><span class="n">buf</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="n">subcmd_add</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">&</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="n">subcmd_remove</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">&</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="n">subcmd_rename</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">&</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="n">subcmd_seturl</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">&</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="n">subcmd_show</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">&</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="n"><a name="git_libgit2_shutdown-3" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></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">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">-></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">"you need to specify a name and URL"</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">-></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">-></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-4" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_create">git_remote_create</a></span><span class="p">(</span><span class="o">&</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">"could not create remote"</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">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">-></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">"you need to specify a name"</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">-></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-13" class="fnlink" href="../../#v0.26.3/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">"could not delete remote"</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">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">-></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">"you need to specify old and new remote name"</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">-></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">-></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-12" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_rename">git_remote_rename</a></span><span class="p">(</span><span class="o">&</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"><</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_free-16" class="fnlink" href="../../#v0.26.3/group/strarray/git_strarray_free">git_strarray_free</a></span><span class="p">(</span><span class="o">&</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">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"><</span> <span class="n">o</span><span class="o">-></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">-></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">"--push"</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">'-'</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="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">'-'</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="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">"invalid argument to set-url"</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">"you need to specify remote and the new URL"</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-9" class="fnlink" href="../../#v0.26.3/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-8" class="fnlink" href="../../#v0.26.3/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">"could not set URL"</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">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"><</span> <span class="n">o</span><span class="o">-></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">-></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">"-v"</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">"--verbose"</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-11" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_list">git_remote_list</a></span><span class="p">(</span><span class="o">&</span><span class="n">remotes</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> + <span class="s">"could not retrieve remotes"</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"><</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-5" class="fnlink" href="../../#v0.26.3/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&</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">"could not look up remote"</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-6" class="fnlink" href="../../#v0.26.3/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">"%s</span><span class="se">\t</span><span class="s">%s (fetch)</span><span class="se">\n</span><span class="s">"</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-7" class="fnlink" href="../../#v0.26.3/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="n">push</span> <span class="o">:</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">"%s</span><span class="se">\t</span><span class="s">%s (push)</span><span class="se">\n</span><span class="s">"</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-10" class="fnlink" href="../../#v0.26.3/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_free-17" class="fnlink" href="../../#v0.26.3/group/strarray/git_strarray_free">git_strarray_free</a></span><span class="p">(</span><span class="o">&</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">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"><</span> <span class="mi">2</span><span class="p">)</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"no command specified"</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">"add"</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">"remove"</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">"rename"</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">"set-url"</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">"show"</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">"command is not valid"</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">-></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">-></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">-></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">"usage: remote add <name> <url></span><span class="se">\n</span><span class="s">"</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">" remote remove <name></span><span class="se">\n</span><span class="s">"</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">" remote rename <old> <new></span><span class="se">\n</span><span class="s">"</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">" remote set-url [--push] <name> <newurl></span><span class="se">\n</span><span class="s">"</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">" remote show [-v|--verbose]</span><span class="se">\n</span><span class="s">"</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">&&</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">"</span><span class="se">\n</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</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">&&</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">"</span><span class="se">\n</span><span class="s">%s: %s</span><span class="se">\n</span><span class="s">"</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/v0.26.3/rev-list.html b/ex/v0.26.3/rev-list.html new file mode 100644 index 000000000..d3a21f770 --- /dev/null +++ b/ex/v0.26.3/rev-list.html @@ -0,0 +1,55 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>rev-list.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/rev-parse.html b/ex/v0.26.3/rev-parse.html new file mode 100644 index 000000000..240918048 --- /dev/null +++ b/ex/v0.26.3/rev-parse.html @@ -0,0 +1,188 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "rev-parse" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</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="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="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="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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="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"><a name="git_libgit2_init-1" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + <span class="n">parse_opts</span><span class="p">(</span><span class="o">&</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="o">&</span><span class="n">ps</span><span class="p">),</span> <span class="s">"Parsing"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_repository_free-17" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_free">git_repository_free</a></span><span class="p">(</span><span class="n">ps</span><span class="p">.</span><span class="n">repo</span><span class="p">);</span> + <span class="n"><a name="git_libgit2_shutdown-2" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span> + +<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">&&</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">"%s: %s</span><span class="se">\n</span><span class="s">"</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">"%s</span><span class="se">\n</span><span class="s">"</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">"usage: rev-parse [ --option ] <args>...</span><span class="se">\n</span><span class="s">"</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"><</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">'-'</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">-></span><span class="n">spec</span><span class="p">)</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"Too many specs"</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span> + <span class="n">ps</span><span class="o">-></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">"--not"</span><span class="p">))</span> + <span class="n">ps</span><span class="o">-></span><span class="n">not</span> <span class="o">=</span> <span class="o">!</span><span class="n">ps</span><span class="o">-></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">&</span><span class="n">ps</span><span class="o">-></span><span class="n">repodir</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--git-dir"</span><span class="p">))</span> + <span class="n">usage</span><span class="p">(</span><span class="s">"Cannot handle argument"</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="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_HEXSZ</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">ps</span><span class="o">-></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">ps</span><span class="o">-></span><span class="n">repodir</span><span class="p">)</span> + <span class="n">ps</span><span class="o">-></span><span class="n">repodir</span> <span class="o">=</span> <span class="s">"."</span><span class="p">;</span> + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-16" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">ps</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></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">"Could not open repository from"</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></span><span class="n">repodir</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-18" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse">git_revparse</a></span><span class="p">(</span><span class="o">&</span><span class="n">rs</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></span><span class="n">spec</span><span class="p">),</span> <span class="s">"Could not parse"</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></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">&</span> <span class="n">GIT_REVPARSE_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-12" class="fnlink" href="../../#v0.26.3/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-4" class="fnlink" href="../../#v0.26.3/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">"%s</span><span class="se">\n</span><span class="s">"</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="../../#v0.26.3/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">&</span> <span class="n">GIT_REVPARSE_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-13" class="fnlink" href="../../#v0.26.3/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-5" class="fnlink" href="../../#v0.26.3/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">"%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span> + <span class="n"><a name="git_object_free-10" class="fnlink" href="../../#v0.26.3/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">&</span> <span class="n">GIT_REVPARSE_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-3" class="fnlink" href="../../#v0.26.3/group/merge/git_merge_base">git_merge_base</a></span><span class="p">(</span><span class="o">&</span><span class="n">base</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> + <span class="n"><a name="git_object_id-6" class="fnlink" href="../../#v0.26.3/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-7" class="fnlink" href="../../#v0.26.3/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">"Could not find merge base"</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></span><span class="n">spec</span><span class="p">);</span> + + <span class="n"><a name="git_oid_tostr-14" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">base</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"%s</span><span class="se">\n</span><span class="s">"</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-15" class="fnlink" href="../../#v0.26.3/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-8" class="fnlink" href="../../#v0.26.3/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">"^%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">str</span><span class="p">);</span> + <span class="n"><a name="git_object_free-11" class="fnlink" href="../../#v0.26.3/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">"Invalid results from <a name="git_revparse-19" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse">git_revparse</a>"</span><span class="p">,</span> <span class="n">ps</span><span class="o">-></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/v0.26.3/showindex.html b/ex/v0.26.3/showindex.html new file mode 100644 index 000000000..a44729887 --- /dev/null +++ b/ex/v0.26.3/showindex.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<html> +<head> + <meta http-equiv="content-type" content="text/html;charset=utf-8"> + <title>showindex.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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>showindex.c</h1></th> + <th class=code></th> + </tr> + </thead> + <tbody> + </table> +</div> +</body> diff --git a/ex/v0.26.3/status.html b/ex/v0.26.3/status.html new file mode 100644 index 000000000..ee2ff5add --- /dev/null +++ b/ex/v0.26.3/status.html @@ -0,0 +1,681 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "status" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span> +<span class="cp">#ifdef _WIN32</span> +<span class="cp"># include <Windows.h></span> +<span class="cp"># define sleep(a) Sleep(a * 1000)</span> +<span class="cp">#else</span> +<span class="cp"># include <unistd.h></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">¶</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 "long" format +from <code>git status</code></li> +<li>A sample status formatter that matches the "short" 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="p">};</span> + +<span class="cp">#define MAX_PATHSPEC 8</span> + +<span class="k">struct</span> <span class="n">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">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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> + <span class="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">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">"."</span> <span class="p">};</span> + + <span class="n"><a name="git_libgit2_init-1" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></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">&</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-3'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-3">¶</a> + </div> + <p>Try to open the repository at the given path (or at the current +directory if none was given).</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_open_ext-5" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</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="mi">0</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">),</span> + <span class="s">"Could not open repository"</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="k">if</span> <span class="p">(</span><span class="n"><a name="git_repository_is_bare-9" class="fnlink" href="../../#v0.26.3/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">"Cannot report status on bare repository"</span><span class="p">,</span> + <span class="n"><a name="git_repository_path-8" class="fnlink" href="../../#v0.26.3/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="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">"</span><span class="se">\033</span><span class="s">[H</span><span class="se">\033</span><span class="s">[2J"</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">¶</a> + </div> + <p>Run status on the repository</p> + +<p>We use <code><a name="git_status_list_new-12" class="fnlink" href="../../#v0.26.3/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-10" class="fnlink" href="../../#v0.26.3/group/status/git_status_foreach">git_status_foreach</a>()</code> or +<code><a name="git_status_foreach_ext-11" class="fnlink" href="../../#v0.26.3/group/status/git_status_foreach_ext">git_status_foreach_ext</a>()</code> if you'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-13" class="fnlink" href="../../#v0.26.3/group/status/git_status_list_new">git_status_list_new</a></span><span class="p">(</span><span class="o">&</span><span class="n">status</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="o">&</span><span class="n">o</span><span class="p">.</span><span class="n">statusopt</span><span class="p">),</span> + <span class="s">"Could not get status"</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-23" class="fnlink" href="../../#v0.26.3/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">&</span><span class="n">submod_count</span><span class="p">),</span> + <span class="s">"Cannot iterate submodules"</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-22" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_repository_free-6" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-2" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + <tr id='section-5'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-5">¶</a> + </div> + <p>If the user asked for the branch, let'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-7" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_head">git_repository_head</a></span><span class="p">(</span><span class="o">&</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-4" class="fnlink" href="../../#v0.26.3/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">"failed to get current branch"</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">"# On branch %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n">branch</span> <span class="o">?</span> <span class="n">branch</span> <span class="o">:</span> <span class="s">"Not currently on any branch."</span><span class="p">);</span> + <span class="k">else</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"## %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">branch</span> <span class="o">?</span> <span class="n">branch</span> <span class="o">:</span> <span class="s">"HEAD (no branch)"</span><span class="p">);</span> + + <span class="n"><a name="git_reference_free-3" class="fnlink" href="../../#v0.26.3/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-6'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-6">¶</a> + </div> + <p>This function print out an output similar to git'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-14" class="fnlink" href="../../#v0.26.3/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-7'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-7">¶</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"><</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-16" class="fnlink" href="../../#v0.26.3/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">-></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">-></span><span class="n">status</span> <span class="o">&</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">-></span><span class="n">status</span> <span class="o">&</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">"new file: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"modified: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"deleted: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"renamed: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"typechange:"</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">"# Changes to be committed:</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"# (use </span><span class="se">\"</span><span class="s">git reset HEAD <file>...</span><span class="se">\"</span><span class="s"> to unstage)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"#</span><span class="se">\n</span><span class="s">"</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">-></span><span class="n">head_to_index</span><span class="o">-></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">-></span><span class="n">head_to_index</span><span class="o">-></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">&&</span> <span class="n">new_path</span> <span class="o">&&</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">"#</span><span class="se">\t</span><span class="s">%s %s -> %s</span><span class="se">\n</span><span class="s">"</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">"#</span><span class="se">\t</span><span class="s">%s %s</span><span class="se">\n</span><span class="s">"</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="n">old_path</span> <span class="o">:</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">"#</span><span class="se">\n</span><span class="s">"</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-8'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-8">¶</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"><</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-17" class="fnlink" href="../../#v0.26.3/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-9'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-9">¶</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">-></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">-></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-10'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-10">¶</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">-></span><span class="n">status</span> <span class="o">&</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">"modified: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"deleted: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"renamed: "</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">"typechange:"</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">"# Changes not staged for commit:</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"# (use </span><span class="se">\"</span><span class="s">git add%s <file>...</span><span class="se">\"</span><span class="s"> to update what will be committed)</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">rm_in_workdir</span> <span class="o">?</span> <span class="s">"/rm"</span> <span class="o">:</span> <span class="s">""</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"# (use </span><span class="se">\"</span><span class="s">git checkout -- <file>...</span><span class="se">\"</span><span class="s"> to discard changes in working directory)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"#</span><span class="se">\n</span><span class="s">"</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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">&&</span> <span class="n">new_path</span> <span class="o">&&</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">"#</span><span class="se">\t</span><span class="s">%s %s -> %s</span><span class="se">\n</span><span class="s">"</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">"#</span><span class="se">\t</span><span class="s">%s %s</span><span class="se">\n</span><span class="s">"</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="n">old_path</span> <span class="o">:</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">"#</span><span class="se">\n</span><span class="s">"</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">¶</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"><</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-18" class="fnlink" href="../../#v0.26.3/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">-></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">"# Untracked files:</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"# (use </span><span class="se">\"</span><span class="s">git add <file>...</span><span class="se">\"</span><span class="s"> to include in what will be committed)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"#</span><span class="se">\n</span><span class="s">"</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">"#</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">index_to_workdir</span><span class="o">-></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-12'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-12">¶</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"><</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-19" class="fnlink" href="../../#v0.26.3/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">-></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">"# Ignored files:</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"# (use </span><span class="se">\"</span><span class="s">git add -f <file>...</span><span class="se">\"</span><span class="s"> to include in what will be committed)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"#</span><span class="se">\n</span><span class="s">"</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">"#</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">index_to_workdir</span><span class="o">-></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">&&</span> <span class="n">changed_in_workdir</span><span class="p">)</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"no changes added to commit (use </span><span class="se">\"</span><span class="s">git add</span><span class="se">\"</span><span class="s"> and/or </span><span class="se">\"</span><span class="s">git commit -a</span><span class="se">\"</span><span class="s">)</span><span class="se">\n</span><span class="s">"</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">¶</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-15" class="fnlink" href="../../#v0.26.3/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"><</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-20" class="fnlink" href="../../#v0.26.3/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">-></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">' '</span><span class="p">;</span> + <span class="n">extra</span> <span class="o">=</span> <span class="s">""</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'A'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'M'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'D'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'R'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'T'</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></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="n">istatus</span> <span class="o">==</span> <span class="sc">' '</span><span class="p">)</span> + <span class="n">istatus</span> <span class="o">=</span> <span class="sc">'?'</span><span class="p">;</span> + <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">'?'</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">-></span><span class="n">status</span> <span class="o">&</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">'M'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'D'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'R'</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">status</span> <span class="o">&</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">'T'</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="o">-></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="n">istatus</span> <span class="o">=</span> <span class="sc">'!'</span><span class="p">;</span> + <span class="n">wstatus</span> <span class="o">=</span> <span class="sc">'!'</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">'?'</span> <span class="o">&&</span> <span class="n">wstatus</span> <span class="o">==</span> <span class="sc">'?'</span><span class="p">)</span> + <span class="k">continue</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">¶</a> + </div> + <p>A commit in a tree is how submodules are stored, so +let'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">-></span><span class="n">index_to_workdir</span> <span class="o">&&</span> + <span class="n">s</span><span class="o">-></span><span class="n">index_to_workdir</span><span class="o">-></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-26" class="fnlink" href="../../#v0.26.3/group/submodule/git_submodule_status">git_submodule_status</a></span><span class="p">(</span><span class="o">&</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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">&</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">" (new commits)"</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">&</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">" (modified content)"</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">&</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">" (modified content)"</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">&</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">" (untracked content)"</span><span class="p">;</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">¶</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">-></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">-></span><span class="n">head_to_index</span><span class="o">-></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">-></span><span class="n">head_to_index</span><span class="o">-></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">-></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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">-></span><span class="n">index_to_workdir</span><span class="o">-></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">'R'</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">'R'</span><span class="p">)</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"%c%c %s %s %s%s</span><span class="se">\n</span><span class="s">"</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">"%c%c %s %s%s</span><span class="se">\n</span><span class="s">"</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">'R'</span><span class="p">)</span> + <span class="n">printf</span><span class="p">(</span><span class="s">"%c%c %s %s%s</span><span class="se">\n</span><span class="s">"</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">"%c%c %s%s</span><span class="se">\n</span><span class="s">"</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"><</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-21" class="fnlink" href="../../#v0.26.3/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">-></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">"?? %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">s</span><span class="o">-></span><span class="n">index_to_workdir</span><span class="o">-></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">"# Submodules</span><span class="se">\n</span><span class="s">"</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">"# - submodule '%s' at %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> + <span class="n"><a name="git_submodule_name-24" class="fnlink" href="../../#v0.26.3/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-25" class="fnlink" href="../../#v0.26.3/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-16'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-16">¶</a> + </div> + <p>Parse options that git'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">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"><</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">'-'</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">-></span><span class="n">npaths</span> <span class="o"><</span> <span class="n">MAX_PATHSPEC</span><span class="p">)</span> + <span class="n">o</span><span class="o">-></span><span class="n">pathspec</span><span class="p">[</span><span class="n">o</span><span class="o">-></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">"Example only supports a limited pathspec"</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">"-s"</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">"--short"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--long"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--porcelain"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-b"</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">"--branch"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-z"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">o</span><span class="o">-></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">-></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">-></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">"--ignored"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-uno"</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">"--untracked-files=no"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></span><span class="n">statusopt</span><span class="p">.</span><span class="n">flags</span> <span class="o">&=</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">"-unormal"</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">"--untracked-files=normal"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"-uall"</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">"--untracked-files=all"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--ignore-submodules=all"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"--git-dir="</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="s">"--git-dir="</span><span class="p">)))</span> + <span class="n">o</span><span class="o">-></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">"--git-dir="</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">"--repeat"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">&</span><span class="n">o</span><span class="o">-></span><span class="n">repeat</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"--repeat"</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">"--list-submodules"</span><span class="p">))</span> + <span class="n">o</span><span class="o">-></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">"Unsupported option"</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">-></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">-></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">-></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">-></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">-></span><span class="n">npaths</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> + <span class="n">o</span><span class="o">-></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">-></span><span class="n">pathspec</span><span class="p">;</span> + <span class="n">o</span><span class="o">-></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">-></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/v0.26.3/tag.html b/ex/v0.26.3/tag.html new file mode 100644 index 000000000..62c9ad7d5 --- /dev/null +++ b/ex/v0.26.3/tag.html @@ -0,0 +1,514 @@ +<!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 … + <div id="jump_wrapper"> + <div id="jump_page"> + <a class="source" href="../../#v0.26.3">API Docs</a> + <a class="source" href="add.html">add.c</a> + <a class="source" href="blame.html">blame.c</a> + <a class="source" href="cat-file.html">cat-file.c</a> + <a class="source" href="common.html">common.c</a> + <a class="source" href="describe.html">describe.c</a> + <a class="source" href="diff.html">diff.c</a> + <a class="source" href="for-each-ref.html">for-each-ref.c</a> + <a class="source" href="general.html">general.c</a> + <a class="source" href="init.html">init.c</a> + <a class="source" href="log.html">log.c</a> + <a class="source" href="network/clone.html">clone.c</a> + <a class="source" href="network/common.html">common.c</a> + <a class="source" href="network/fetch.html">fetch.c</a> + <a class="source" href="network/git2.html">git2.c</a> + <a class="source" href="network/index-pack.html">index-pack.c</a> + <a class="source" href="network/ls-remote.html">ls-remote.c</a> + <a class="source" href="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="showindex.html">showindex.c</a> + <a class="source" href="status.html">status.c</a> + <a class="source" href="tag.html">tag.c</a> + </div> + </div> + </div> + <table cellspacing=0 cellpadding=0> + <thead> + <tr> + <th class=docs><h1>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">¶</a> + </div> + + </td> + <td class=code> + <div class='highlight'><pre><span class="cm">/*</span> +<span class="cm"> * libgit2 "tag" 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"> * <http://creativecommons.org/publicdomain/zero/1.0/>.</span> +<span class="cm"> */</span> + +<span class="cp">#include "common.h"</span></pre></div> + </td> + </tr> + <tr id='section-2'> + <td class=docs> + <div class="pilwrap"> + <a class="pilcrow" href="#section-2">¶</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 "v0.1*"</code>)</li> +<li>Lightweight tag creation (<code>tag test v0.18.0</code>)</li> +<li>Tag creation (<code>tag -a -m "Test message" 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'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">¶</a> + </div> + <p>tag_options represents the parsed command line options</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="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> <span class="n">tag_options</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">¶</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="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">¶</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">¶</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">-></span><span class="n">opts</span><span class="o">-></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">¶</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">&&</span> <span class="o">*</span><span class="n">msg</span> <span class="o">!=</span> <span class="sc">'\n'</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%c"</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">¶</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">&&</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">'\n'</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">"</span><span class="se">\n</span><span class="s">"</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">¶</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">&&</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">"</span><span class="se">\n</span><span class="s">"</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">¶</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">&&</span> <span class="n">num</span><span class="o">--</span> <span class="o">>=</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">" "</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">&&</span> <span class="o">*</span><span class="n">msg</span> <span class="o">!=</span> <span class="sc">'\n'</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%c"</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">¶</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">&&</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">'\n'</span> <span class="o">&&</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">'\n'</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">"</span><span class="se">\n</span><span class="s">"</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">&&</span> <span class="o">*</span><span class="n">msg</span> <span class="o">==</span> <span class="sc">'\n'</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">"</span><span class="se">\n</span><span class="s">"</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">¶</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">"%-16s"</span><span class="p">,</span> <span class="n"><a name="git_tag_name-20" class="fnlink" href="../../#v0.26.3/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">-></span><span class="n">opts</span><span class="o">-></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-21" class="fnlink" href="../../#v0.26.3/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">"</span><span class="se">\n</span><span class="s">"</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">¶</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">"%-16s"</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">-></span><span class="n">opts</span><span class="o">-></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="../../#v0.26.3/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">"</span><span class="se">\n</span><span class="s">"</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">¶</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">"%s</span><span class="se">\n</span><span class="s">"</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">¶</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">-></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-13" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">"Failed to lookup rev"</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-6" class="fnlink" href="../../#v0.26.3/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="n">GIT_OBJ_TAG</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="n">GIT_OBJ_COMMIT</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="nl">default:</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-7" class="fnlink" href="../../#v0.26.3/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">-></span><span class="n">opts</span><span class="o">-></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-25" class="fnlink" href="../../#v0.26.3/group/tag/git_tag_list_match">git_tag_list_match</a></span><span class="p">(</span><span class="o">&</span><span class="n">tag_names</span><span class="p">,</span> <span class="n">pattern</span> <span class="o">?</span> <span class="n">pattern</span> <span class="o">:</span> <span class="s">"*"</span><span class="p">,</span> <span class="n">state</span><span class="o">-></span><span class="n">repo</span><span class="p">),</span> + <span class="s">"Unable to get list of tags"</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"><</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_free-19" class="fnlink" href="../../#v0.26.3/group/strarray/git_strarray_free">git_strarray_free</a></span><span class="p">(</span><span class="o">&</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="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">-></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">-></span><span class="n">tag_name</span><span class="p">,</span> <span class="s">"Name required"</span><span class="p">);</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-14" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</span><span class="n">obj</span><span class="p">,</span> <span class="n">state</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></span><span class="n">tag_name</span><span class="p">),</span> + <span class="s">"Failed to lookup rev"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></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-5" class="fnlink" href="../../#v0.26.3/group/object/git_object_short_id">git_object_short_id</a></span><span class="p">(</span><span class="o">&</span><span class="n">abbrev_oid</span><span class="p">,</span> <span class="n">obj</span><span class="p">),</span> + <span class="s">"Unable to get abbreviated OID"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></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-24" class="fnlink" href="../../#v0.26.3/group/tag/git_tag_delete">git_tag_delete</a></span><span class="p">(</span><span class="n">state</span><span class="o">-></span><span class="n">repo</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></span><span class="n">tag_name</span><span class="p">),</span> + <span class="s">"Unable to delete tag"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></span><span class="n">tag_name</span><span class="p">);</span> + + <span class="n">printf</span><span class="p">(</span><span class="s">"Deleted tag '%s' (was %s)</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></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_free-1" class="fnlink" href="../../#v0.26.3/group/buf/git_buf_free">git_buf_free</a></span><span class="p">(</span><span class="o">&</span><span class="n">abbrev_oid</span><span class="p">);</span> + <span class="n"><a name="git_object_free-8" class="fnlink" href="../../#v0.26.3/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_lighweight_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">-></span><span class="n">repo</span><span class="p">;</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">-></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">-></span><span class="n">tag_name</span><span class="p">,</span> <span class="s">"Name required"</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">-></span><span class="n">target</span><span class="p">)</span> <span class="n">opts</span><span class="o">-></span><span class="n">target</span> <span class="o">=</span> <span class="s">"HEAD"</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">-></span><span class="n">target</span><span class="p">,</span> <span class="s">"Target required"</span><span class="p">);</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-15" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">-></span><span class="n">target</span><span class="p">),</span> + <span class="s">"Unable to resolve spec"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></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-23" class="fnlink" href="../../#v0.26.3/group/tag/git_tag_create_lightweight">git_tag_create_lightweight</a></span><span class="p">(</span><span class="o">&</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">-></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">-></span><span class="n">force</span><span class="p">),</span> <span class="s">"Unable to create tag"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_object_free-9" class="fnlink" href="../../#v0.26.3/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">-></span><span class="n">repo</span><span class="p">;</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">-></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">-></span><span class="n">tag_name</span><span class="p">,</span> <span class="s">"Name required"</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">-></span><span class="n">message</span><span class="p">,</span> <span class="s">"Message required"</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">-></span><span class="n">target</span><span class="p">)</span> <span class="n">opts</span><span class="o">-></span><span class="n">target</span> <span class="o">=</span> <span class="s">"HEAD"</span><span class="p">;</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_revparse_single-16" class="fnlink" href="../../#v0.26.3/group/revparse/git_revparse_single">git_revparse_single</a></span><span class="p">(</span><span class="o">&</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">-></span><span class="n">target</span><span class="p">),</span> + <span class="s">"Unable to resolve spec"</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></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-17" class="fnlink" href="../../#v0.26.3/group/signature/git_signature_default">git_signature_default</a></span><span class="p">(</span><span class="o">&</span><span class="n">tagger</span><span class="p">,</span> <span class="n">repo</span><span class="p">),</span> + <span class="s">"Unable to create signature"</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-22" class="fnlink" href="../../#v0.26.3/group/tag/git_tag_create">git_tag_create</a></span><span class="p">(</span><span class="o">&</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">-></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">-></span><span class="n">message</span><span class="p">,</span> <span class="n">opts</span><span class="o">-></span><span class="n">force</span><span class="p">),</span> <span class="s">"Unable to create tag"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n"><a name="git_object_free-10" class="fnlink" href="../../#v0.26.3/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-18" class="fnlink" href="../../#v0.26.3/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">"usage: see `git help tag`</span><span class="se">\n</span><span class="s">"</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">¶</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="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">&</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"><</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">'-'</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">-></span><span class="n">tag_name</span><span class="p">)</span> + <span class="n">opts</span><span class="o">-></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">-></span><span class="n">target</span><span class="p">)</span> + <span class="n">opts</span><span class="o">-></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">&</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">&</span><span class="n">action_create_lighweight_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">"-n"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">&</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">"-a"</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">&</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">"-f"</span><span class="p">))</span> <span class="p">{</span> + <span class="n">opts</span><span class="o">-></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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">num_lines</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-n"</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">&</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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">pattern</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-l"</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">&</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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">tag_name</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-d"</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">&</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">&</span><span class="n">opts</span><span class="o">-></span><span class="n">message</span><span class="p">,</span> <span class="o">&</span><span class="n">args</span><span class="p">,</span> <span class="s">"-m"</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">&</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">¶</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="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">-></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">-></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">-></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">-></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">-></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">-></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">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> +<span class="p">{</span> + <span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">;</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"><a name="git_libgit2_init-3" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_init">git_libgit2_init</a></span><span class="p">();</span> + + <span class="n">check_lg2</span><span class="p">(</span><span class="n"><a name="git_repository_open_ext-11" class="fnlink" href="../../#v0.26.3/group/repository/git_repository_open_ext">git_repository_open_ext</a></span><span class="p">(</span><span class="o">&</span><span class="n">repo</span><span class="p">,</span> <span class="s">"."</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">"Could not open repository"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> + + <span class="n">tag_options_init</span><span class="p">(</span><span class="o">&</span><span class="n">opts</span><span class="p">);</span> + <span class="n">parse_options</span><span class="p">(</span><span class="o">&</span><span class="n">action</span><span class="p">,</span> <span class="o">&</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">&</span><span class="n">opts</span><span class="p">;</span> + <span class="n">action</span><span class="p">(</span><span class="o">&</span><span class="n">state</span><span class="p">);</span> + + <span class="n"><a name="git_repository_free-12" class="fnlink" href="../../#v0.26.3/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="n"><a name="git_libgit2_shutdown-4" class="fnlink" href="../../#v0.26.3/group/libgit2/git_libgit2_shutdown">git_libgit2_shutdown</a></span><span class="p">();</span> + + <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> +<span class="p">}</span></pre></div> + </td> + </tr> + </table> +</div> +</body> |