<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[152533] contrib/mp-buildbot/mpbb-checkout</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/152533">152533</a></dd>
<dt>Author</dt> <dd>larryv@macports.org</dd>
<dt>Date</dt> <dd>2016-09-11 18:59:14 -0700 (Sun, 11 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>mpbb: Allow fetching jobs tools and ports via Git

`mpbb checkout` accepts a new `--git` option, which is also the default.
It is an error to specify it alongside `--svn` or `--svn-url`.

It also accepts `--ports-branch`, which can be used to fetch Git objects
from a particular branch of a remote repository.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#contribmpbuildbotmpbbcheckout">contrib/mp-buildbot/mpbb-checkout</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="contribmpbuildbotmpbbcheckout"></a>
<div class="modfile"><h4>Modified: contrib/mp-buildbot/mpbb-checkout (152532 => 152533)</h4>
<pre class="diff"><span>
<span class="info">--- contrib/mp-buildbot/mpbb-checkout        2016-09-12 01:59:12 UTC (rev 152532)
+++ contrib/mp-buildbot/mpbb-checkout        2016-09-12 01:59:14 UTC (rev 152533)
</span><span class="lines">@@ -16,25 +16,37 @@
</span><span class="cx"> 
</span><span class="cx"> Options:
</span><span class="cx"> 
</span><ins>+  --git[=&lt;path&gt;]
+    Use Git to obtain the jobs tools and ports tree; this is the default
+    behavior. The path to a Git client may be provided explicitly,
+    otherwise \`git' is used. Cannot be specified together with --svn.
+
</ins><span class="cx">   --jobs-url=&lt;URL&gt;
</span><span class="cx">     URL to a repository containing the jobs tools. Only used when
</span><span class="cx">     checking out a new working copy. Defaults to
</span><del>-    \`https://svn.macports.org/repository/macports/trunk/base/portmgr/jobs'.
</del><ins>+    \`https://github.com/macports/infrastructure.git' for Git and
+    \`https://github.com/macports/infrastructure.git/trunk/jobs' for
+    Subversion.
</ins><span class="cx"> 
</span><ins>+  --ports-branch=&lt;branch&gt;
+    The branch of the remote repository from which the ports tree will
+    be checked out. Only used with Git; defaults to \`master'.
+
</ins><span class="cx">   --ports-commit=&lt;commit&gt;
</span><span class="cx">     A commit or revision at which the ports tree will be checked out.
</span><span class="cx">     Any specifier understood by the version-control client may be used.
</span><del>-    Defaults to \`HEAD'.
</del><ins>+    Defaults to \`FETCH_HEAD' for Git and \`HEAD' for Subversion.
</ins><span class="cx"> 
</span><span class="cx">   --ports-url=&lt;URL&gt;
</span><span class="cx">     URL to a repository containing the ports tree. Only used when
</span><span class="cx">     checking out a new working copy. Defaults to
</span><del>-    \`https://svn.macports.org/repository/macports/trunk/dports'.
</del><ins>+    \`https://github.com/macports/ports.git' for Git and.
+    \`https://github.com/macports/ports.git/trunk' for Subversion.
</ins><span class="cx"> 
</span><span class="cx">   --svn[=&lt;path&gt;]
</span><del>-    Use Subversion to obtain the jobs tools and ports tree; this is the
-    default behavior. The path to a Subversion client may be provided
-    explicitly, otherwise \`svn' is used.
</del><ins>+    Use Subversion to obtain the jobs tools and ports tree. The path to
+    a Subversion client may be provided explicitly, otherwise \`svn' is
+    used. Cannot be specified together with --git.
</ins><span class="cx"> 
</span><span class="cx"> Run \`$prog help' for global options and a list of other subcommands.
</span><span class="cx"> EOF
</span><span class="lines">@@ -48,6 +60,47 @@
</span><span class="cx">     (shopt -s dotglob nullglob; f=(&quot;$1&quot;/*); (( ! ${#f[@]} )))
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+git-checkout() {
+    if (( $# &lt; 2 )); then
+        err 'git-checkout requires at least two arguments'
+        return 2
+    fi
+
+    local -r dst=$1 src=$2 commitish=${3-FETCH_HEAD} branch=${4-master}
+
+    # top is null unless dst exists somewhere in a Git working tree.
+    local -r top=$({ cd &quot;$dst&quot; &amp;&amp; &quot;$git&quot; rev-parse --show-toplevel; } 2&gt;/dev/null)
+    if ! { [[ -z $top ]] &amp;&amp; is-empty &quot;$dst&quot; || [[ $top -ef $dst ]]; }; then
+        err &quot;\`$dst' is not an empty directory or&quot; \
+            'the top level of a Git working tree'
+        return 1
+    fi
+
+    printf &quot;\n---&gt; Updating Git repository from \`%s' branch of \`%s'\n&quot; \
+        &quot;$branch&quot; &quot;$src&quot;
+    (
+        # &quot;git init&quot; creates the intermediate directories and is safe to
+        # run in an existing repository.
+        &quot;$git&quot; init &quot;$dst&quot; || exit
+
+        # Change directories explicitly because Lion's Git (1.7.12.4) is
+        # too old to understand &quot;git -C&quot; (requires 1.8.5).
+        cd &quot;$dst&quot; || exit
+
+        # Fetch directly from the URL to avoid fussing with remotes and
+        # to allow switching sources easily.
+        &quot;$git&quot; fetch --tags &quot;$src&quot; &quot;$branch&quot; || exit
+
+        # Maintain master to prevent Git from garbage-collecting the
+        # fetched objects.
+        &quot;$git&quot; update-ref -m &quot;mpbb checkout $(date -u +%Y-%m-%dT%TZ)&quot; \
+                    refs/heads/master FETCH_HEAD || exit
+
+        # Only update the working tree here, at the very end.
+        &quot;$git&quot; checkout --detach &quot;$commitish&quot;
+    )
+}
+
</ins><span class="cx"> svn-checkout() {
</span><span class="cx">     if (( $# &lt; 2 )); then
</span><span class="cx">         err 'svn-checkout requires at least two arguments'
</span><span class="lines">@@ -77,7 +130,7 @@
</span><span class="cx"> 
</span><span class="cx"> checkout() {
</span><span class="cx">     local args
</span><del>-    parseopt jobs-url:,ports-commit:,ports-url:,prefix:,svn::,svn-url: &quot;$@&quot; \
</del><ins>+    parseopt git::,jobs-url:,ports-branch:,ports-commit:,ports-url:,prefix:,svn::,svn-url: &quot;$@&quot; \
</ins><span class="cx">         || return
</span><span class="cx">     # shellcheck disable=SC2086
</span><span class="cx">     set -- ${args+&quot;${args[@]}&quot;}
</span><span class="lines">@@ -91,28 +144,40 @@
</span><span class="cx">     # shellcheck disable=SC2154
</span><span class="cx">     local -r ports_dir=${option_work_dir}/ports
</span><span class="cx"> 
</span><del>-    local checkout jobs_dir svn
</del><ins>+    local checkout git jobs_dir svn
</ins><span class="cx">     # shellcheck disable=SC2100 disable=SC2154
</span><del>-    if svn=${option_svn:-$(command -v svn)}; then
</del><ins>+    if [[ -z ${option_svn+_} ]] &amp;&amp; git=${option_git:-$(command -v git)}; then
+        checkout=git-checkout
+        # Checking out &quot;jobs_url&quot; should create a &quot;jobs&quot; subdirectory.
+        jobs_dir=$(dirname &quot;${option_jobs_dir}&quot;)
+        : &quot;${option_jobs_url=https://github.com/macports/infrastructure.git}&quot;
+        : &quot;${option_ports_url=https://github.com/macports/ports.git}&quot;
+    elif [[ -z ${option_git+_} ]] &amp;&amp; svn=${option_svn:-$(command -v svn)}; then
</ins><span class="cx">         checkout=svn-checkout
</span><span class="cx">         jobs_dir=${option_jobs_dir}
</span><span class="cx">         if [[ -n ${option_svn_url+_} ]]; then
</span><span class="cx">             : &quot;${option_jobs_url=${option_svn_url}/base/portmgr/jobs}&quot;
</span><span class="cx">             : &quot;${option_ports_url=${option_svn_url}/dports}&quot;
</span><span class="cx">         else
</span><del>-            : &quot;${option_jobs_url=https://svn.macports.org/repository/macports/trunk/base/portmgr/jobs}&quot;
-            : &quot;${option_ports_url=https://svn.macports.org/repository/macports/trunk/dports}&quot;
</del><ins>+            : &quot;${option_jobs_url=https://github.com/macports/infrastructure.git/trunk/jobs}&quot;
+            : &quot;${option_ports_url=https://github.com/macports/ports.git/trunk}&quot;
</ins><span class="cx">         fi
</span><span class="cx">     else
</span><del>-        err 'cannot find a Subversion client'
</del><ins>+        case ${option_git+_},${option_svn+_} in
+            _,_) err 'cannot use both Git and Subversion'; return 2 ;;
+            _,)  err 'cannot find a Git client' ;;
+            ,_)  err 'cannot find a Subversion client' ;;
+            ,)   err 'cannot find any Git or Subversion clients' ;;
+        esac
</ins><span class="cx">         return 1
</span><span class="cx">     fi
</span><del>-    readonly checkout jobs_dir svn
</del><ins>+    readonly checkout git jobs_dir svn
</ins><span class="cx"> 
</span><span class="cx">     $checkout &quot;${jobs_dir}&quot; &quot;${option_jobs_url}&quot; || return
</span><span class="cx">     # shellcheck disable=SC2086 disable=SC2154
</span><span class="cx">     $checkout &quot;${ports_dir}&quot; &quot;${option_ports_url}&quot; \
</span><del>-            ${option_ports_commit+&quot;${option_ports_commit}&quot;} || return
</del><ins>+            ${option_ports_commit+&quot;${option_ports_commit}&quot;} \
+            ${option_ports_branch+&quot;${option_ports_branch}&quot;} || return
</ins><span class="cx"> 
</span><span class="cx">     # $option_prefix is set in mpbb
</span><span class="cx">     # shellcheck disable=SC2154
</span></span></pre>
</div>
</div>

</body>
</html>