Dariusz on Software Quality

02/06/2011

Perforce -> GIT import

Filed under: en — Tags: , , — dariusz.cieslak @

I’ve been assigned recently a task to prepare development process for two teams that are working on separate version control systems (GIT and Perforce in my case). One of important parts of this task is to create effective method of syncing codebases between both storages.

Of course we have git-p4 tool, but my requirements are a bit complicated for this tool:

  • Only subset of whole GIT repository will be stored in P4
  • GIT repository already exists with some history (the same for P4)

so I decided to write small script that will do at least P4 -> GIT sync.

(more…)

07/04/2011

Simple shell lock implementation on Linux

Filed under: en — Tags: , — dariusz.cieslak @

Sometimes you want to avoid running second instance of some shell script. Locking implementation is not very hard:

LOCK_FILE=$0.lock
test -f $LOCK_FILE && {
        PID=`cat $LOCK_FILE`
        echo "$LOCK_FILE exists, PID=$PID, exiting"
        exit 1
}
echo $$ > $LOCK_FILE
trap "rm $LOCK_FILE" 0 2 3 15

29/10/2010

Micro-tools: Linux command line find & replace

Filed under: en — Tags: , , — dariusz.cieslak @

Sometimes you have to update many files at once. If you are using an IDE there is option during replace “search in all files”. I’ll show you how make those massive changes faster, using just Linux command line. Place this file in ~/bin/repl

#!/bin/sh

PATTERN="$1"
FROM="$2"
TO="$3"

FILES=$(grep -le "$FROM" `find . -name "$PATTERN"`)
echo Files: $FILES

sed -i "s!$FROM!$TO!g" $FILES

Sample usage is:

repl "*.cpp" "loadFiles" "retrieveFiles"

Some explanation about script:

  • grep -l: shows on stdout only filenames of matching files
  • grep -e: accepts pattern as argument
  • sed -i: changing files “in place”
  • grep -le: we want only files that will match $FROM to be updated (minimizes build time after change)

Pretty easy and powerful. Enjoy!

« Newer Posts

Powered by WordPress