Saturday 7 July 2012

msysgit & corrupted symbolic links

Using msysgit on Windows?

Let's say the project you are cloning has:

real-directory-1/
real-directory-2/linked-directory-1/
Where linked-directory-1/ is a symbolic link to real-directory-1/.

What you will find in your clone of this project is:
real-directory-1/
real-directory-2/linked-directory-1
Where linked-directory-1 is a file containing the local path of what it's target would be if it were the symbolic link it were supposed to be.


The problem?

Cloning projects in a broken state just seemed.. ridiculously unusable.  I've wasted hours on errors that appear to be in one place, but are actually because of these broken symbolic links.  With a bit of googling, I encountered someone suggesting that someone else set their core.symlink GIT setting.  Out of curiosity, I decided to check the .git/config file in my cloned project.

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly

I don't understand..  The default value is to create broken clones, with missing symlinks and junk files littered throughout them?  Is there something I am missing here?

The solution?

A bit of further searching revealed that you can set this setting globally.  Something like:
git config --global core.symlink true
After executing that, and then modifying the red highlighted project-specific setting..
$ git checkout -f
error: unable to create symlink AndroidAppSettings.cfg (Function not implemented)
error: unable to create symlink project/jni/application/atari800/atari800 (Function not implemented)
 
Now the files are missing, but at least I know that the clone is bad.

I think the best approach is to have it work this way by default, then cloned projects can have their local setting changed in their configuration file.  Then the corrupted clone can be processed with a script to turn the corrupt files into the links they should be.

The following almost does the trick:
#!/bin/sh

git ls-files -s | awk '/120000/{print $4}' | while read FILEPATH
do
    if [ ! -e $FILEPATH ]; then
        echo "Please check that GIT core.symlink for this project is 'false'" 1>2
        exit 1
    fi

    if [ ! -L $FILEPATH ] && [ -f $FILEPATH ]; then
        wc -l $FILEPATH | while read LINES DISCARD
        do
            if [ "$LINES" = "0" ]; then
                FILEDIR=`dirname $FILEPATH`
                FILENAME=`basename $FILEPATH`
                LINKPATH=`cat $FILEPATH`
                pushd . > /dev/null
                cd $FILEDIR
                if [ -e $FILENAME ]; then
                    if [ -e $LINKPATH ]; then
                        ln -s -f $LINKPATH $FILENAME
                        echo "Repairing symlink: $FILEPATH"
                    else
                        echo "$FILEPATH: symlink path '$LINKPATH' invalid" 1>2
                    fi
                else
                    echo "$FILEPATH: problem finding this file"
                fi
                popd > /dev/null
            else
                # ERROR: Expected a file with one line for the link path
                echo "$FILEPATH: bad link file: expected 0 lines, got $LINES" > /dev/null # 1>2
            fi
        done
    else
        echo "$FILEPATH: already a symlink" > /dev/null # 1>2
    fi    
done
What it does not do, is create a symbolic link within the same directory, to that same directory the link is intended to reside within.

Conclusion

Do not use Git for Windows AKA msysgit.  Even if you work around the corrupted files with the above script, you cannot make the links yourself because some cases are not supported by the ln command.  You can get a little further by switching over to a MinGW msys installation (the above script works in the "does not do" case), but there are still problems.  It is probable that MinGW ln is copying, rather than linking, given the time the script takes to run.

Cygwin has the same problem, when using it's git command.

Portable Ubuntu has been recommended, but I haven't tried it yet, or looked at it's suitability.

Next: Android NDK & Windows symbolic links.

Tuesday 3 July 2012

Broken gǔzhèng strings

This post is intended to record what I have learnt about tuning my gǔzhèng (古筝), and sourcing new strings in New Zealand.

When you transport your gǔzhèng, you remove the bridges to prevent the strings from breaking if weight is placed on them.  The next time you want to play it, you replace the bridges and retune each string.

2012-06-29 - Gu Zheng - 03 - Bridges
Gǔzhèng bridges
Replacing the bridges and tuning the strings, I snapped three of the higher ones (1, 6 and 7).  These are the thinnest, and are more likely to break.  With my bad tuning technique, I think some of the lower strings are also damaged but are thankfully still usable and whole.

2012-06-29 - Gu Zheng - 05 - Instrument
Tuning knobs and strings
The best solution would have been to find suitable strings in local music stores.  I tried two local stores and it became clear this wasn't something they dealt with ever.  The first store was staffed by a Chinese lady who knew what I was talking about, and later called to suggest looking in one of the many local Chinese newspapers for gǔzhèng teachers as they often sell parts or instruments (as teachers also do in China).  The second showed me a selection of strings for other instruments that might be suitable, but we concluded they weren't and they kept my number in case they located any.  When they later called back, they had found a local teacher who would sell individual strings at $5 NZ a piece.

In the meantime, I had ordered and received several sets (a full 21 piece, and two sets of 1-10 strings) from a store in the USA called Sound of Asia.  This came to about $70 NZ including shipping, and was much cheaper than buying from a local teacher would have been given the price above.  It also arrived extremely quickly, within 3-4 days of ordering.

2012-06-29 - Gu Zheng - 02 - Strings
Sound of Asia sourced strings
With the new strings and a desire not to have to order more, I had researched (and learnt in the practice of doing this) some guidelines to follow when replacing the bridges:
  • Bridge placement: Use the tuning chart from the Sound of Asia web site, which illustrates best bridge placement for each string.  You can see white tape on the left side of my gǔzhèng, in the first picture.  This is where I've measured and marked each of the distances.
  • String fitting: There's a trick to properly winding the new string onto it's tuning knob.  Wind the string around the knob several times before pushing the end of the string through the hole.  If you do not do this, then you'll run out of tightening room before your strings are tightened enough.
  • String tuning/tightening: When turning the tuning knob for a given string tighter, take the string off the bridge, tighten and then having done that replace the string on the bridge.
I've included the tuning chart below, as I am unable to locate it on the Sound of Asia site any more.

Good luck!  And here's a YouTube video of someone playing Richard Marx's Right Here Waiting on one of these instruments, just for the sake of it.  I've got to learn more about music so I can try playing some western songs.