|
<!DOCTYPE html> |
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
|
<head> |
|
<meta charset="UTF-8"/> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
|
<meta name="generator" content="Asciidoctor 2.0.17"/> |
|
<title>My First Object Walk</title> |
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"/> |
|
<style> |
|
|
|
|
|
|
|
html{font-family:sans-serif;-webkit-text-size-adjust:100%} |
|
a{background:none} |
|
a:focus{outline:thin dotted} |
|
a:active,a:hover{outline:0} |
|
h1{font-size:2em;margin:.67em 0} |
|
b,strong{font-weight:bold} |
|
abbr{font-size:.9em} |
|
abbr[title]{cursor:help;border-bottom:1px dotted #dddddf;text-decoration:none} |
|
dfn{font-style:italic} |
|
hr{height:0} |
|
mark{background:#ff0;color:#000} |
|
code,kbd,pre,samp{font-family:monospace;font-size:1em} |
|
pre{white-space:pre-wrap} |
|
q{quotes:"\201C" "\201D" "\2018" "\2019"} |
|
small{font-size:80%} |
|
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline} |
|
sup{top:-.5em} |
|
sub{bottom:-.25em} |
|
img{border:0} |
|
svg:not(:root){overflow:hidden} |
|
figure{margin:0} |
|
audio,video{display:inline-block} |
|
audio:not([controls]){display:none;height:0} |
|
fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em} |
|
legend{border:0;padding:0} |
|
button,input,select,textarea{font-family:inherit;font-size:100%;margin:0} |
|
button,input{line-height:normal} |
|
button,select{text-transform:none} |
|
button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer} |
|
button[disabled],html input[disabled]{cursor:default} |
|
input[type=checkbox],input[type=radio]{padding:0} |
|
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0} |
|
textarea{overflow:auto;vertical-align:top} |
|
table{border-collapse:collapse;border-spacing:0} |
|
*,::before,::after{box-sizing:border-box} |
|
html,body{font-size:100%} |
|
body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;line-height:1;position:relative;cursor:auto;-moz-tab-size:4;-o-tab-size:4;tab-size:4;word-wrap:anywhere;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased} |
|
a:hover{cursor:pointer} |
|
img,object,embed{max-width:100%;height:auto} |
|
object,embed{height:100%} |
|
img{-ms-interpolation-mode:bicubic} |
|
.left{float:left!important} |
|
.right{float:right!important} |
|
.text-left{text-align:left!important} |
|
.text-right{text-align:right!important} |
|
.text-center{text-align:center!important} |
|
.text-justify{text-align:justify!important} |
|
.hide{display:none} |
|
img,object,svg{display:inline-block;vertical-align:middle} |
|
textarea{height:auto;min-height:50px} |
|
select{width:100%} |
|
.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em} |
|
div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0} |
|
a{color:#2156a5;text-decoration:underline;line-height:inherit} |
|
a:hover,a:focus{color:#1d4b8f} |
|
a img{border:0} |
|
p{line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility} |
|
p aside{font-size:.875em;line-height:1.35;font-style:italic} |
|
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em} |
|
h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0} |
|
h1{font-size:2.125em} |
|
h2{font-size:1.6875em} |
|
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em} |
|
h4,h5{font-size:1.125em} |
|
h6{font-size:1em} |
|
hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em} |
|
em,i{font-style:italic;line-height:inherit} |
|
strong,b{font-weight:bold;line-height:inherit} |
|
small{font-size:60%;line-height:inherit} |
|
code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)} |
|
ul,ol,dl{line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit} |
|
ul,ol{margin-left:1.5em} |
|
ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0} |
|
ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit} |
|
ul.square{list-style-type:square} |
|
ul.circle{list-style-type:circle} |
|
ul.disc{list-style-type:disc} |
|
ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0} |
|
dl dt{margin-bottom:.3125em;font-weight:bold} |
|
dl dd{margin-bottom:1.25em} |
|
blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd} |
|
blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)} |
|
@media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2} |
|
h1{font-size:2.75em} |
|
h2{font-size:2.3125em} |
|
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em} |
|
h4{font-size:1.4375em}} |
|
table{background:#fff;margin-bottom:1.25em;border:1px solid #dedede;word-wrap:normal} |
|
table thead,table tfoot{background:#f7f8f7} |
|
table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left} |
|
table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)} |
|
table tr.even,table tr.alt{background:#f8f8f7} |
|
table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{line-height:1.6} |
|
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em} |
|
h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400} |
|
.center{margin-left:auto;margin-right:auto} |
|
.stretch{width:100%} |
|
.clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table} |
|
.clearfix::after,.float-group::after{clear:both} |
|
:not(pre).nobreak{word-wrap:normal} |
|
:not(pre).nowrap{white-space:nowrap} |
|
:not(pre).pre-wrap{white-space:pre-wrap} |
|
:not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed} |
|
pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed} |
|
pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit} |
|
pre>code{display:block} |
|
pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal} |
|
em em{font-style:normal} |
|
strong strong{font-weight:400} |
|
.keyseq{color:rgba(51,51,51,.8)} |
|
kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;border-radius:3px;box-shadow:0 1px 0 rgba(0,0,0,.2),inset 0 0 0 .1em #fff;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap} |
|
.keyseq kbd:first-child{margin-left:0} |
|
.keyseq kbd:last-child{margin-right:0} |
|
.menuseq,.menuref{color:#000} |
|
.menuseq b:not(.caret),.menuref{font-weight:inherit} |
|
.menuseq{word-spacing:-.02em} |
|
.menuseq b.caret{font-size:1.25em;line-height:.8} |
|
.menuseq i.caret{font-weight:bold;text-align:center;width:.45em} |
|
b.button::before,b.button::after{position:relative;top:-1px;font-weight:400} |
|
b.button::before{content:"[";padding:0 3px 0 2px} |
|
b.button::after{content:"]";padding:0 2px 0 3px} |
|
p a>code:hover{color:rgba(0,0,0,.9)} |
|
#header,#content,#footnotes,#footer{width:100%;margin:0 auto;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em} |
|
#header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table} |
|
#header::after,#content::after,#footnotes::after,#footer::after{clear:both} |
|
#content{margin-top:1.25em} |
|
#content::before{content:none} |
|
#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0} |
|
#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf} |
|
#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px} |
|
#header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap} |
|
#header .details span:first-child{margin-left:-.125em} |
|
#header .details span.email a{color:rgba(0,0,0,.85)} |
|
#header .details br{display:none} |
|
#header .details br+span::before{content:"\00a0\2013\00a0"} |
|
#header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)} |
|
#header .details br+span#revremark::before{content:"\00a0|\00a0"} |
|
#header #revnumber{text-transform:capitalize} |
|
#header #revnumber::after{content:"\00a0"} |
|
#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem} |
|
#toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em} |
|
#toc>ul{margin-left:.125em} |
|
#toc ul.sectlevel0>li>a{font-style:italic} |
|
#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0} |
|
#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none} |
|
#toc li{line-height:1.3334;margin-top:.3334em} |
|
#toc a{text-decoration:none} |
|
#toc a:active{text-decoration:underline} |
|
#toctitle{color:#7a2518;font-size:1.2em} |
|
@media screen and (min-width:768px){#toctitle{font-size:1.375em} |
|
body.toc2{padding-left:15em;padding-right:0} |
|
#toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto} |
|
#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em} |
|
#toc.toc2>ul{font-size:.9em;margin-bottom:0} |
|
#toc.toc2 ul ul{margin-left:0;padding-left:1em} |
|
#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em} |
|
body.toc2.toc-right{padding-left:0;padding-right:15em} |
|
body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}} |
|
@media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0} |
|
#toc.toc2{width:20em} |
|
#toc.toc2 #toctitle{font-size:1.375em} |
|
#toc.toc2>ul{font-size:.95em} |
|
#toc.toc2 ul ul{padding-left:1.25em} |
|
body.toc2.toc-right{padding-left:0;padding-right:20em}} |
|
#content #toc{border:1px solid #e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;border-radius:4px} |
|
#content #toc>:first-child{margin-top:0} |
|
#content #toc>:last-child{margin-bottom:0} |
|
#footer{max-width:none;background:rgba(0,0,0,.8);padding:1.25em} |
|
#footer-text{color:hsla(0,0%,100%,.8);line-height:1.44} |
|
#content{margin-bottom:.625em} |
|
.sect1{padding-bottom:.625em} |
|
@media screen and (min-width:768px){#content{margin-bottom:1.25em} |
|
.sect1{padding-bottom:1.25em}} |
|
.sect1:last-child{padding-bottom:0} |
|
.sect1+.sect1{border-top:1px solid #e7e7e9} |
|
#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400} |
|
#content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em} |
|
#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible} |
|
#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none} |
|
#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221} |
|
details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em} |
|
details{margin-left:1.25rem} |
|
details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent} |
|
details>summary::-webkit-details-marker{display:none} |
|
details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)} |
|
details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)} |
|
details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem} |
|
.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic} |
|
table.tableblock.fit-content>caption.title{white-space:nowrap;width:0} |
|
.paragraph.lead>p,#preamble>.sectionbody>[class=paragraph]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)} |
|
.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%} |
|
.admonitionblock>table td.icon{text-align:center;width:80px} |
|
.admonitionblock>table td.icon img{max-width:none} |
|
.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase} |
|
.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6);word-wrap:anywhere} |
|
.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0} |
|
.exampleblock>.content{border:1px solid #e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;border-radius:4px} |
|
.exampleblock>.content>:first-child{margin-top:0} |
|
.exampleblock>.content>:last-child{margin-bottom:0} |
|
.sidebarblock{border:1px solid #dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;border-radius:4px} |
|
.sidebarblock>:first-child{margin-top:0} |
|
.sidebarblock>:last-child{margin-bottom:0} |
|
.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center} |
|
.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0} |
|
.literalblock pre,.listingblock>.content>pre{border-radius:4px;overflow-x:auto;padding:1em;font-size:.8125em} |
|
@media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}} |
|
@media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}} |
|
.literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class=highlight],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8} |
|
.literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)} |
|
.listingblock>.content{position:relative} |
|
.listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5} |
|
.listingblock:hover code[data-lang]::before{display:block} |
|
.listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5} |
|
.listingblock.terminal pre .command:not([data-prompt])::before{content:"$"} |
|
.listingblock pre.highlightjs{padding:0} |
|
.listingblock pre.highlightjs>code{padding:1em;border-radius:4px} |
|
.listingblock pre.prettyprint{border-width:0} |
|
.prettyprint{background:#f7f7f8} |
|
pre.prettyprint .linenums{line-height:1.45;margin-left:2em} |
|
pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0} |
|
pre.prettyprint li code[data-lang]::before{opacity:1} |
|
pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none} |
|
table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none} |
|
table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal} |
|
table.linenotable td.code{padding-left:.75em} |
|
table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} |
|
pre.pygments span.linenos{display:inline-block;margin-right:.75em} |
|
.quoteblock{margin:0 1em 1.25em 1.5em;display:table} |
|
.quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em} |
|
.quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify} |
|
.quoteblock blockquote{margin:0;padding:0;border:0} |
|
.quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)} |
|
.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0} |
|
.quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right} |
|
.verseblock{margin:0 1em 1.25em} |
|
.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans-serif;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility} |
|
.verseblock pre strong{font-weight:400} |
|
.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex} |
|
.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic} |
|
.quoteblock .attribution br,.verseblock .attribution br{display:none} |
|
.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)} |
|
.quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none} |
|
.quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0} |
|
.quoteblock.abstract{margin:0 1em 1.25em;display:block} |
|
.quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center} |
|
.quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf} |
|
.quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0} |
|
.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem} |
|
.quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;font-size:.85rem;text-align:left;margin-right:0} |
|
p.tableblock:last-child{margin-bottom:0} |
|
td.tableblock>.content{margin-bottom:1.25em;word-wrap:anywhere} |
|
td.tableblock>.content>:last-child{margin-bottom:-1.25em} |
|
table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede} |
|
table.grid-all>*>tr>*{border-width:1px} |
|
table.grid-cols>*>tr>*{border-width:0 1px} |
|
table.grid-rows>*>tr>*{border-width:1px 0} |
|
table.frame-all{border-width:1px} |
|
table.frame-ends{border-width:1px 0} |
|
table.frame-sides{border-width:0 1px} |
|
table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-child>*{border-top-width:0} |
|
table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0} |
|
table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0} |
|
table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0} |
|
table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7} |
|
th.halign-left,td.halign-left{text-align:left} |
|
th.halign-right,td.halign-right{text-align:right} |
|
th.halign-center,td.halign-center{text-align:center} |
|
th.valign-top,td.valign-top{vertical-align:top} |
|
th.valign-bottom,td.valign-bottom{vertical-align:bottom} |
|
th.valign-middle,td.valign-middle{vertical-align:middle} |
|
table thead th,table tfoot th{font-weight:bold} |
|
tbody tr th{background:#f7f8f7} |
|
tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold} |
|
p.tableblock>code:only-child{background:none;padding:0} |
|
p.tableblock{font-size:1em} |
|
ol{margin-left:1.75em} |
|
ul li ol{margin-left:1.5em} |
|
dl dd{margin-left:1.125em} |
|
dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0} |
|
li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} |
|
ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none} |
|
ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em} |
|
ul.unstyled,ol.unstyled{margin-left:0} |
|
li>p:empty:only-child::before{content:"";display:inline-block} |
|
ul.checklist>li>p:first-child{margin-left:-1em} |
|
ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em} |
|
ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em} |
|
ul.inline{display:flex;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em} |
|
ul.inline>li{margin-left:1.25em} |
|
.unstyled dl dt{font-weight:400;font-style:normal} |
|
ol.arabic{list-style-type:decimal} |
|
ol.decimal{list-style-type:decimal-leading-zero} |
|
ol.loweralpha{list-style-type:lower-alpha} |
|
ol.upperalpha{list-style-type:upper-alpha} |
|
ol.lowerroman{list-style-type:lower-roman} |
|
ol.upperroman{list-style-type:upper-roman} |
|
ol.lowergreek{list-style-type:lower-greek} |
|
.hdlist>table,.colist>table{border:0;background:none} |
|
.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none} |
|
td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em} |
|
td.hdlist1{font-weight:bold;padding-bottom:1.25em} |
|
td.hdlist2{word-wrap:anywhere} |
|
.literalblock+.colist,.listingblock+.colist{margin-top:-.5em} |
|
.colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top} |
|
.colist td:not([class]):first-child img{max-width:none} |
|
.colist td:not([class]):last-child{padding:.25em 0} |
|
.thumb,.th{line-height:0;display:inline-block;border:4px solid #fff;box-shadow:0 0 0 1px #ddd} |
|
.imageblock.left{margin:.25em .625em 1.25em 0} |
|
.imageblock.right{margin:.25em 0 1.25em .625em} |
|
.imageblock>.title{margin-bottom:0} |
|
.imageblock.thumb,.imageblock.th{border-width:6px} |
|
.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em} |
|
.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0} |
|
.image.left{margin-right:.625em} |
|
.image.right{margin-left:.625em} |
|
a.image{text-decoration:none;display:inline-block} |
|
a.image object{pointer-events:none} |
|
sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super} |
|
sup.footnote a,sup.footnoteref a{text-decoration:none} |
|
sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline} |
|
#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em} |
|
#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0} |
|
#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em} |
|
#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em} |
|
#footnotes .footnote:last-of-type{margin-bottom:0} |
|
#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0} |
|
div.unbreakable{page-break-inside:avoid} |
|
.big{font-size:larger} |
|
.small{font-size:smaller} |
|
.underline{text-decoration:underline} |
|
.overline{text-decoration:overline} |
|
.line-through{text-decoration:line-through} |
|
.aqua{color:#00bfbf} |
|
.aqua-background{background:#00fafa} |
|
.black{color:#000} |
|
.black-background{background:#000} |
|
.blue{color:#0000bf} |
|
.blue-background{background:#0000fa} |
|
.fuchsia{color:#bf00bf} |
|
.fuchsia-background{background:#fa00fa} |
|
.gray{color:#606060} |
|
.gray-background{background:#7d7d7d} |
|
.green{color:#006000} |
|
.green-background{background:#007d00} |
|
.lime{color:#00bf00} |
|
.lime-background{background:#00fa00} |
|
.maroon{color:#600000} |
|
.maroon-background{background:#7d0000} |
|
.navy{color:#000060} |
|
.navy-background{background:#00007d} |
|
.olive{color:#606000} |
|
.olive-background{background:#7d7d00} |
|
.purple{color:#600060} |
|
.purple-background{background:#7d007d} |
|
.red{color:#bf0000} |
|
.red-background{background:#fa0000} |
|
.silver{color:#909090} |
|
.silver-background{background:#bcbcbc} |
|
.teal{color:#006060} |
|
.teal-background{background:#007d7d} |
|
.white{color:#bfbfbf} |
|
.white-background{background:#fafafa} |
|
.yellow{color:#bfbf00} |
|
.yellow-background{background:#fafa00} |
|
span.icon>.fa{cursor:default} |
|
a span.icon>.fa{cursor:inherit} |
|
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default} |
|
.admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c} |
|
.admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111} |
|
.admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900} |
|
.admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400} |
|
.admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000} |
|
.conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);border-radius:50%;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold} |
|
.conum[data-value] *{color:#fff!important} |
|
.conum[data-value]+b{display:none} |
|
.conum[data-value]::after{content:attr(data-value)} |
|
pre .conum[data-value]{position:relative;top:-.125em} |
|
b.conum *{color:inherit!important} |
|
.conum:not([data-value]):empty{display:none} |
|
dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility} |
|
h1,h2,p,td.content,span.alt,summary{letter-spacing:-.01em} |
|
p strong,td.content strong,div.footnote strong{letter-spacing:-.005em} |
|
p,blockquote,dt,td.content,span.alt,summary{font-size:1.0625rem} |
|
p{margin-bottom:1.25rem} |
|
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em} |
|
.exampleblock>.content{background:#fffef7;border-color:#e0e0dc;box-shadow:0 1px 4px #e0e0dc} |
|
.print-only{display:none!important} |
|
@page{margin:1.25cm .75cm} |
|
@media print{*{box-shadow:none!important;text-shadow:none!important} |
|
html{font-size:80%} |
|
a{color:inherit!important;text-decoration:underline!important} |
|
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important} |
|
a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em} |
|
abbr[title]{border-bottom:1px dotted} |
|
abbr[title]::after{content:" (" attr(title) ")"} |
|
pre,blockquote,tr,img,object,svg{page-break-inside:avoid} |
|
thead{display:table-header-group} |
|
svg{max-width:100%} |
|
p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3} |
|
h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid} |
|
#header,#content,#footnotes,#footer{max-width:none} |
|
#toc,.sidebarblock,.exampleblock>.content{background:none!important} |
|
#toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important} |
|
body.book #header{text-align:center} |
|
body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em} |
|
body.book #header .details{border:0!important;display:block;padding:0!important} |
|
body.book #header .details span:first-child{margin-left:0!important} |
|
body.book #header .details br{display:block} |
|
body.book #header .details br+span::before{content:none!important} |
|
body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important} |
|
body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always} |
|
.listingblock code[data-lang]::before{display:block} |
|
#footer{padding:0 .9375em} |
|
.hide-on-print{display:none!important} |
|
.print-only{display:block!important} |
|
.hide-for-print{display:none!important} |
|
.show-for-print{display:inherit!important}} |
|
@media amzn-kf8,print{#header>h1:first-child{margin-top:1.25rem} |
|
.sect1{padding:0!important} |
|
.sect1+.sect1{border:0} |
|
#footer{background:none} |
|
#footer-text{color:rgba(0,0,0,.6);font-size:.9em}} |
|
@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}} |
|
</style> |
|
</head> |
|
<body class="article"> |
|
<div id="header"> |
|
<h1>My First Object Walk</h1> |
|
</div> |
|
<div id="content"> |
|
<div class="sect1"> |
|
<h2 id="_whats_an_object_walk">What’s an Object Walk?</h2> |
|
<div class="sectionbody"> |
|
<div class="paragraph"> |
|
<p>The object walk is a key concept in Git - this is the process that underpins |
|
operations like object transfer and fsck. Beginning from a given commit, the |
|
list of objects is found by walking parent relationships between commits (commit |
|
X based on commit W) and containment relationships between objects (tree Y is |
|
contained within commit X, and blob Z is located within tree Y, giving our |
|
working tree for commit X something like <code>y/z.txt</code>).</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>A related concept is the revision walk, which is focused on commit objects and |
|
their parent relationships and does not delve into other object types. The |
|
revision walk is used for operations like <code>git log</code>.</p> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_related_reading">Related Reading</h3> |
|
<div class="ulist"> |
|
<ul> |
|
<li> |
|
<p><code>Documentation/user-manual.txt</code> under "Hacking Git" contains some coverage of |
|
the revision walker in its various incarnations.</p> |
|
</li> |
|
<li> |
|
<p><code>revision.h</code></p> |
|
</li> |
|
<li> |
|
<p><a href="https://eagain.net/articles/git-for-computer-scientists/">Git for Computer Scientists</a> |
|
gives a good overview of the types of objects in Git and what your object |
|
walk is really describing.</p> |
|
</li> |
|
</ul> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect1"> |
|
<h2 id="_setting_up">Setting Up</h2> |
|
<div class="sectionbody"> |
|
<div class="paragraph"> |
|
<p>Create a new branch from <code>master</code>.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>git checkout -b revwalk origin/master</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>We’ll put our fiddling into a new command. For fun, let’s name it <code>git walken</code>. |
|
Open up a new file <code>builtin/walken.c</code> and set up the command handler:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>/* |
|
* "git walken" |
|
* |
|
* Part of the "My First Object Walk" tutorial. |
|
*/ |
|
|
|
#include "builtin.h" |
|
|
|
int cmd_walken(int argc, const char **argv, const char *prefix) |
|
{ |
|
trace_printf(_("cmd_walken incoming...\n")); |
|
return 0; |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
<code>trace_printf()</code> differs from <code>printf()</code> in that it can be turned on or |
|
off at runtime. For the purposes of this tutorial, we will write <code>walken</code> as |
|
though it is intended for use as a "plumbing" command: that is, a command which |
|
is used primarily in scripts, rather than interactively by humans (a "porcelain" |
|
command). So we will send our debug output to <code>trace_printf()</code> instead. When |
|
running, enable trace output by setting the environment variable <code>GIT_TRACE</code>. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Add usage text and <code>-h</code> handling, like all subcommands should consistently do |
|
(our test suite will notice and complain if you fail to do so). |
|
We’ll need to include the <code>parse-options.h</code> header.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>#include "parse-options.h" |
|
|
|
... |
|
|
|
int cmd_walken(int argc, const char **argv, const char *prefix) |
|
{ |
|
const char * const walken_usage[] = { |
|
N_("git walken"), |
|
NULL, |
|
}; |
|
struct option options[] = { |
|
OPT_END() |
|
}; |
|
|
|
argc = parse_options(argc, argv, prefix, options, walken_usage, 0); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Also add the relevant line in <code>builtin.h</code> near <code>cmd_whatchanged()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>int cmd_walken(int argc, const char **argv, const char *prefix);</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Include the command in <code>git.c</code> in <code>commands[]</code> near the entry for <code>whatchanged</code>, |
|
maintaining alphabetical ordering:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>{ "walken", cmd_walken, RUN_SETUP },</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Add it to the <code>Makefile</code> near the line for <code>builtin/worktree.o</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>BUILTIN_OBJS += builtin/walken.o</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Build and test out your command, without forgetting to ensure the <code>DEVELOPER</code> |
|
flag is set, and with <code>GIT_TRACE</code> enabled so the debug output can be seen:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ echo DEVELOPER=1 >>config.mak |
|
$ make |
|
$ GIT_TRACE=1 ./bin-wrappers/git walken</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
For a more exhaustive overview of the new command process, take a look at |
|
<code>Documentation/MyFirstContribution.txt</code>. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
A reference implementation can be found at |
|
<a href="https://github.com/nasamuffin/git/tree/revwalk" class="bare">https://github.com/nasamuffin/git/tree/revwalk</a>. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_struct_rev_cmdline_info"><code>struct rev_cmdline_info</code></h3> |
|
<div class="paragraph"> |
|
<p>The definition of <code>struct rev_cmdline_info</code> can be found in <code>revision.h</code>.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>This struct is contained within the <code>rev_info</code> struct and is used to reflect |
|
parameters provided by the user over the CLI.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>nr</code> represents the number of <code>rev_cmdline_entry</code> present in the array.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>alloc</code> is used by the <code>ALLOC_GROW</code> macro. Check <code>cache.h</code> - this variable is |
|
used to track the allocated size of the list.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Per entry, we find:</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>item</code> is the object provided upon which to base the object walk. Items in Git |
|
can be blobs, trees, commits, or tags. (See <code>Documentation/gittutorial-2.txt</code>.)</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>name</code> is the object ID (OID) of the object - a hex string you may be familiar |
|
with from using Git to organize your source in the past. Check the tutorial |
|
mentioned above towards the top for a discussion of where the OID can come |
|
from.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>whence</code> indicates some information about what to do with the parents of the |
|
specified object. We’ll explore this flag more later on; take a look at |
|
<code>Documentation/revisions.txt</code> to get an idea of what could set the <code>whence</code> |
|
value.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>flags</code> are used to hint the beginning of the revision walk and are the first |
|
block under the <code>#include`s in `revision.h</code>. The most likely ones to be set in |
|
the <code>rev_cmdline_info</code> are <code>UNINTERESTING</code> and <code>BOTTOM</code>, but these same flags |
|
can be used during the walk, as well.</p> |
|
</div> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_struct_rev_info"><code>struct rev_info</code></h3> |
|
<div class="paragraph"> |
|
<p>This one is quite a bit longer, and many fields are only used during the walk |
|
by <code>revision.c</code> - not configuration options. Most of the configurable flags in |
|
<code>struct rev_info</code> have a mirror in <code>Documentation/rev-list-options.txt</code>. It’s a |
|
good idea to take some time and read through that document.</p> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect1"> |
|
<h2 id="_basic_commit_walk">Basic Commit Walk</h2> |
|
<div class="sectionbody"> |
|
<div class="paragraph"> |
|
<p>First, let’s see if we can replicate the output of <code>git log --oneline</code>. We’ll |
|
refer back to the implementation frequently to discover norms when performing |
|
an object walk of our own.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>To do so, we’ll first find all the commits, in order, which preceded the current |
|
commit. We’ll extract the name and subject of the commit from each.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Ideally, we will also be able to find out which ones are currently at the tip of |
|
various branches.</p> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_setting_up_2">Setting Up</h3> |
|
<div class="paragraph"> |
|
<p>Preparing for your object walk has some distinct stages.</p> |
|
</div> |
|
<div class="olist arabic"> |
|
<ol class="arabic"> |
|
<li> |
|
<p>Perform default setup for this mode, and others which may be invoked.</p> |
|
</li> |
|
<li> |
|
<p>Check configuration files for relevant settings.</p> |
|
</li> |
|
<li> |
|
<p>Set up the <code>rev_info</code> struct.</p> |
|
</li> |
|
<li> |
|
<p>Tweak the initialized <code>rev_info</code> to suit the current walk.</p> |
|
</li> |
|
<li> |
|
<p>Prepare the <code>rev_info</code> for the walk.</p> |
|
</li> |
|
<li> |
|
<p>Iterate over the objects, processing each one.</p> |
|
</li> |
|
</ol> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_default_setups">Default Setups</h4> |
|
<div class="paragraph"> |
|
<p>Before examining configuration files which may modify command behavior, set up |
|
default state for switches or options your command may have. If your command |
|
utilizes other Git components, ask them to set up their default states as well. |
|
For instance, <code>git log</code> takes advantage of <code>grep</code> and <code>diff</code> functionality, so |
|
its <code>init_log_defaults()</code> sets its own state (<code>decoration_style</code>) and asks |
|
<code>grep</code> and <code>diff</code> to initialize themselves by calling each of their |
|
initialization functions.</p> |
|
</div> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_configuring_from_gitconfig">Configuring From <code>.gitconfig</code></h4> |
|
<div class="paragraph"> |
|
<p>Next, we should have a look at any relevant configuration settings (i.e., |
|
settings readable and settable from <code>git config</code>). This is done by providing a |
|
callback to <code>git_config()</code>; within that callback, you can also invoke methods |
|
from other components you may need that need to intercept these options. Your |
|
callback will be invoked once per each configuration value which Git knows about |
|
(global, local, worktree, etc.).</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Similarly to the default values, we don’t have anything to do here yet |
|
ourselves; however, we should call <code>git_default_config()</code> if we aren’t calling |
|
any other existing config callbacks.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Add a new function to <code>builtin/walken.c</code>. |
|
We’ll also need to include the <code>config.h</code> header:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>#include "config.h" |
|
|
|
... |
|
|
|
static int git_walken_config(const char *var, const char *value, void *cb) |
|
{ |
|
/* |
|
* For now, we don't have any custom configuration, so fall back to |
|
* the default config. |
|
*/ |
|
return git_default_config(var, value, cb); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Make sure to invoke <code>git_config()</code> with it in your <code>cmd_walken()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>int cmd_walken(int argc, const char **argv, const char *prefix) |
|
{ |
|
... |
|
|
|
git_config(git_walken_config, NULL); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_setting_up_rev_info">Setting Up <code>rev_info</code></h4> |
|
<div class="paragraph"> |
|
<p>Now that we’ve gathered external configuration and options, it’s time to |
|
initialize the <code>rev_info</code> object which we will use to perform the walk. This is |
|
typically done by calling <code>repo_init_revisions()</code> with the repository you intend |
|
to target, as well as the <code>prefix</code> argument of <code>cmd_walken</code> and your <code>rev_info</code> |
|
struct.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Add the <code>struct rev_info</code> and the <code>repo_init_revisions()</code> call. |
|
We’ll also need to include the <code>revision.h</code> header:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>#include "revision.h" |
|
|
|
... |
|
|
|
int cmd_walken(int argc, const char **argv, const char *prefix) |
|
{ |
|
/* This can go wherever you like in your declarations.*/ |
|
struct rev_info rev; |
|
... |
|
|
|
/* This should go after the git_config() call. */ |
|
repo_init_revisions(the_repository, &rev, prefix); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_tweaking_rev_info_for_the_walk">Tweaking <code>rev_info</code> For the Walk</h4> |
|
<div class="paragraph"> |
|
<p>We’re getting close, but we’re still not quite ready to go. Now that <code>rev</code> is |
|
initialized, we can modify it to fit our needs. This is usually done within a |
|
helper for clarity, so let’s add one:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void final_rev_info_setup(struct rev_info *rev) |
|
{ |
|
/* |
|
* We want to mimic the appearance of `git log --oneline`, so let's |
|
* force oneline format. |
|
*/ |
|
get_commit_format("oneline", rev); |
|
|
|
/* Start our object walk at HEAD. */ |
|
add_head_to_pending(rev); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
<div class="paragraph"> |
|
<p>Instead of using the shorthand <code>add_head_to_pending()</code>, you could do |
|
something like this:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> struct setup_revision_opt opt; |
|
|
|
memset(&opt, 0, sizeof(opt)); |
|
opt.def = "HEAD"; |
|
opt.revarg_opt = REVARG_COMMITTISH; |
|
setup_revisions(argc, argv, rev, &opt);</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Using a <code>setup_revision_opt</code> gives you finer control over your walk’s starting |
|
point.</p> |
|
</div> |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Then let’s invoke <code>final_rev_info_setup()</code> after the call to |
|
<code>repo_init_revisions()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>int cmd_walken(int argc, const char **argv, const char *prefix) |
|
{ |
|
... |
|
|
|
final_rev_info_setup(&rev); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Later, we may wish to add more arguments to <code>final_rev_info_setup()</code>. But for |
|
now, this is all we need.</p> |
|
</div> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_preparing_rev_info_for_the_walk">Preparing <code>rev_info</code> For the Walk</h4> |
|
<div class="paragraph"> |
|
<p>Now that <code>rev</code> is all initialized and configured, we’ve got one more setup step |
|
before we get rolling. We can do this in a helper, which will both prepare the |
|
<code>rev_info</code> for the walk, and perform the walk itself. Let’s start the helper |
|
with the call to <code>prepare_revision_walk()</code>, which can return an error without |
|
dying on its own:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_commit_walk(struct rev_info *rev) |
|
{ |
|
if (prepare_revision_walk(rev)) |
|
die(_("revision walk setup failed")); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
<code>die()</code> prints to <code>stderr</code> and exits the program. Since it will print to |
|
<code>stderr</code> it’s likely to be seen by a human, so we will localize it. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
</div> |
|
<div class="sect3"> |
|
<h4 id="_performing_the_walk">Performing the Walk!</h4> |
|
<div class="paragraph"> |
|
<p>Finally! We are ready to begin the walk itself. Now we can see that <code>rev_info</code> |
|
can also be used as an iterator; we move to the next item in the walk by using |
|
<code>get_revision()</code> repeatedly. Add the listed variable declarations at the top and |
|
the walk loop below the <code>prepare_revision_walk()</code> call within your |
|
<code>walken_commit_walk()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_commit_walk(struct rev_info *rev) |
|
{ |
|
struct commit *commit; |
|
struct strbuf prettybuf = STRBUF_INIT; |
|
|
|
... |
|
|
|
while ((commit = get_revision(rev))) { |
|
strbuf_reset(&prettybuf); |
|
pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf); |
|
puts(prettybuf.buf); |
|
} |
|
strbuf_release(&prettybuf); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
<code>puts()</code> prints a <code>char*</code> to <code>stdout</code>. Since this is the part of the |
|
command we expect to be machine-parsed, we’re sending it directly to stdout. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Give it a shot.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ make |
|
$ ./bin-wrappers/git walken</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>You should see all of the subject lines of all the commits in |
|
your tree’s history, in order, ending with the initial commit, "Initial revision |
|
of "git", the information manager from hell". Congratulations! You’ve written |
|
your first revision walk. You can play with printing some additional fields |
|
from each commit if you’re curious; have a look at the functions available in |
|
<code>commit.h</code>.</p> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_adding_a_filter">Adding a Filter</h3> |
|
<div class="paragraph"> |
|
<p>Next, let’s try to filter the commits we see based on their author. This is |
|
equivalent to running <code>git log --author=<pattern></code>. We can add a filter by |
|
modifying <code>rev_info.grep_filter</code>, which is a <code>struct grep_opt</code>.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>First some setup. Add <code>grep_config()</code> to <code>git_walken_config()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static int git_walken_config(const char *var, const char *value, void *cb) |
|
{ |
|
grep_config(var, value, cb); |
|
return git_default_config(var, value, cb); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Next, we can modify the <code>grep_filter</code>. This is done with convenience functions |
|
found in <code>grep.h</code>. For fun, we’re filtering to only commits from folks using a |
|
<code>gmail.com</code> email address - a not-very-precise guess at who may be working on |
|
Git as a hobby. Since we’re checking the author, which is a specific line in the |
|
header, we’ll use the <code>append_header_grep_pattern()</code> helper. We can use |
|
the <code>enum grep_header_field</code> to indicate which part of the commit header we want |
|
to search.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>In <code>final_rev_info_setup()</code>, add your filter line:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void final_rev_info_setup(int argc, const char **argv, |
|
const char *prefix, struct rev_info *rev) |
|
{ |
|
... |
|
|
|
append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, |
|
"gmail"); |
|
compile_grep_patterns(&rev->grep_filter); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>append_header_grep_pattern()</code> adds your new "gmail" pattern to <code>rev_info</code>, but |
|
it won’t work unless we compile it with <code>compile_grep_patterns()</code>.</p> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
If you are using <code>setup_revisions()</code> (for example, if you are passing a |
|
<code>setup_revision_opt</code> instead of using <code>add_head_to_pending()</code>), you don’t need |
|
to call <code>compile_grep_patterns()</code> because <code>setup_revisions()</code> calls it for you. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
We could add the same filter via the <code>append_grep_pattern()</code> helper if we |
|
wanted to, but <code>append_header_grep_pattern()</code> adds the <code>enum grep_context</code> and |
|
<code>enum grep_pat_token</code> for us. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_changing_the_order">Changing the Order</h3> |
|
<div class="paragraph"> |
|
<p>There are a few ways that we can change the order of the commits during a |
|
revision walk. Firstly, we can use the <code>enum rev_sort_order</code> to choose from some |
|
typical orderings.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p><code>topo_order</code> is the same as <code>git log --topo-order</code>: we avoid showing a parent |
|
before all of its children have been shown, and we avoid mixing commits which |
|
are in different lines of history. (<code>git help log</code>'s section on <code>--topo-order</code> |
|
has a very nice diagram to illustrate this.)</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Let’s see what happens when we run with <code>REV_SORT_BY_COMMIT_DATE</code> as opposed to |
|
<code>REV_SORT_BY_AUTHOR_DATE</code>. Add the following:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void final_rev_info_setup(int argc, const char **argv, |
|
const char *prefix, struct rev_info *rev) |
|
{ |
|
... |
|
|
|
rev->topo_order = 1; |
|
rev->sort_order = REV_SORT_BY_COMMIT_DATE; |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Let’s output this into a file so we can easily diff it with the walk sorted by |
|
author date.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ make |
|
$ ./bin-wrappers/git walken > commit-date.txt</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Then, let’s sort by author date and run it again.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void final_rev_info_setup(int argc, const char **argv, |
|
const char *prefix, struct rev_info *rev) |
|
{ |
|
... |
|
|
|
rev->topo_order = 1; |
|
rev->sort_order = REV_SORT_BY_AUTHOR_DATE; |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ make |
|
$ ./bin-wrappers/git walken > author-date.txt</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Finally, compare the two. This is a little less helpful without object names or |
|
dates, but hopefully we get the idea.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ diff -u commit-date.txt author-date.txt</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>This display indicates that commits can be reordered after they’re written, for |
|
example with <code>git rebase</code>.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Let’s try one more reordering of commits. <code>rev_info</code> exposes a <code>reverse</code> flag. |
|
Set that flag somewhere inside of <code>final_rev_info_setup()</code>:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void final_rev_info_setup(int argc, const char **argv, const char *prefix, |
|
struct rev_info *rev) |
|
{ |
|
... |
|
|
|
rev->reverse = 1; |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Run your walk again and note the difference in order. (If you remove the grep |
|
pattern, you should see the last commit this call gives you as your current |
|
HEAD.)</p> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect1"> |
|
<h2 id="_basic_object_walk">Basic Object Walk</h2> |
|
<div class="sectionbody"> |
|
<div class="paragraph"> |
|
<p>So far we’ve been walking only commits. But Git has more types of objects than |
|
that! Let’s see if we can walk <em>all</em> objects, and find out some information |
|
about each one.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>We can base our work on an example. <code>git pack-objects</code> prepares all kinds of |
|
objects for packing into a bitmap or packfile. The work we are interested in |
|
resides in <code>builtins/pack-objects.c:get_object_list()</code>; examination of that |
|
function shows that the all-object walk is being performed by |
|
<code>traverse_commit_list()</code> or <code>traverse_commit_list_filtered()</code>. Those two |
|
functions reside in <code>list-objects.c</code>; examining the source shows that, despite |
|
the name, these functions traverse all kinds of objects. Let’s have a look at |
|
the arguments to <code>traverse_commit_list()</code>.</p> |
|
</div> |
|
<div class="ulist"> |
|
<ul> |
|
<li> |
|
<p><code>struct rev_info *revs</code>: This is the <code>rev_info</code> used for the walk. If |
|
its <code>filter</code> member is not <code>NULL</code>, then <code>filter</code> contains information for |
|
how to filter the object list.</p> |
|
</li> |
|
<li> |
|
<p><code>show_commit_fn show_commit</code>: A callback which will be used to handle each |
|
individual commit object.</p> |
|
</li> |
|
<li> |
|
<p><code>show_object_fn show_object</code>: A callback which will be used to handle each |
|
non-commit object (so each blob, tree, or tag).</p> |
|
</li> |
|
<li> |
|
<p><code>void *show_data</code>: A context buffer which is passed in turn to <code>show_commit</code> |
|
and <code>show_object</code>.</p> |
|
</li> |
|
</ul> |
|
</div> |
|
<div class="paragraph"> |
|
<p>In addition, <code>traverse_commit_list_filtered()</code> has an additional parameter:</p> |
|
</div> |
|
<div class="ulist"> |
|
<ul> |
|
<li> |
|
<p><code>struct oidset *omitted</code>: A linked-list of object IDs which the provided |
|
filter caused to be omitted.</p> |
|
</li> |
|
</ul> |
|
</div> |
|
<div class="paragraph"> |
|
<p>It looks like these methods use callbacks we provide instead of needing us |
|
to call it repeatedly ourselves. Cool! Let’s add the callbacks first.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>For the sake of this tutorial, we’ll simply keep track of how many of each kind |
|
of object we find. At file scope in <code>builtin/walken.c</code> add the following |
|
tracking variables:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static int commit_count; |
|
static int tag_count; |
|
static int blob_count; |
|
static int tree_count;</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Commits are handled by a different callback than other objects; let’s do that |
|
one first:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_show_commit(struct commit *cmt, void *buf) |
|
{ |
|
commit_count++; |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>The <code>cmt</code> argument is fairly self-explanatory. But it’s worth mentioning that |
|
the <code>buf</code> argument is actually the context buffer that we can provide to the |
|
traversal calls - <code>show_data</code>, which we mentioned a moment ago.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Since we have the <code>struct commit</code> object, we can look at all the same parts that |
|
we looked at in our earlier commit-only walk. For the sake of this tutorial, |
|
though, we’ll just increment the commit counter and move on.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>The callback for non-commits is a little different, as we’ll need to check |
|
which kind of object we’re dealing with:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_show_object(struct object *obj, const char *str, void *buf) |
|
{ |
|
switch (obj->type) { |
|
case OBJ_TREE: |
|
tree_count++; |
|
break; |
|
case OBJ_BLOB: |
|
blob_count++; |
|
break; |
|
case OBJ_TAG: |
|
tag_count++; |
|
break; |
|
case OBJ_COMMIT: |
|
BUG("unexpected commit object in walken_show_object\n"); |
|
default: |
|
BUG("unexpected object type %s in walken_show_object\n", |
|
type_name(obj->type)); |
|
} |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Again, <code>obj</code> is fairly self-explanatory, and we can guess that <code>buf</code> is the same |
|
context pointer that <code>walken_show_commit()</code> receives: the <code>show_data</code> argument |
|
to <code>traverse_commit_list()</code> and <code>traverse_commit_list_filtered()</code>. Finally, |
|
<code>str</code> contains the name of the object, which ends up being something like |
|
<code>foo.txt</code> (blob), <code>bar/baz</code> (tree), or <code>v1.2.3</code> (tag).</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>To help assure us that we aren’t double-counting commits, we’ll include some |
|
complaining if a commit object is routed through our non-commit callback; we’ll |
|
also complain if we see an invalid object type. Since those two cases should be |
|
unreachable, and would only change in the event of a semantic change to the Git |
|
codebase, we complain by using <code>BUG()</code> - which is a signal to a developer that |
|
the change they made caused unintended consequences, and the rest of the |
|
codebase needs to be updated to understand that change. <code>BUG()</code> is not intended |
|
to be seen by the public, so it is not localized.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Our main object walk implementation is substantially different from our commit |
|
walk implementation, so let’s make a new function to perform the object walk. We |
|
can perform setup which is applicable to all objects here, too, to keep separate |
|
from setup which is applicable to commit-only walks.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>We’ll start by enabling all types of objects in the <code>struct rev_info</code>. We’ll |
|
also turn on <code>tree_blobs_in_commit_order</code>, which means that we will walk a |
|
commit’s tree and everything it points to immediately after we find each commit, |
|
as opposed to waiting for the end and walking through all trees after the commit |
|
history has been discovered. With the appropriate settings configured, we are |
|
ready to call <code>prepare_revision_walk()</code>.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_object_walk(struct rev_info *rev) |
|
{ |
|
rev->tree_objects = 1; |
|
rev->blob_objects = 1; |
|
rev->tag_objects = 1; |
|
rev->tree_blobs_in_commit_order = 1; |
|
|
|
if (prepare_revision_walk(rev)) |
|
die(_("revision walk setup failed")); |
|
|
|
commit_count = 0; |
|
tag_count = 0; |
|
blob_count = 0; |
|
tree_count = 0;</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Let’s start by calling just the unfiltered walk and reporting our counts. |
|
Complete your implementation of <code>walken_object_walk()</code>. |
|
We’ll also need to include the <code>list-objects.h</code> header.</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>#include "list-objects.h" |
|
|
|
... |
|
|
|
traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); |
|
|
|
printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count, |
|
blob_count, tag_count, tree_count); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
This output is intended to be machine-parsed. Therefore, we are not |
|
sending it to <code>trace_printf()</code>, and we are not localizing it - we need scripts |
|
to be able to count on the formatting to be exactly the way it is shown here. |
|
If we were intending this output to be read by humans, we would need to localize |
|
it with <code>_()</code>. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Finally, we’ll ask <code>cmd_walken()</code> to use the object walk instead. Discussing |
|
command line options is out of scope for this tutorial, so we’ll just hardcode |
|
a branch we can change at compile time. Where you call <code>final_rev_info_setup()</code> |
|
and <code>walken_commit_walk()</code>, instead branch like so:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> if (1) { |
|
add_head_to_pending(&rev); |
|
walken_object_walk(&rev); |
|
} else { |
|
final_rev_info_setup(argc, argv, prefix, &rev); |
|
walken_commit_walk(&rev); |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
For simplicity, we’ve avoided all the filters and sorts we applied in |
|
<code>final_rev_info_setup()</code> and simply added <code>HEAD</code> to our pending queue. If you |
|
want, you can certainly use the filters we added before by moving |
|
<code>final_rev_info_setup()</code> out of the conditional and removing the call to |
|
<code>add_head_to_pending()</code>. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Now we can try to run our command! It should take noticeably longer than the |
|
commit walk, but an examination of the output will give you an idea why. Your |
|
output should look similar to this example, but with different counts:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees.</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>This makes sense. We have more trees than commits because the Git project has |
|
lots of subdirectories which can change, plus at least one tree per commit. We |
|
have no tags because we started on a commit (<code>HEAD</code>) and while tags can point to |
|
commits, commits can’t point to tags.</p> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
You will have different counts when you run this yourself! The number of |
|
objects grows along with the Git project. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_adding_a_filter_2">Adding a Filter</h3> |
|
<div class="paragraph"> |
|
<p>There are a handful of filters that we can apply to the object walk laid out in |
|
<code>Documentation/rev-list-options.txt</code>. These filters are typically useful for |
|
operations such as creating packfiles or performing a partial clone. They are |
|
defined in <code>list-objects-filter-options.h</code>. For the purposes of this tutorial we |
|
will use the "tree:1" filter, which causes the walk to omit all trees and blobs |
|
which are not directly referenced by commits reachable from the commit in |
|
<code>pending</code> when the walk begins. (<code>pending</code> is the list of objects which need to |
|
be traversed during a walk; you can imagine a breadth-first tree traversal to |
|
help understand. In our case, that means we omit trees and blobs not directly |
|
referenced by <code>HEAD</code> or <code>HEAD</code>'s history, because we begin the walk with only |
|
<code>HEAD</code> in the <code>pending</code> list.)</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>For now, we are not going to track the omitted objects, so we’ll replace those |
|
parameters with <code>NULL</code>. For the sake of simplicity, we’ll add a simple |
|
build-time branch to use our filter or not. Preface the line calling |
|
<code>traverse_commit_list()</code> with the following, which will remind us which kind of |
|
walk we’ve just performed:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> if (0) { |
|
/* Unfiltered: */ |
|
trace_printf(_("Unfiltered object walk.\n")); |
|
} else { |
|
trace_printf( |
|
_("Filtered object walk with filterspec 'tree:1'.\n")); |
|
CALLOC_ARRAY(rev->filter, 1); |
|
parse_list_objects_filter(rev->filter, "tree:1"); |
|
} |
|
traverse_commit_list(rev, walken_show_commit, |
|
walken_show_object, NULL);</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>The <code>rev->filter</code> member is usually built directly from a command |
|
line argument, so the module provides an easy way to build one from a string. |
|
Even though we aren’t taking user input right now, we can still build one with |
|
a hardcoded string using <code>parse_list_objects_filter()</code>.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>With the filter spec "tree:1", we are expecting to see <em>only</em> the root tree for |
|
each commit; therefore, the tree object count should be less than or equal to |
|
the number of commits. (For an example of why that’s true: <code>git commit --revert</code> |
|
points to the same tree object as its grandparent.)</p> |
|
</div> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_counting_omitted_objects">Counting Omitted Objects</h3> |
|
<div class="paragraph"> |
|
<p>We also have the capability to enumerate all objects which were omitted by a |
|
filter, like with <code>git log --filter=<spec> --filter-print-omitted</code>. Asking |
|
<code>traverse_commit_list_filtered()</code> to populate the <code>omitted</code> list means that our |
|
object walk does not perform any better than an unfiltered object walk; all |
|
reachable objects are walked in order to populate the list.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>First, add the <code>struct oidset</code> and related items we will use to iterate it:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_object_walk( |
|
... |
|
|
|
struct oidset omitted; |
|
struct oidset_iter oit; |
|
struct object_id *oid = NULL; |
|
int omitted_count = 0; |
|
oidset_init(&omitted, 0); |
|
|
|
...</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Modify the call to <code>traverse_commit_list_filtered()</code> to include your <code>omitted</code> |
|
object:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> ... |
|
|
|
traverse_commit_list_filtered(rev, |
|
walken_show_commit, walken_show_object, NULL, &omitted); |
|
|
|
...</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Then, after your traversal, the <code>oidset</code> traversal is pretty straightforward. |
|
Count all the objects within and modify the print statement:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> /* Count the omitted objects. */ |
|
oidset_iter_init(&omitted, &oit); |
|
|
|
while ((oid = oidset_iter_next(&oit))) |
|
omitted_count++; |
|
|
|
printf("commits %d\nblobs %d\ntags %d\ntrees %d\nomitted %d\n", |
|
commit_count, blob_count, tag_count, tree_count, omitted_count);</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>By running your walk with and without the filter, you should find that the total |
|
object count in each case is identical. You can also time each invocation of |
|
the <code>walken</code> subcommand, with and without <code>omitted</code> being passed in, to confirm |
|
to yourself the runtime impact of tracking all omitted objects.</p> |
|
</div> |
|
</div> |
|
<div class="sect2"> |
|
<h3 id="_changing_the_order_2">Changing the Order</h3> |
|
<div class="paragraph"> |
|
<p>Finally, let’s demonstrate that you can also reorder walks of all objects, not |
|
just walks of commits. First, we’ll make our handlers chattier - modify |
|
<code>walken_show_commit()</code> and <code>walken_show_object()</code> to print the object as they |
|
go:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>static void walken_show_commit(struct commit *cmt, void *buf) |
|
{ |
|
trace_printf("commit: %s\n", oid_to_hex(&cmt->object.oid)); |
|
commit_count++; |
|
} |
|
|
|
static void walken_show_object(struct object *obj, const char *str, void *buf) |
|
{ |
|
trace_printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid)); |
|
|
|
... |
|
}</pre> |
|
</div> |
|
</div> |
|
<div class="admonitionblock note"> |
|
<table> |
|
<tr> |
|
<td class="icon"> |
|
<div class="title">Note</div> |
|
</td> |
|
<td class="content"> |
|
Since we will be examining this output directly as humans, we’ll use |
|
<code>trace_printf()</code> here. Additionally, since this change introduces a significant |
|
number of printed lines, using <code>trace_printf()</code> will allow us to easily silence |
|
those lines without having to recompile. |
|
</td> |
|
</tr> |
|
</table> |
|
</div> |
|
<div class="paragraph"> |
|
<p>(Leave the counter increment logic in place.)</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>With only that change, run again (but save yourself some scrollback):</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ GIT_TRACE=1 ./bin-wrappers/git walken | head -n 10</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Take a look at the top commit with <code>git show</code> and the object ID you printed; it |
|
should be the same as the output of <code>git show HEAD</code>.</p> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Next, let’s change a setting on our <code>struct rev_info</code> within |
|
<code>walken_object_walk()</code>. Find where you’re changing the other settings on <code>rev</code>, |
|
such as <code>rev->tree_objects</code> and <code>rev->tree_blobs_in_commit_order</code>, and add the |
|
<code>reverse</code> setting at the bottom:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre> ... |
|
|
|
rev->tree_objects = 1; |
|
rev->blob_objects = 1; |
|
rev->tag_objects = 1; |
|
rev->tree_blobs_in_commit_order = 1; |
|
rev->reverse = 1; |
|
|
|
...</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>Now, run again, but this time, let’s grab the last handful of objects instead |
|
of the first handful:</p> |
|
</div> |
|
<div class="listingblock"> |
|
<div class="content"> |
|
<pre>$ make |
|
$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10</pre> |
|
</div> |
|
</div> |
|
<div class="paragraph"> |
|
<p>The last commit object given should have the same OID as the one we saw at the |
|
top before, and running <code>git show <oid></code> with that OID should give you again |
|
the same results as <code>git show HEAD</code>. Furthermore, if you run and examine the |
|
first ten lines again (with <code>head</code> instead of <code>tail</code> like we did before applying |
|
the <code>reverse</code> setting), you should see that now the first commit printed is the |
|
initial commit, <code>e83c5163</code>.</p> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<div class="sect1"> |
|
<h2 id="_wrapping_up">Wrapping Up</h2> |
|
<div class="sectionbody"> |
|
<div class="paragraph"> |
|
<p>Let’s review. In this tutorial, we:</p> |
|
</div> |
|
<div class="ulist"> |
|
<ul> |
|
<li> |
|
<p>Built a commit walk from the ground up</p> |
|
</li> |
|
<li> |
|
<p>Enabled a grep filter for that commit walk</p> |
|
</li> |
|
<li> |
|
<p>Changed the sort order of that filtered commit walk</p> |
|
</li> |
|
<li> |
|
<p>Built an object walk (tags, commits, trees, and blobs) from the ground up</p> |
|
</li> |
|
<li> |
|
<p>Learned how to add a filter-spec to an object walk</p> |
|
</li> |
|
<li> |
|
<p>Changed the display order of the filtered object walk</p> |
|
</li> |
|
</ul> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<div id="footer"> |
|
<div id="footer-text"> |
|
Last updated 2023-04-19 05:40:20 UTC |
|
</div> |
|
</div> |
|
</body> |
|
</html> |