More Git

Been using Git for a while now and getting to like it. Found out some more info about some of the commands.

The commands I gave previously for adding p4merge as the merge tool didn't do quite what I was expecting, and didn't actually work :)

After expecting git to use this merge tool whenever merges were needed it doesn't, you have to run it when auto merge fails using this command (discovered from this SO question):

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git mergetool[/sourcecode]

This will then go through each file with conflicts and run p4merge on them. Except that each time it tried to run p4merge it failed, so I guess the command was setup incorrectly.

I took a look at the .gitconfig file in my user folder and noticed that each of the file parameters to the p4merge.exe had got lots of slashes:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"][user]

name = Mike Hunt

email = someone@somewhere.com

[core]

editor = notepad.exe

[merge]

tool = p4merge

[mergetool "p4merge"]

cmd = p4merge.exe \\\"$BASE\\\" \\\"$LOCAL\\\" \\\"$REMOTE\\\" \\\"$MERGED\\\"[/sourcecode]

So I changed it to this:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]

[user]

name = Mike Hunt

email = someone@somewhere.com

[core]

editor = notepad.exe

[merge]

tool = p4merge

[mergetool "p4merge"]

cmd = p4merge.exe "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

[diff]

tool = p4merge

[difftool "p4merge"]

cmd = p4merge.exe "$LOCAL" "$REMOTE"

[/sourcecode]

And now it runs p4merge for the merges and shows the files properly, and also note the entry for the diff tool, so it uses that for diffs as well, using the command:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git difftool[/sourcecode]

Other things that had me scratching my head for a while were:

1) If I delete a folder from the working set I couldn't stage the delete (or commit it), which I discovered was due to me not using:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git add -u .[/sourcecode]

or

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git add -A .[/sourcecode]

-u (or --update) stages files based on what is in the index rather than the working set, so it won't add new files, but will update newly updated files that are already staged, and it will also remove files that were staged but have been removed from the working set.

-A (or --all) will do as -u but will also stage new files as well (lesson learned, "use git add -A ." from now on!) More details here

2) "git pull" performs a "git fetch" then a "git merge". The fetch fetches the remote branch to a local tracking branch based on the remote and branch you fetched, e.g. "git fetch unfuddle master" fetches the master branch from the unfuddle remote to a tracking branch locally called 'unfuddle/master'. The merge then merges that tracking branch to the local branch. e.g. if you are in the local branch "git merge unfuddle/master" will merge the changes.

3) If you mess up and want to reset your working files to the last commit:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git reset --hard HEAD[/sourcecode]

4) If you only want to reset individual files:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git checkout -- hello.cs[/sourcecode]

will reset the local working file hello.cs to the staged version

or

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git checkout HEAD hello.cs[/sourcecode]

will reset the local working file to the HEAD version (last local commit)

Here are some handy links that I have come across for finding this info:

http://stackoverflow.com/questions/255202/how-do-i-view-git-diff-output-with-visual-diff-program

http://gitguru.com/2009/02/22/integrating-git-with-a-visual-merge-tool/

http://stackoverflow.com/questions/866262/p4merge-error

http://www.andymcintosh.com/?p=33

http://www.gitready.com/advanced/2009/02/11/pull-with-rebase.html

Git :)

With the weather being a bit rubbish the past few weekends I have been geeking out (in addition to playing Uncharted 1 & 2) and been learning wpf, mvvm pattern and I decided to start using an open source source code control system. After some deliberation I picked Git (I did look at subversion and mercurial), it seems to have gained popularity and I wanted to see what all the fuss was about and if it was written and used by Linus for the linux kernel then it should be good enough for me :)

After some investigation I found msysgit which is basically git on windows. It effectively installs a bash shell on your windows box with all the git commands. I also decided to use Unfuddle as an online store of my source code. Here are the steps I took to get setup, mainly so that I can find them again if I need to do this later…

Installing msysgit was pretty straight forward, I accepted the defaults and it installed just fine. (This was after discovering the right package to download, as that is not immediately obvious, but it’s here, the git package, rather than the msysgit package)

Setting up git to work with unfuddle and setting up ssh keys etc was the next step, and also setting up the repo to work with Visual Studio, which is basically setting up a .gitignore file to tell git not to include certain files and filetypes in the source code control

Once git is up and running you should then set up some global config, an ssh-key can be created using the following:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]ssh-keygen –C “your@email.com” –t rsa[/sourcecode]

This will create the key in a folder called .ssh in your user folder. You then use this key to add to unfuddle (or github or wherever) so that you can be authorised against the remote repo.

Then set your username and email:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git config -–global user.name “Your Name”

git config –-global user.email "Your@Email.com”[/sourcecode]

In your user folder there should be a .profile file, if there isn’t then you can use

[sourcecode language="bash" gutter="false" 1="tab-size="4"" toolbar="true"]touch .profile [/sourcecode]

which will create a file without a filename and only an extension (you can't do this in explorer) Then add this to it, which starts up the SSH Agent when bash is run, so that you only have to enter the ssh key password once.

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]SSH_ENV=$HOME/.ssh/environment

function start_agent {

echo "Initialising new SSH agent...";

/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"

echo succeeded

chmod 600 "${SSH_ENV}"

. "${SSH_ENV}" > /dev/null

/usr/bin/ssh-add;

}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then

. ${SSH_ENV} > /dev/null

#ps ${SSH_AGENT_PID} doesn't work under cywgin

ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

start_agent;

}

else

start_agent;

fi

[/sourcecode]

This question on SO tells you how to change git’s default editor, I changed it from vi to notepad. (I use notepad2, but it’s installed to take over from notepad, so opening notepad.exe opens notepad2)

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git config –-global core.editor “notepad.exe”[/sourcecode]

This question on SO tells you how to change the default merge tool to p4merge, which is my merge tool of choice:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git config --global merge.tool p4merge

git config --global mergetool.p4merge.cmd ‘p4merge.exe \”$BASE\” \”$LOCAL\” \”$REMOTE\” \”$MERGED\”’[/sourcecode]

Then that should be the environment set up, after that its just a case of either creating a new repo or cloning one from unfuddle.

This page has the basic info on how to do it:

1) If you are starting a new repo, create it in unfuddle, then create a folder locally for it then:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git init[/sourcecode]

1b) you might also want to create a .gitignore file in the repo folder, so that you can tell git to only commit your source code, mine looks like this (you can tell where I ‘borrowed’ it from):

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]# .gitignore for .NET projects

# Thanks to Derick Bailey

# http://www.lostechies.com/blogs/derickbailey/archive/2009/05/18/a-net-c-developer-s-gitignore-file.aspx

# Additional Thanks to

# - Alexey Abramov

# Standard VS.NET and ReSharper Foo

obj

bin

*.csproj.user

*ReSharper*

*resharper*

*.suo

*.cache

*Thumbs.db

*.scc

# Other useful stuff

*.bak

*.cache

*.log

*.swp

*.user

_compareTemp

_notes

aspnet_client

httpd.parse.errors

# Office Temp Files

~$*

# If you have a deploy folder

deploy

deploy/*

# Exclude ALL DLLs?

#*.dll[/sourcecode]

2) Associate the repo with the unfuddle remote repo:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git remote add unfuddle git@subdomain.unfuddle.com:subdomain/abbreviation.git

git config remote.unfuddle.push refs/heads/master:refs/heads/master[/sourcecode]

2a) If you already have code in the repo you can clone it

3) Finally, write some code, and when you are happy and want to commit the changes to your local repo:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git add *

git commit[/sourcecode]

4) Then push the changes to the remote unfuddle repo:

[sourcecode language="bash" gutter="false" firstline="1" toolbar="true"]git push unfuddle master[/sourcecode]

Fishing

Just spent the morning rock fishing at Whale Beach, and this time we actually caught something! It's a beautiful day, blue skies, blue seas, and almost no-one there so we got to pick our spot.









The sun is a good cure for a hangover

Well, we decided to head out for beers and pool last night, so after some dinner at James Squires I introduced Dave to the delights of the Shark Hotel. It has supposedly been refurbished, but looked pretty much the same to me, although they have taken up some of the space for more chairs and tables, and squashed the pool tables together a bit. Still, it didn't affect my game, as I lost most of them to Dave, who seems to be getting the hang of these funny upside down tables now. Needless to say, a lot of boags, strongbow, and g&t's were quaffed, hence my "special" feeling this morning.

Dave pursuaded me to go with him to sit in the sun on the grass at the botanical gardens and I'm sat here on the grass typing this. Not a bad idea Dave! I've attached some pictures of Dave enjoying himself, mind you it's only about the 3rd day or so of sun that we have had since he got here, so he's been enjoying the decidedly English-like weather up until yesterday!

Oh and happy Halloween too!







We've all arrived in Filey

We're all settled in, it's a little bit windy and a bit pearl harbour, I doubt I'll be going for a dip in the sea, I'll wait till I get home to Sydney for that

I am really using my iPhone for stuff these days

I'm surprised at how much I am using my iPhone nowadays, and what for.

I've managed to steer clear of eBooks for a long time, being a firm believer of having a nice chunk of mashed up tree in my hand is part of getting into a good book. However, I have recently installed iPhone app Stanza and downloaded a couple of eBooks. Partly because books are really expensive over here, and partly because I didn’t want to lug a book around with me on my way to work.

I have to say that I have got into reading on my iPhone, I’ve bought a copy of the book I am reading at the moment, Day Watch by Sergey Lukyanenko and just carried on reading from where I had already got to in the paper book. I had thought before I gave it a try that the iPhone would be too small to read on, but using it I don’t think that’s the case. The app remembers where you got to in each book, it has online catalogues that you can browse to either purchase books and download them there and then in the app or safari, or just download from the many free catalogues too, like project gutenberg.

Since I was on a roll with eBooks, I thought I’d give video a go, to make the journey to and from work pass quickly. After some research (well, googling, still not that impressed with bing) I discovered an opensource project called Handbrake which is a video transcoding app. It has a default setting for iPhone, and I just ran some tv shows through it and hey presto, 200mb m4v files of each episode, no matter what format I threw at it, xvid in avi, or h264 in mkv, it sorted them all out.

Most impressed, a quick iTunes sync with the iPhone and the next morning I was watching TV on the way to work, great quality, really watchable even on the screen size that it is (I think handbrake crops the video as well as shrinking it so you may lose some of the edges of the frames, but it doesn’t make everything really tiny).

The only thing I have to be careful of now is missing my stop on the train cos I am too busy watching tv :)

Sydney moved to Mars

Woke up yesterday morning after it being really windy all night, to the deep orange glow of a very dusty Sydney. Very eerie it was, sorta like you'd think a dust storm on Mars would be :)

Took a couple of shots with my iPhone camera:

[caption id="" align="aligncenter" width="425" caption="Dusty Sydney"][/caption]

[caption id="" align="aligncenter" width="425" caption="Dusty Sydney in my apartment"]Dusty Sydney in my apartment[/caption]

It had mostly gone by lunch time and things were back to normal

Some general Winforms coding info

The difference between Control.Invalidate, Control.Update and Control.Refresh:

Control.Invalidate()

Adds a region or a control to the update region of a window

Control.Update()

Sends WM_PAINT to the window if the windows update region is not empty (sends directly to wndproc bypassing the apps message queue)

Control.Refresh()

Calls invalidate and then update

String format alignment enums

The names of LineAlignment and Alignment (plus the descriptions in their tooltips) are confusing and I keep forgetting which one is which.

StringFormat.LineAlignment

Text alignment vertically

StringFormat.Alignment

Text alignment horizontally

Scrollbars

The scroll value automatically takes into account not scrolling the amount at the end of the range given by LargeChange. According to reflector:

case ScrollEventType.SmallDecrement:

newValue = Math.Max(this.value - this.SmallChange, this.minimum);

break;

case ScrollEventType.SmallIncrement:

newValue = Math.Min((int) (this.value + this.SmallChange),

(int) ((this.maximum - this.LargeChange) + 1));

break;

case ScrollEventType.LargeDecrement:

newValue = Math.Max(this.value - this.LargeChange,

this.minimum);

break;

case ScrollEventType.LargeIncrement:

newValue = Math.Min((int) (this.value + this.LargeChange),

(int) ((this.maximum - this.LargeChange) + 1));

break;

A compact framework tip

Thought I'd start posting tips and reminders here for things about coding I have found useful, mainly as a place where I can store them so I can find them again when I have forgotten them in the near future :)

So this one is the location of the actual compact framework assemblies on your development machine, handy for loading into reflector.

C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL

The Behemoth has arisen

It’s been an interesting weekend, and it’s been a geeky weekend. It started on Friday with my new PC locking up a few times, and blue screening. It had been working nicely all week, and then starts playing up all of a sudden on Friday.

So Saturday morning I get up and can’t turn it on, until I power off the PSU. Then once it got past POST it wouldn’t boot into windows. Grrrr.

Finally after trying an Ubuntu LiveCD and checking that the drives were ok etc. I tried it one last time before an O/S reinstall and hey presto! It boots again.

So I copy off my data, just to be on the safe side, and then I decide to reformat and reinstall anyway. I did the same to the mediacenter pc as well, because that got an upgrade to 64bit :)

Then I spent the rest of the day attempting to install vista or windows 7 on the new pc. Either it would fail and reboot during the installation, or would install, then crash, or install and crash during first boot, or many other combinations. Needless to say, starting to get annoyed, very annoyed.

I got the media center pc up and running again (and finally got the dual boot vista 64 and windows 7 64 bit going) and started reading up on cpu voltages, temps, base clock frequencies and multipliers, with a thought that maybe the new 975 cpu wasn’t being supplied enough volts by the motherboard as standard. Had a play with the overclocking settings, but still not booting.

Finally thought it might be some dodgy ram, so spent a couple of hours stress testing it with memtest86+, no errors.

As a last resort I took out all the components I could, just to see if I could install the o/s with bare minimum. As it happens, that wasn’t much, 1 SATA drive, and 2x2GB memory sticks, and the pcie soundcard.

Surprisingly it booted and installed ok, so I started adding bits back in one by one to see if I could find the culprit. However, I couldn’t get it to fail. So then thought maybe the ram wasn’t seated properly (or had become unseated) and started setting everything back up, then went to bed.

Sunday morning, and it’s still crashing, although not as much. I don’t really know what could be causing it, but have been reading about a few tools. I had stressed the memory yesterday and couldn’t get it to fail, so I thought I should check the CPU. So I downloaded a copy of LinX which is a CPU stress tool, along with CPU-Z and Everest (so I could monitor core temps and voltages)

I set LinX going and all 8 threads (4 cores with HyperThreading) went up to 100% cpu usage, and the core temps started going up from 40 odd degrees to about 70-75 degrees c which I thought was a little warm.

Unplug everything time, and then I gave it time to cool off before removing the cpu heatsink and fan, it’s a huge Zalman thing. I checked the thermal compound and the CPU and it all looked fine. However just to be on the safe side I cleaned both the cpu and the heatsink and re-applied more thermal compound, a lot more :)

I took the opportunity to take a few shots of the beast whilst it was out and in pieces, forgot when I was building it last week.

Connect it all back up, boot up first time, nice :) Start running the stress tests again, idle core temps around 35 degrees, and running a LinX test using all system ram the temps never got over 65 degrees C. So it looks like that was the issue.

Since then I have set the memory speed to 1800Mhz (rather than the default 1333Mhz) and it’s running nice and stable, I couldn’t even get Windows 7 to do a Windows Experience Assessment with the memory on that setting before.

Fingers crossed it seems to have sorted out all the instability issues I was having, and also my netgear router hasn’t b0rked itself since either, which it seemed to have been doing regularly since I got the new PC. I wonder if the crashes were spannering the network cards in the pc and causing some traffic that the router couldn’t handle… we’ll see anyway.

So after planning a weekend of using the PC to finish off some stuff for work, play with Visual Studio 2010 and of course a go on WoW, I end up re-installing and messing with OC settings etc. It’s Sunday evening and my pc is almost back to normal now.

The lesson learned here though is that every time I build a pc now I will be using the set of stress tools to check memory, cpu, etc. to make sure that it has been built properly.

Here’s a couple of shots of the behemoth :)

 

The Behemoth

The case is massive, only just fits under the table!

The Behemoth

 

The Behemoth

There are it's innards, with a case this big there is plenty of room. You can see the Zalman CPU cooler, the red fins on the Dominator memory. Very happy with the case, it’s also ready for liquid cooling, the reservoir pipes have ready made holes in the chassis (at the top of the pic)