<!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>[152530] 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/152530">152530</a></dd>
<dt>Author</dt> <dd>larryv@macports.org</dd>
<dt>Date</dt> <dd>2016-09-11 18:59:08 -0700 (Sun, 11 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>mpbb: Refactor Subversion checkout

`checkout` now calls a VCS-specific function to do the heavy lifting.
Factor out the Subversion-related code and improve it:

- Use `svn info` to check for an existing repository instead of just
  looking for a `.svn` directory.

- Refuse to checkout into a nonempty directory. Subversion itself won't
  complain in this scenario: `svn --non-interactive checkout` registers
  conflicts and exits with status 0. (This might happen if a user
  switches version control systems and doesn't remove the preexisting
  working tree.)

- Print URL of the remote repository.

- It doesn't hurt to run `svn cleanup` on a clean repository, so just
  run it always.</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 (152529 => 152530)</h4>
<pre class="diff"><span>
<span class="info">--- contrib/mp-buildbot/mpbb-checkout        2016-09-12 01:59:06 UTC (rev 152529)
+++ contrib/mp-buildbot/mpbb-checkout        2016-09-12 01:59:08 UTC (rev 152530)
</span><span class="lines">@@ -40,6 +40,41 @@
</span><span class="cx"> EOF
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+is-empty() {
+    if [[ $# -ne 1 || -z $1 ]]; then
+        err 'is-empty requires a single non-null argument'
+        return 2
+    fi
+    (shopt -s dotglob nullglob; f=(&quot;$1&quot;/*); (( ! ${#f[@]} )))
+}
+
+svn-checkout() {
+    if (( $# &lt; 2 )); then
+        err 'svn-checkout requires at least two arguments'
+        return 2
+    fi
+
+    local -r dst=$1 src=$2 rev=${3-HEAD}
+    local -r svn=(&quot;$svn&quot; --non-interactive)
+    local -r root=$(&quot;${svn[@]}&quot; info --show-item wc-root &quot;$dst&quot; 2&gt;/dev/null)
+
+    if [[ -z $root ]] &amp;&amp; is-empty &quot;$dst&quot;; then
+        printf &quot;\n---&gt; Checking out Subversion repository from \`%s'\n&quot; &quot;$src&quot;
+        # &quot;svn checkout&quot; creates the intermediate directories.
+        &quot;${svn[@]}&quot; checkout --revision &quot;$rev&quot; &quot;$src&quot; &quot;$dst&quot;
+    elif [[ $root -ef $dst ]]; then
+        # TODO Allow switching the Subversion server.
+        printf &quot;\n---&gt; Updating Subversion repository from \`%s'\n&quot; \
+            &quot;$(&quot;${svn[@]}&quot; info --show-item url &quot;$dst&quot;)&quot;
+        &quot;${svn[@]}&quot; cleanup &quot;$dst&quot; \
+            &amp;&amp; &quot;${svn[@]}&quot; update --revision &quot;$rev&quot; &quot;$dst&quot;
+    else
+        err &quot;\`$dst' is not an empty directory or&quot; \
+            'the root of a Subversion working copy'
+        return 1
+    fi
+}
+
</ins><span class="cx"> checkout() {
</span><span class="cx">     local args
</span><span class="cx">     parseopt jobs-url:,ports-commit:,ports-url:,prefix:,svn::,svn-url: &quot;$@&quot; \
</span><span class="lines">@@ -56,9 +91,10 @@
</span><span class="cx">     # shellcheck disable=SC2154
</span><span class="cx">     local -r ports_dir=${option_work_dir}/dports
</span><span class="cx"> 
</span><del>-    local jobs_dir svn
-    # shellcheck disable=SC2154
</del><ins>+    local checkout jobs_dir svn
+    # shellcheck disable=SC2100 disable=SC2154
</ins><span class="cx">     if svn=${option_svn:-$(command -v svn)}; then
</span><ins>+        checkout=svn-checkout
</ins><span class="cx">         jobs_dir=${option_work_dir}/tools
</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="lines">@@ -67,43 +103,17 @@
</span><span class="cx">             : &quot;${option_jobs_url=https://svn.macports.org/repository/macports/trunk/base/portmgr/jobs}&quot;
</span><span class="cx">             : &quot;${option_ports_url=https://svn.macports.org/repository/macports/trunk/dports}&quot;
</span><span class="cx">         fi
</span><del>-    if [[ -d &quot;${jobs_dir}/.svn&quot; ]] ; then
-        echo &quot;Update macports tools from svn...&quot;
-        if [[ -e &quot;${jobs_dir}/.svn/lock&quot; ]]; then
-            &quot;$svn&quot; --non-interactive cleanup &quot;${jobs_dir}&quot; || return
-        fi
-        &quot;$svn&quot; update --non-interactive \
-            -r HEAD \
-            &quot;${jobs_dir}&quot; || return
</del><span class="cx">     else
</span><del>-        echo &quot;Checking out macports tools from svn...&quot;
-        mkdir -p &quot;$(dirname &quot;${jobs_dir}&quot;)&quot;
-        &quot;$svn&quot; checkout --non-interactive \
-            -r HEAD &quot;${option_jobs_url}&quot; \
-            &quot;${jobs_dir}&quot; || return
-    fi
-
-    if [[ -d &quot;${ports_dir}/.svn&quot; ]] ; then
-        echo &quot;Update macports from svn...&quot;
-        # TODO: add switching of SVN server
-        if [[ -e &quot;${ports_dir}/.svn/lock&quot; ]]; then
-            &quot;$svn&quot; --non-interactive cleanup &quot;${ports_dir}&quot; || return
-        fi
-        &quot;$svn&quot; update --non-interactive \
-            -r &quot;${option_ports_commit-HEAD}&quot; \
-            &quot;${ports_dir}&quot; || return
-    else
-        echo &quot;Checking out macports from svn...&quot;
-        mkdir -p &quot;$(dirname &quot;${ports_dir}&quot;)&quot;
-        &quot;$svn&quot; checkout --non-interactive \
-            -r &quot;${option_ports_commit-HEAD}&quot; &quot;${option_ports_url}&quot; \
-            &quot;${ports_dir}&quot; || return
-    fi
-    else
</del><span class="cx">         err 'cannot find a Subversion client'
</span><span class="cx">         return 1
</span><span class="cx">     fi
</span><ins>+    readonly checkout jobs_dir svn
</ins><span class="cx"> 
</span><ins>+    $checkout &quot;${jobs_dir}&quot; &quot;${option_jobs_url}&quot; || return
+    # shellcheck disable=SC2086 disable=SC2154
+    $checkout &quot;${ports_dir}&quot; &quot;${option_ports_url}&quot; \
+            ${option_ports_commit+&quot;${option_ports_commit}&quot;} || return
+
</ins><span class="cx">     # $option_prefix is set in mpbb
</span><span class="cx">     # shellcheck disable=SC2154
</span><span class="cx">     (cd &quot;${ports_dir}&quot; &amp;&amp; &quot;${option_prefix}/bin/portindex&quot;) || return
</span></span></pre>
</div>
</div>

</body>
</html>