Monday, November 8, 2010

Some simple commands to setup your first git repository coming from a subversion background.

Coming from Subversion we're used to a primary repository that we can import, do editing and commit our changes to.

Git can do this, but it may be a little slow going until you read a few pages of docs. One concept that I had to understand was that every git project directory is a repository with a history of changes. Subversion only keeps revisions on the server.

To create your a primary git repository and another directory in your main dir:
  1. First make a bare git repository
    Create a directory to store this project. I used /srv/git/yourappname
  2. cd /srv/git/yourappname and run git init --bare
    This is important and it will act only as a repository. In other words without the --bare flag, a repository is created with the expectation that source files will be in this directory and will be editted.
  3. Go to your workspace directory and import, or in git terminology - clone the project
    cd ~/workspace
    git clone /srv/git/yourappname myapp
At this point you now have your project setup and you can start to edit files. Like any versioning control system, you will want to know how to add and commit your changes.
  1. cd ~/workspace/myapp
  2. Edit some files
  3. git add .
    (do this in myapp)
  4. git commit -a -m  'my commit'
Your own repository will have all the changes, they're committed, and you may continue to edit. If you want to revert or check history like you do with subversion, you will be able to. The next consideration is what if you want to now sync up with the original repository aka in svn syncing with the trunk. There's a nuance here that the first committer needs to do or you get a message like this:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/srv/git/yourappname'

Reading some of the docs, one would expect you would only need to type in git push to do this. The first time you need to do:
  1. git push origin master
    What this does is create the the master branch on the origin repository. I supposed this is like creating the trunk in svn.
  2. Subsequent pushes only require git push to update your code on master.
  3. Even if you delete ~/workspace/myapp and do another clone, you will again only need to do git push

Getting this to work with Eclipse

If you're using linux, there are a few gui's available gitg, gitk, git gui (That's the command 'git gui'). Some of us use eclipse as our primary ide, so it's convenient to have git integrated with our workflow. Here's how to set it up. Sorry I'm too lazy for screenshots. I'm using Eclipse Helios SR-1

  1. Make sure you have the git plugin.
  2. If you did the above steps you can add that git project to the Git Repository Interface.
  3. Select 'Add an existing repository to this view'
  4. Select /home/you/workspace/myapp
  5. The repository will appear in the interface, like a repository appears eclipse subclipse.
  6. Click on Working Directory and select 'Import Projects'
  7. Go through the wizard, select your project type and tada, that's all there is. You will now have a git managed project where you can commit your changes to. Like SVN, you go to TEAM and perform the operations tasks you want.
To push with eclipse, select master, master and add spec.

Monday, September 27, 2010

Eclipse Helios PDT and 50% CPU Usage

Running Windows XP, PDT 2.2 and Eclipse Helios All In One.

Eclipse would remain sluggish even after a clean install and waiting for a period of time for the build to finish.

One possible to having unaturally high CPU usage is:

Go to preference and turn off Semantic Highlighting.

As a side note another one is to turn off code folding.

Wednesday, January 27, 2010

mod_rails We're sorry, but something went wrong. message

After running rails by exec'ing script/server I installed mod_rails/Phusion to run rails through apache.

I was getting this message

"We're sorry, but something went wrong. message"

Not a lot of help, and I was uanble to find much in the logs and user manuals either.


1) By default, mod_rails runs your app in production mode. When you're running rails through script/server it is in development mode.

2) You can either run rake db:migrate RAILS_ENV="production" which will build the production database from the values in database.yml

3) Or if you want to keep on using the dev database add this line to your apache virtual host

RailsEnv development

Thursday, January 21, 2010

cakephp mod_rewrite optimizations

A few people on the wordpress forums were discussing ways to improve the performance by editing the .htaccess file. Since WP and cakephp along with other PHP frameworks use a similar method of improving URLs, here's my attempt at improving cakephp's ./webroot/.htaccess

# optimizations
RewriteEngine On

# images in these dirs tells mod_rewrite to stop processing
# '-' means to pass request unchanged. ie serve it immediately
RewriteRule ^(img|css|js)/(.*)\.(gif|jpe?g|png|ico)$ - [L,NC]
# these other files are served as is anywhere in ./webroot
RewriteRule \.(swf|css|js)$ - [L,NC]
# If File is a file or is a DIR then skip (1 rule) and serve the file
# (vs before where it was !-f AND !-d Not a file AND not a dir, two checks vs less than two if the first one matches)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [S=1]
# else rewrite the request
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]