Setting up and using a git wrapper around SVN with git-svn

Posted on January 27th, 2012 in git, Uncategorized | No Comments »

Note: I wrote this post a long time ago but never got around to posting it. A lot of these steps are applicable to porting an SVN repo to Git as well.

Preface on why I love git

Roughly four years ago I switched to git for version control and it’s changed my development life. While SVN is sufficient to “get the job done” in terms of keeping a history of your commits with a group of people, Git is truly the next evolutionary step up in every way. I could expound a whole article on the joy of git, but many others already have, and this articles not about that. But I will kindly throw in my 0.02 on why I personally love it:

  • It’s fast. Git keeps your whole repo’s history local. So no need to ping your repo server for every command. You can even checkout your codebase from 3 weeks ago or a year ago in under a second.”
  • It works offline. That’s right, no internet. Sync up later.
  • It has useful modern tools. Like git stash and git bisect. Both will save you a lot of time.
  • It’s your third hand. Let’s face it, besides svn being slow, it’s not friendly enough to do more than throw your past commits into an empty hole you will probably never see again. With very little setup, you have beautiful colored output in your logs and diffs with git. And “git log” actually pages by default (while keeping colors) instead of flooding your console with the entire repos history! Want to query something in your history log? What about all commits from your friend Bob in the past 2 weeks?
    git log --date=relative --author=nizam --since="2 weeks ago"

    Bam. Done.

  • Easy repo creation. You don’t have to be an admin to setup a git repo. Just cd into a folder and type “git init”. You just created a new repo. I do this all the time, for example in my folder of todo lists, I use it to track history of my todos. At work someone kept messing up the apache config file, all I had to do was “git init” in /etc/httpd/conf and now I can easily “git diff” new changes that were made and revert / adjust if needed.
  • Many ways to use it. Git is promoted as “decentralized” version control, but it can be an easy drop in replacement for any job SVN can do. Which leads me to…

With all those advantages, many larger companies haven’t jumped on the git bandwagon. I believe there’s two reasons this is the case.

  • As programmers get more experienced, they generally become more pragmatic (which is generally a good thing.) They adopt a “if it ain’t broke, don’t fix it.” mentality. After all, SVN get’s the job done.
  • There is a bit of a learning curve with git. But there are a ton of good resources for learning it. I recommend getting your hands dirty with Git Immersion if you’re new or would like to learn. I don’t recommend wrapping git around svn as I’m about to show you for a person who’s learning git.

Getting down to business.

In order to use git with an svn repo, you’ll have to run some commands to import that svn repo, commit by commit into a git repo.

1. First, make sure you have a version of git installed with svn bindings. If you type “git svn” and it give you an error, I’d google one of the resources in reinstalling git with svn bindings.

2. We need to keep

# In your existing svn repo, lets grab a list of authors
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
# create a new folder
cd ..; mkdir NEWREPO.git;
git svn clone -A ../OLDREPO/authors.txt https://svn/repo/trunk
git svn fetch # this could take a long time as it checks the repo out one rev at a time.
 
# update your working copy:
git-svn rebase
 
# commit your changes to svn server
git-svn dcommit

kudos to:

http://flavio.castelli.name/howto_use_git_with_svn

Great little bash snippet to summarize your daily git commits.

Posted on January 9th, 2012 in bash, git | No Comments »

For general invoicing and hour tracking, I like to post the details of my git commits. Though, I had my own little version of this script, this one posted at stackoverflow was a lot better looking. Posted here for posterity:

function gdaily {
    NEXT=$(date +%F)
    echo "CHANGELOG"
    echo ----------------------
    git log --no-merges --format="%cd" --date=short | sort -u -r | while read DATE ; do
        echo
        echo [$DATE]
        GIT_PAGER=cat git log --no-merges --format=" * %s" --since=$DATE --until=$NEXT
        NEXT=$DATE
    done
}

Which looks like:

[2012-01-07]
 * Refactor list portfolio page css and js.
 * namespace.data include to load fake api data until it is ready. Portfolio list working again.
 * CurrentUser model defaults and code cleanup.

[2012-01-06]
 * Upgrade portfolio call from GET and POST. To be discussed in tomorrow's standup.

Low powered web servers and resolving issues installing Ubuntu on an Android Galaxy S

Posted on November 21st, 2011 in android, Linux | 2 Comments »

I’ve been on a multi-month long side project trying to create a low powered web server for hosting an offline version of Wikipedia in the dessert (long story). I assembled my own machine from Newegg but even with solid-state it was running between 30-50 watts.

My latest approach has been modifying a Linksys NSLU2, an old low-powered network storage device, and installing Debian on it (thanks to great documentation from the NSLU/Linux community). The end product is a web server that runs between 3-5.5 watts! And it’s able to support two usb drives. Not the fastest machine but certainly useable, especially at the cost of only $35 used for the device off Craigslist (compared also to the $225 or so I spent assembling the machine above.)

While I think it’s the approach I’m going to go with, I found a link where someone installed Ubuntu on their Android device. This piqued my interest as it’s also a low wattage device (and the fact that I have a Galaxy S sitting around doing nothing.) I followed the steps, and though it worked well, the Ubuntu package manager has problems when you want to install any new packages or do an update. It just 404′s like so:

Err http://ports.ubuntu.com karmic/main Packages
  404  Not Found

After much research I ended up having to change /etc/apt/sources.list from:

deb http://ports.ubuntu.com/ubuntu-ports karmic main universe

to:

deb http://old-releases.ubuntu.com/ubuntu/ karmic main universe

I tried to post this update to the blog above but it errored out, so I’m leaving the solution here instead should anyone else have the issue.

Additional note In the case of the NSLU2: if DHCP has assigned the Slug an ip address but your wireless router doesn’t find it, use nmap to ping for port 22 on your subnet:

nmap -p 22 --open -sV 10.0.0.0/24

Common Backbone errors and what they mean.

Posted on October 22nd, 2011 in backbone | 3 Comments »

I’m a big fan of Backbone, the open-source JavaScript MVC framework. It’s lightweight, extendable, has an awesome event model that allows one to bind to changes from just about anything – it’s error messages, however, can be quite cryptic. Simply referencing a missing template file can lead to half an hour of wasted time tracking down the issue. Without further ado here’s a quick list of the day-to-day errors I occasionally encounter and what the problem ended up being:

TypeError: ‘undefined’ is not a function (evaluating ‘func.apply(obj, args.concat(slice.call(arguments)))’)

You probably created an event listener in view that binded to a function that doesn’t exist.

invalid ‘in’ operand attrs

You probably passed a string instead of an object to a Model.set. This frequently happens to me during an ajax callback using jQuery – for some reason Webkit browser return and object while Firefox returns a string.

Uncaught TypeError: Cannot call method ‘replace’ of null (underscore.js:768)

You’re calling an underscore template put not passing in the data it uses in the template. You’re referencing an underscore template that doesn’t exist. You could have created a new template but forgot to change it’s id.

TypeError: ‘undefined’ is not an object (evaluating ‘func.bind’)

You probably set a _bind or _bindAll in your view initiailize code and that method doesn’t exist in this view. Double check for a typo.

TypeError: ‘null’ is not an object (evaluating ‘func.bind’)

In your view you could be binding an event to a callback that got overwritten during initialization. Commen when your model is called “contact” and your model is called the same and gets passed in.

TypeError: ‘undefined’ is not a function (evaluating ‘this._configure(options || {})’) backbone.js #881

Something went wrong in the routing. You may have not instantiated a new view.

Uncaught TypeError: Cannot call method ‘extend’ of undefined (yourfile.js)

Your probably extending an object that extended a backbone object, but the reference to the object is wrong or missing.

Uncaught SyntaxError: Unexpected identifier (underscore.js:782)

Your template logic might have an error in it. Check that you closed open parens and such.

If you’ve experienced a Backbone error that’s not on the list, feel free to post it in the comments.

Response Times: The 3 Important Limits

Posted on October 22nd, 2011 in General Web Dev | No Comments »

Regardless of new technology and devices the basic advice regarding (perceived) response time has been the same for forty years in counting. I find that I’m always having to google around to find this link when the subject pops up so I’ll post the basics here, and link to the rest if you’re interested in reading more.

  • 0.1 second is about the limit for having the user feel that the system is reacting instantaneously, meaning that no special feedback is necessary except to display the result.
  • 1.0 second is about the limit for the user’s flow of thought to stay uninterrupted, even though the user will notice the delay. Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second, but the user does lose the feeling of operating directly on the data.
  • 10 seconds is about the limit for keeping the user’s attention focused on the dialogue. For longer delays, users will want to perform other tasks while waiting for the computer to finish, so they should be given feedback indicating when the computer expects to be done. Feedback during the delay is especially important if the response time is likely to be highly variable, since users will then not know what to expect.

From the book Usability Engineering (1993). More info here.