|
| 1 | +<!DOCTYPE html> |
| 2 | +<html class="writer-html5" lang="en" > |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel="canonical" href="https://go-git.github.io/docs/concepts/overview/" /> |
| 7 | + <link rel="shortcut icon" href="../../img/favicon.ico" /> |
| 8 | + <title>Overview - go-git Documentation</title> |
| 9 | + <link rel="stylesheet" href="../../css/theme.css" /> |
| 10 | + <link rel="stylesheet" href="../../css/theme_extra.css" /> |
| 11 | + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" /> |
| 12 | + |
| 13 | + <script> |
| 14 | + // Current page data |
| 15 | + var mkdocs_page_name = "Overview"; |
| 16 | + var mkdocs_page_input_path = "concepts/overview.md"; |
| 17 | + var mkdocs_page_url = "/docs/concepts/overview/"; |
| 18 | + </script> |
| 19 | + |
| 20 | + <!--[if lt IE 9]> |
| 21 | + <script src="../../js/html5shiv.min.js"></script> |
| 22 | + <![endif]--> |
| 23 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script> |
| 24 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/go.min.js"></script> |
| 25 | + <script>hljs.highlightAll();</script> |
| 26 | +</head> |
| 27 | + |
| 28 | +<body class="wy-body-for-nav" role="document"> |
| 29 | + |
| 30 | + <div class="wy-grid-for-nav"> |
| 31 | + <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav"> |
| 32 | + <div class="wy-side-scroll"> |
| 33 | + <div class="wy-side-nav-search"> |
| 34 | + <a href="../.." class="icon icon-home"> go-git Documentation |
| 35 | + </a><div role="search"> |
| 36 | + <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get"> |
| 37 | + <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" title="Type search term here" /> |
| 38 | + </form> |
| 39 | +</div> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> |
| 43 | + <ul> |
| 44 | + <li class="toctree-l1"><a class="reference internal" href="../..">Home</a> |
| 45 | + </li> |
| 46 | + </ul> |
| 47 | + <p class="caption"><span class="caption-text">Tutorials</span></p> |
| 48 | + <ul> |
| 49 | + <li class="toctree-l1"><a class="reference internal" href="../../tutorials/getting-started/">Getting Started</a> |
| 50 | + </li> |
| 51 | + <li class="toctree-l1"><a class="reference internal" href="../../tutorials/advanced-usage/">Advanced Usage</a> |
| 52 | + </li> |
| 53 | + <li class="toctree-l1"><a class="reference internal" href="../../tutorials/troubleshooting/">Troubleshooting</a> |
| 54 | + </li> |
| 55 | + <li class="toctree-l1"><a class="reference internal" href="../../tutorials/migrating-from-v5-to-v6/">Migrating to V6</a> |
| 56 | + </li> |
| 57 | + </ul> |
| 58 | + <p class="caption"><span class="caption-text">Concepts</span></p> |
| 59 | + <ul class="current"> |
| 60 | + <li class="toctree-l1 current"><a class="reference internal current" href="#">Overview</a> |
| 61 | + <ul class="current"> |
| 62 | + <li class="toctree-l2"><a class="reference internal" href="#dot-git-storers">Dot Git Storers</a> |
| 63 | + </li> |
| 64 | + <li class="toctree-l2"><a class="reference internal" href="#filesystem">Filesystem</a> |
| 65 | + </li> |
| 66 | + <li class="toctree-l2"><a class="reference internal" href="#transport-schemes">Transport Schemes</a> |
| 67 | + </li> |
| 68 | + <li class="toctree-l2"><a class="reference internal" href="#cache">Cache</a> |
| 69 | + </li> |
| 70 | + <li class="toctree-l2"><a class="reference internal" href="#hash">Hash</a> |
| 71 | + </li> |
| 72 | + </ul> |
| 73 | + </li> |
| 74 | + </ul> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </nav> |
| 78 | + |
| 79 | + <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| 80 | + <nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu"> |
| 81 | + <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| 82 | + <a href="../..">go-git Documentation</a> |
| 83 | + |
| 84 | + </nav> |
| 85 | + <div class="wy-nav-content"> |
| 86 | + <div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation"> |
| 87 | + <ul class="wy-breadcrumbs"> |
| 88 | + <li><a href="../.." class="icon icon-home" aria-label="Docs"></a></li> |
| 89 | + <li class="breadcrumb-item">Concepts</li> |
| 90 | + <li class="breadcrumb-item active">Overview</li> |
| 91 | + <li class="wy-breadcrumbs-aside"> |
| 92 | + <a href="https://github.com/go-git/docs/edit/master/docs/concepts/overview.md" class="icon icon-github"> Edit on GitHub</a> |
| 93 | + </li> |
| 94 | + </ul> |
| 95 | + <hr/> |
| 96 | +</div> |
| 97 | + <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| 98 | + <div class="section" itemprop="articleBody"> |
| 99 | + |
| 100 | + <h1 id="concepts">Concepts</h1> |
| 101 | +<p><code>go-git</code> was built in a highly extensible manner, which enables some of its functionalities to be changed or extended without the need of changing its codebase.</p> |
| 102 | +<p>Here are key concepts that enable that extensibility:</p> |
| 103 | +<h2 id="dot-git-storers">Dot Git Storers</h2> |
| 104 | +<p>Dot git storers are the components responsible for storing the Git internal files, including objects and references.</p> |
| 105 | +<p>The built-in storer implementations include <a href="https://github.com/go-git/go-git/tree/main/storage/memory">memory</a> and <a href="https://github.com/go-git/go-git/tree/main/storage/filesystem">filesystem</a>. The <code>memory</code> storer stores all the data in memory, and its use look like this:</p> |
| 106 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nx">r</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">git</span><span class="p">.</span><span class="nx">Init</span><span class="p">(</span><span class="nx">memory</span><span class="p">.</span><span class="nx">NewStorage</span><span class="p">(),</span><span class="w"> </span><span class="kc">nil</span><span class="p">)</span> |
| 107 | +</code></pre></div> |
| 108 | +<p>The <code>filesystem</code> storer stores the data in the OS filesystem, and can be used as follows:</p> |
| 109 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nx">r</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">git</span><span class="p">.</span><span class="nx">Init</span><span class="p">(</span><span class="nx">filesystem</span><span class="p">.</span><span class="nx">NewStorage</span><span class="p">(</span><span class="nx">osfs</span><span class="p">.</span><span class="nx">New</span><span class="p">(</span><span class="s">"/tmp/foo"</span><span class="p">)),</span><span class="w"> </span><span class="kc">nil</span><span class="p">)</span> |
| 110 | +</code></pre></div> |
| 111 | +<p>New implementations can be created by implementing the <a href="https://github.com/go-git/go-git/tree/main/storage/storer.go#L16">storage.Storer interface</a>.</p> |
| 112 | +<h2 id="filesystem">Filesystem</h2> |
| 113 | +<p>Git repository worktrees are managed using a filesystem abstraction based on <a href="https://github.com/go-git/go-billy">go-billy</a>. The Git operations will take place against the specific filesystem implementation. Initialising a repository in Memory can be done as follows:</p> |
| 114 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nx">fs</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">memfs</span><span class="p">.</span><span class="nx">New</span><span class="p">()</span> |
| 115 | +<span class="w"> </span><span class="nx">r</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">git</span><span class="p">.</span><span class="nx">Init</span><span class="p">(</span><span class="nx">memory</span><span class="p">.</span><span class="nx">NewStorage</span><span class="p">(),</span><span class="w"> </span><span class="nx">fs</span><span class="p">)</span> |
| 116 | +</code></pre></div> |
| 117 | +<p>The same operation can be done against the OS filesystem:</p> |
| 118 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nx">fs</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">osfs</span><span class="p">.</span><span class="nx">New</span><span class="p">(</span><span class="s">"/tmp/foo"</span><span class="p">)</span> |
| 119 | +<span class="w"> </span><span class="nx">r</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">git</span><span class="p">.</span><span class="nx">Init</span><span class="p">(</span><span class="nx">memory</span><span class="p">.</span><span class="nx">NewStorage</span><span class="p">(),</span><span class="w"> </span><span class="nx">fs</span><span class="p">)</span> |
| 120 | +</code></pre></div> |
| 121 | +<p>New filesystems (e.g. cloud based storage) could be created by implementing <code>go-billy</code>'s <a href="https://github.com/go-git/go-billy/blob/326c59f064021b821a55371d57794fbfb86d4cb3/fs.go#L52">Filesystem interface</a>.</p> |
| 122 | +<h2 id="transport-schemes">Transport Schemes</h2> |
| 123 | +<p>Git supports various transport schemes, including <code>http</code>, <code>https</code>, <code>ssh</code>, <code>git</code>, <code>file</code>. <code>go-git</code> defines the <a href="https://github.com/go-git/go-git/tree/main/plumbing/transport/common.go#L48">transport.Transport interface</a> to represent them.</p> |
| 124 | +<p>The built-in implementations can be replaced by calling <code>transport.Register</code>.</p> |
| 125 | +<p>An example of changing the built-in <code>https</code> implementation to skip TLS could look like this:</p> |
| 126 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nx">customClient</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="o">&</span><span class="nx">http</span><span class="p">.</span><span class="nx">Client</span><span class="p">{</span> |
| 127 | +<span class="w"> </span><span class="nx">Transport</span><span class="p">:</span><span class="w"> </span><span class="o">&</span><span class="nx">http</span><span class="p">.</span><span class="nx">Transport</span><span class="p">{</span> |
| 128 | +<span class="w"> </span><span class="nx">TLSClientConfig</span><span class="p">:</span><span class="w"> </span><span class="o">&</span><span class="nx">tls</span><span class="p">.</span><span class="nx">Config</span><span class="p">{</span><span class="nx">InsecureSkipVerify</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">},</span> |
| 129 | +<span class="w"> </span><span class="p">},</span> |
| 130 | +<span class="w"> </span><span class="p">}</span> |
| 131 | + |
| 132 | +<span class="w"> </span><span class="nx">transport</span><span class="p">.</span><span class="nx">Register</span><span class="p">(</span><span class="s">"https"</span><span class="p">,</span><span class="w"> </span><span class="nx">githttp</span><span class="p">.</span><span class="nx">NewClient</span><span class="p">(</span><span class="nx">customClient</span><span class="p">))</span> |
| 133 | +</code></pre></div> |
| 134 | +<p>Some internal implementations enables code reuse amongst the different transport implementations. Some of these may be made public in the future (e.g. <code>plumbing/transport/internal/common</code>).</p> |
| 135 | +<h2 id="cache">Cache</h2> |
| 136 | +<p>Several different operations across <code>go-git</code> lean on caching of objects in order to achieve optimal performance. The caching functionality is defined by the <a href="https://github.com/go-git/go-git/tree/main/plumbing/cache/common.go#L17">cache.Object interface</a>.</p> |
| 137 | +<p>Two built-in implementations are <code>cache.ObjectLRU</code> and <code>cache.BufferLRU</code>. However, the caching functionality can be customized by implementing the interface <code>cache.Object</code> interface.</p> |
| 138 | +<h2 id="hash">Hash</h2> |
| 139 | +<p><code>go-git</code> uses the <code>crypto.Hash</code> interface to represent hash functions. The built-in implementations are <code>github.com/pjbgf/sha1cd</code> for SHA1 and Go's <code>crypto/SHA256</code>.</p> |
| 140 | +<p>The default hash functions can be changed by calling <code>hash.RegisterHash</code>. |
| 141 | +<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="kd">func</span><span class="w"> </span><span class="nx">init</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> |
| 142 | +<span class="w"> </span><span class="nx">hash</span><span class="p">.</span><span class="nx">RegisterHash</span><span class="p">(</span><span class="nx">crypto</span><span class="p">.</span><span class="nx">SHA1</span><span class="p">,</span><span class="w"> </span><span class="nx">sha1</span><span class="p">.</span><span class="nx">New</span><span class="p">)</span> |
| 143 | +<span class="w"> </span><span class="p">}</span> |
| 144 | +</code></pre></div></p> |
| 145 | +<p>New <code>SHA1</code> or <code>SHA256</code> hash functions that implement the <code>hash.RegisterHash</code> interface can be registered by calling <code>RegisterHash</code>.</p> |
| 146 | + |
| 147 | + </div> |
| 148 | + </div><footer> |
| 149 | + <div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation"> |
| 150 | + <a href="../../tutorials/migrating-from-v5-to-v6/" class="btn btn-neutral float-left" title="Migrating to V6"><span class="icon icon-circle-arrow-left"></span> Previous</a> |
| 151 | + </div> |
| 152 | + |
| 153 | + <hr/> |
| 154 | + |
| 155 | + <div role="contentinfo"> |
| 156 | + <!-- Copyright etc --> |
| 157 | + </div> |
| 158 | + |
| 159 | + Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. |
| 160 | +</footer> |
| 161 | + |
| 162 | + </div> |
| 163 | + </div> |
| 164 | + |
| 165 | + </section> |
| 166 | + |
| 167 | + </div> |
| 168 | + |
| 169 | + <div class="rst-versions" role="note" aria-label="Versions"> |
| 170 | + <span class="rst-current-version" data-toggle="rst-current-version"> |
| 171 | + |
| 172 | + <span> |
| 173 | + <a href="https://github.com/go-git/docs" class="fa fa-github" style="color: #fcfcfc"> GitHub</a> |
| 174 | + </span> |
| 175 | + |
| 176 | + |
| 177 | + <span><a href="../../tutorials/migrating-from-v5-to-v6/" style="color: #fcfcfc">« Previous</a></span> |
| 178 | + |
| 179 | + |
| 180 | + </span> |
| 181 | +</div> |
| 182 | + <script src="../../js/jquery-3.6.0.min.js"></script> |
| 183 | + <script>var base_url = "../..";</script> |
| 184 | + <script src="../../js/theme_extra.js"></script> |
| 185 | + <script src="../../js/theme.js"></script> |
| 186 | + <script src="../../search/main.js"></script> |
| 187 | + <script> |
| 188 | + jQuery(function () { |
| 189 | + SphinxRtdTheme.Navigation.enable(true); |
| 190 | + }); |
| 191 | + </script> |
| 192 | + |
| 193 | +</body> |
| 194 | +</html> |
0 commit comments