<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Git on bramp.net</title>
    <link>https://blog.bramp.net/</link>
    <description>Recent content in Git on bramp.net</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-GB</language>
    <lastBuildDate>Tue, 04 Sep 2012 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bramp.net/tags/git/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Setting up git-p4</title>
      <link>https://blog.bramp.net/post/2012/09/04/setting-up-git-p4/</link>
      <pubDate>Tue, 04 Sep 2012 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2012/09/04/setting-up-git-p4/</guid>
      <description><p>I couldn’t find a good article on setting up git-p4, and for some reason most of the articles out there point to dead URLs. So I figured I’d quickly write this up.</p>
<p>Git-p4 is a tool for using git on top of a perforce server. This is great if your team wants to work with a DVCS, but your company requires a centralised VCS.</p>
<p>There were multiple github projects <a href="https://github.com/baldrick/git-p4/">1</a>, <a href="https://github.com/gkielSfdc/git-p4">2</a>, <a href="https://github.com/jendave/git-p4">3</a>, that had forks of the git-p4 script, however, I found the latest mixed in with the official git source code. So download it from <a href="https://raw.github.com/git/git/master/git-p4.py">here</a>. Tip: Don’t forget to “chmod +x git-p4.py” once it’s downloaded.</p>
<p>Next, I wanted to be able to type “git p4″, so I used an <a href="https://git.wiki.kernel.org/index.php/Aliases">alias</a> to do this. Edit/create the file ~/.gitconfig and add:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[alias]</span>
</span></span><span class="line"><span class="cl"><span class="na">p4</span> <span class="o">=</span> <span class="s">!~/bin/git-p4.py</span>
</span></span></code></pre></div><p>Once that’s done you should be able to:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Fetch only the head</span>
</span></span><span class="line"><span class="cl">git p4 clone //depot/path/to/project/ project
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># or Fetch all revisions (takes a little longer)</span>
</span></span><span class="line"><span class="cl">git p4 clone //depot/path/to/project/@all project
</span></span></code></pre></div><p>If that returns an error, such as “p4 returned an error: Perforce password (P4PASSWD) invalid or unset.”, then you most likely don’t have your p4 command line set up. To set mine up, I added the following to my .bashrc</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">P4CLIENT</span><span class="o">=</span>myclient
</span></span><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">P4HOST</span><span class="o">=</span>perforce:1666
</span></span><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">P4USER</span><span class="o">=</span>myuser
</span></span><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">P4EDITOR</span><span class="o">=</span>nano
</span></span></code></pre></div><p>and then logged in</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">p4 login
</span></span></code></pre></div><p>More information on that set up can be found in the <a href="http://www.perforce.com/perforce/doc.current/manuals/p4guide/02_config.html"> official documentation</a>.</p>
<p>Once cloned, you can change to the project directory and use many of the normal git commands, such as “git log”. You may notice that your newly checked out git repo only has one commit. If you want to see a full history use @all on the end of your depot path.</p></description>
    </item>
    
    <item>
      <title>Python close_fds issue</title>
      <link>https://blog.bramp.net/post/2010/05/11/python-close_fds-issue/</link>
      <pubDate>Tue, 11 May 2010 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2010/05/11/python-close_fds-issue/</guid>
      <description><p>So I spent the better part of my evening trying to track down a bug, which turns out to be a “feature” of python.</p>
<p>I had just installed the <a href="http://trac-hacks.org/wiki/GitPlugin">GitPlugin</a> for <a href="http://trac.edgewall.org/">trac</a> but I started to experience problems. When browsing the source inside trac it was taking over 30seconds to load the page and sometimes it would fail completely. A lot of searching didn’t help much, so I attempted to debug the problem myself. The first thing I noticed was Apache was taking 100% of the processor for a good 30seconds. I attached <a href="http://en.wikipedia.org/wiki/Strace">strace</a> to it and saw something like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">[pid 22682] close(43029)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43030)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43031)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43032)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43033)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43034)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43035)                = -1 EBADF (Bad file descriptor)
</span></span><span class="line"><span class="cl">[pid 22682] close(43036)                = -1 EBADF (Bad file descriptor)
</span></span></code></pre></div><p>This obviously didn’t look good! After some tinkering I found the problem went away when I ran trac <a href="http://trac.edgewall.org/wiki/TracStandalone">standalone</a>, instead of using <a href="http://www.modpython.org/">mod_python</a> or <a href="http://en.wikipedia.org/wiki/FastCGI">fcgi</a>. This turned out to be a bit of a red herring because I spent my time trying to figure out what was different between a standalone executable and one being run inside Apache.</p>
<p>After playing around with environment variables, I gave up and attempted to printf debug the trac git plugin. I found that the actual call to git was taking on the order of seconds, whereas calling it myself from the command took milliseconds. The line of code (in PyGIT.py) looked a bit like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="n">p</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__build_git_cmd</span><span class="p">(</span><span class="n">git_cmd</span><span class="p">,</span> <span class="o">*</span><span class="n">cmd_args</span><span class="p">),</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">			                                        <span class="n">stderr</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">close_fds</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span></code></pre></div><p>Now, when I removed the close_fds argument the problems went away! After some more digging I found this <a href="http://bugs.python.org/issue8052">bug report</a> which describes the behaviour of close_fds. Python will spin in a tight loop calling close for all possible valid fd number just incase it was previously used. WTF! You can see the python <a href="http://svn.python.org/projects/python/tags/r311/Lib/subprocess.py">code here</a>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">_close_fds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">but</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">os</span><span class="o">.</span><span class="n">closerange</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">but</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">os</span><span class="o">.</span><span class="n">closerange</span><span class="p">(</span><span class="n">but</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">MAXFD</span><span class="p">)</span>
</span></span></code></pre></div><p>So the simple fix to this was to remove the close_fds, so that Python doesn’t stupidly spin calling close(). I suspect the reason I only noticed this when running inside Apache, is because Apache must have a larger MAXFD. Hopefully in the future Python will change this behaviour and find a more sensible way to close all file descriptors, especially when I read this <a href="http://bugs.python.org/issue7213">bug report</a> which advises changing close_fds default to true.</p>
</description>
    </item>
    
    <item>
      <title>Useful scripts/configurations</title>
      <link>https://blog.bramp.net/post/2009/11/28/useful-scripts-configurations/</link>
      <pubDate>Sat, 28 Nov 2009 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2009/11/28/useful-scripts-configurations/</guid>
      <description><p>Make <a href="http://git-scm.com">git</a> colourful</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git config --global color.diff auto
</span></span><span class="line"><span class="cl">git config --global color.status auto
</span></span><span class="line"><span class="cl">git config --global color.branch auto
</span></span></code></pre></div><p>Make <a href="http://www.nano-editor.org/">nano</a> colourful</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cp /usr/local/share/examples/nano/nanorc.sample ~/.nanorc
</span></span><span class="line"><span class="cl"><span class="c1"># or</span>
</span></span><span class="line"><span class="cl">zcat /usr/share/doc/nano/examples/nanorc.sample.gz &gt;~/.nanorc
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># then</span>
</span></span><span class="line"><span class="cl">nano ~/.nanorc
</span></span></code></pre></div><p>To trim trailing whitespace from *.cc on Linux (taken from <a href="http://zebert.blogspot.com/2009/06/clean-up-trailing-whitespaces-in.html">this blog</a>):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">find . -name <span class="s1">&#39;*.cc&#39;</span> -exec sed -i <span class="o">{}</span> -e <span class="s1">&#39;s/[ \t]*$//&#39;</span> <span class="s1">&#39;;&#39;</span>
</span></span></code></pre></div><p>and on BSDs:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">find . -name <span class="s1">&#39;*.cc&#39;</span> -exec sed -i <span class="s1">&#39;&#39;</span> -e <span class="s1">&#39;s/\ *$//&#39;</span> <span class="o">{}</span> <span class="s1">&#39;;&#39;</span>
</span></span></code></pre></div><p>Linux style ‘ls’ colours on FreeBSD (taken from <a href="http://www.puresimplicity.net/~hemi/freebsd/misc.html">here</a>):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">CLICOLOR</span><span class="o">=</span><span class="s2">&#34;YES&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">LSCOLORS</span><span class="o">=</span><span class="s2">&#34;ExGxFxdxCxDxDxhbadExEx&#34;</span>
</span></span></code></pre></div><p>To ensure the http_proxy environmental variable is passed to sudo. Edit the sudoers file by running visudo. Then add the following.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">Defaults <span class="nv">env_keep</span> <span class="o">+=</span> <span class="s2">&#34;ftp_proxy http_proxy https_proxy&#34;</span>
</span></span></code></pre></div><p>Bash autocompletion on FreeBSD:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span>  /usr/ports/shells/bash-completion
</span></span><span class="line"><span class="cl">sudo make install clean
</span></span></code></pre></div><p>Edit ~/.bashrc and add</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">if</span> <span class="o">[</span> -f /usr/local/etc/bash_completion <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
</span></span><span class="line"><span class="cl">    . /usr/local/etc/bash_completion
</span></span><span class="line"><span class="cl"><span class="k">fi</span>
</span></span></code></pre></div><p>Make svn output colorful<br>
Edit ~/.subversion/config</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[helpers]</span>
</span></span><span class="line"><span class="cl"><span class="na">diff-cmd</span> <span class="o">=</span> <span class="s">/usr/bin/colordiff</span>
</span></span></code></pre></div><p>Create diffs with function names and ignoring whitespace</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">svn diff -x -uwp
</span></span></code></pre></div><p>To be continued…</p>
</description>
    </item>
    
    <item>
      <title>64bit TortoiseGit</title>
      <link>https://blog.bramp.net/post/2009/02/15/64bit-tortoisegit/</link>
      <pubDate>Sun, 15 Feb 2009 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2009/02/15/64bit-tortoisegit/</guid>
      <description><p>Recently I tried <a href="http://code.google.com/p/tortoisegit/">TortoiseGit</a>, a <a href="http://tortoisesvn.tigris.org/">TortoiseSVN</a> style Git client, however there were no binaries for my 64 bit windows machine. The 32 bit version found on the official site would install, but the shell extension unfortunately does not work.</p>
<p>So I took the law into my own hands and went and built my own version.</p>
<p><del>So here is <a href="TortoiseGit-3.3.9d335-64bit.msi">TortoiseGIT 0.3.3.0 (64 bit)</a> built from revision 9d3351f627b26d9555794e785cf8bbae22155f12.</del> There is now a newer offical version available at: <a href="http://code.google.com/p/tortoisegit/downloads/list">http://code.google.com/p/tortoisegit/downloads/list</a></p>
<p>Hopefully 64bit builds will be available from the official site in the future.</p>
<p><strong>Disclaimer</strong>, I haven’t fully tested this app, and I suspect some features of the 64 bit build might be broken. Regardless I’ve been able to use at least the basic features of this version.</p>
</description>
    </item>
    
    <item>
      <title>A Practical Introduction to Version Control Systems</title>
      <link>https://blog.bramp.net/post/2009/02/04/a-practical-introduction-to-version-control-systems/</link>
      <pubDate>Wed, 04 Feb 2009 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2009/02/04/a-practical-introduction-to-version-control-systems/</guid>
      <description><p>Today I presented a CAKES talk in our department to help teach people about version control systems. I hope by sharing my knowledge on a subject, that others will share theirs. Below is the abstract and slides for my tak:</p>
<p>This talk aims to explain what version control systems (VCS) also known as source control management (SCM) are, how they work, and how to use them. This includes explaining why you should use VCS for your every day projects, even if they don’t include any source code. The differences between the main two classes of VCS; centralised and decentralised systems will be discussed, outlining both their benefits and disadvantages. This presentation will give you practical knowledge to start using systems such as subversion (SVN) or git, as well as many example use cases. Bottom line is that using a VCS can help you keep your work organised, backed up, revertible, whilst allowing contributions from multiple users. This talk is for anyone that has heard about CVS/SVN/git but was never quite sure what it was, or how to use it.</p>
<p><a href="version_control.pdf">Download Slides</a></p>
</description>
    </item>
    
  </channel>
</rss>
