View unanswered posts | View active topics It is currently Mon Nov 20, 2017 8:54 am



Reply to topic  [ 2 posts ] 
Git keyword expansion tip 
Author Message
QFP80 - Contributor
User avatar

Joined: Tue Jul 06, 2010 1:03 pm
Posts: 45
Location: Espoo, Finland
Bumped into a simple problem when designing a PCB with eagle. Wanted to have a Git commit id in the boards silkscreen that would update automatically. As Eagle files are in XML it should not be a big problem.

You can use the clean/smudge filter in git attributes to do this:
http://git-scm.com/book/ch7-2.html#Keyword-Expansion

You can specify a custom keyword that you "clean" when you add or commit files. When you take the file out of the repo it will "smudge" the keyword with the info you want. I'll explain my approach here.

Here is the part of the XML file holding the Git hash. This is what it looks like after smudge.
Code:
<text x="95.885" y="10.16" size="1.4224" layer="21" rot="R180">GIT 73d710e</text>


And this is what it looks like when you create the file and in repo after clean:
Code:
<text x="95.885" y="10.16" size="1.4224" layer="21" rot="R180">%GIT_COMMIT_ID%</text>


You can use git attributes file to add a custom command like this:
Code:
my_ultimate_board.brd filter=hasher

.gitattributes

I call it the "hasher". This command is then specified either in the global git config or under the project config:
Code:
[filter "hasher"]
        smudge = sed \"s/GIT %GIT_COMMIT_ID%/GIT `git rev-parse --verify HEAD --short`/\"
        clean = sed \"s/GIT [0-9a-z]\\{7\\}/GIT %GIT_COMMIT_ID%/\"

.git/config

I just used simple sed regexp replace commands to find and replace the hash/keyword. You can use whatever command you like/have or script. You can also alter the git command as you please. Maybe use git describe etc.

One problem with this approach is that after you commit the file the new commit id won't be available until after you checkout the file again. So remember that.

To get the id into eagle I save the file, commit, delete the file and checkout the file again. Then I can make the gerbers or whatever I publish with the current commit id.

Thats it. Hope this comes in handy and if you find a better approach or enhance this, let me/us know.


Sat May 04, 2013 11:53 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 14871
Location: Home sweet home!
That problem with the having to check it out again, is that normal? Or something to do with your setup? I hadn't heard of that before. If it is normal, you could likely use a hook to do a checkout of the file post commit. Just FYI.

Thanks for posting it up! :-)

Fred.

_________________
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!


Sat May 04, 2013 1:14 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF. ColorizeIt.