Storing FreeCAD files in a git repo

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: Storing FreeCAD files in a git repo

Post by galou_breizh »

Thank you shoogen for providing this tool. However, I couldn't have it work:

Code: Select all

>>> App.getDocument("contact_sensor_leg_side").save()
>>> import zip2git
>>> zip2git.saveandcommit(App.ActiveDocument, 'git_repo')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/gael/.FreeCAD/zip2git.py", line 396, in saveandcommit
    commitid = commitfile(filename,repopath=repodir,refname=branch,
UnboundLocalError: local variable 'branch' referenced before assignment
Don't you want to make a normal git repository for it, so that issue list is enable?
petebachant
Posts: 1
Joined: Wed Oct 14, 2015 11:03 pm

Re: Storing FreeCAD files in a git repo

Post by petebachant »

It would be great if an entire project were structured around a Git repo, such that one could diff/merge from the command line and actually understand what they were reading! Using GitHub pull requests for collaboration on CAD projects would be really cool. Has anyone made any progress on this?
bkw
Posts: 31
Joined: Tue Mar 01, 2016 12:18 am

Re: Storing FreeCAD files in a git repo

Post by bkw »

I wish I could figure out how to use this. I copied all 4 py files from the gist to my user macros dir, installed the latest dulwich from git, copied dulwich py and some long named *.egg file to the macros dir, and at least got to the point where I don't get dulwich errors any more, but I get no further.

I copied all 4 files to my user macros dir.
It failed with cannot import dulwich.
I installed dulwich from git.

Then when it still wasn't found I copied /opt/brew/bin/dulwich to dulwitch.py in my macros dir. It's only a tiny py file that loads something else, but I can't tell where it looks for the thing it wants to load, so it was no surprise that it still failed.

So when it failed with a message that it couldn't find dulwich--0.12.1... , I poked around my system at random and in the dulwich source tree I took a wild undocumented stab in that dark that the only thing that looked like it even might be, or possibly contain, the missing stuff is this "*.egg" in a build directory. Having no idea what I was really doing, I copied the .egg file to the freecad user macros dir. That seems to have worked. At least I no longer get errors about dulwich in the report log.

I tried to execute "checkoutgui", but it just said can not load porcelain. I don't know what that is or where I might find it, or put it, but I also don't know if I was even supposed to execute checkoutgui directly in the first place, or if something else was supposed to execute it. It says gui in the name, so it seemed like a reasonable guess that it's the front-end that runs the other stuff.

So, I have a few freecad files in a git repo already, whole freecad files with compression level 0, not unzipped freecad files.
So just to see what happens, I tried to execute "checkoutandload" and select that git directory. I actually got a dialog to select a file, though all files it shows are greyed out and unselectable, but maybe you are supposed to pick a directory, as in a git repo. I tried that, but it just said "repo contains multiple branches" which yes, it does.

No idea what you're supposed to do about that so I just tried going the other way, I loaded a drawing first, and then tried to execute "saveandcommit", but it just said "variable branch used before assignment".

Ok so I guess I have to somehow tell the script what git branch to use, by setting a variable named "branch". I guess with a config file or some other way to set that variable?
microartisan
Posts: 12
Joined: Fri Mar 23, 2018 11:52 am
Location: beijing
Contact:

Re: Storing FreeCAD files in a git repo

Post by microartisan »

https://bitbucket.org/sippey/zippey

I try this python tool, it work well for me to use git.

Zippey: A Git filter for friendly handling of ZIP-based files


Intro
There are many types of ZIP-based files, such as Microsoft Office .docx, .xlsx, .pptx files, OpenOffice .odt files and jar files, that contains plain text content but that can't really be tracked by git since the compression smears what parts have been modified and what parts remain the same across commits. This prevent Git from versioning these files and it saves them as a new binary blob every time the file is modified.

Method
Zippey is a Git filter that unzips zip-based files into a simple text format during git add/commit ("clean" process) and recover the original zip-based file after git checkout ("smudge" process). Since diff is taken on the "clean" file, it is likely that the real changes to file can be reflected by the built-in git diff command. This solves the problem of diffs for these files normally being useless and unreadable for humans.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Storing FreeCAD files in a git repo

Post by yorik »

microartisan wrote: Fri Mar 23, 2018 11:56 am https://bitbucket.org/sippey/zippey
I try this python tool, it work well for me to use git.
Hmm very interesting find... Will test
microartisan
Posts: 12
Joined: Fri Mar 23, 2018 11:52 am
Location: beijing
Contact:

Re: Storing FreeCAD files in a git repo

Post by microartisan »

the principle of this tool is :
1. unzip freecad file to files and write to one utf-8 cache.
2. use git to deal with this cache.

So it works very well if the freecad file is small.
If the feecad file is big, it means the cache also very big, maybe will catch some problem.
So far I have not try big freecad file.

yorik wrote: Fri Mar 23, 2018 2:26 pm
microartisan wrote: Fri Mar 23, 2018 11:56 am https://bitbucket.org/sippey/zippey
I try this python tool, it work well for me to use git.
Hmm very interesting find... Will test
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Storing FreeCAD files in a git repo

Post by yorik »

microartisan wrote: Tue Apr 24, 2018 4:28 am If the feecad file is big, it means the cache also very big, maybe will catch some problem.
Yes but 99% of what is inside a freecad file is text (the xml files, and the brep files). So if you have a large freecad file, but most of the shapes inside don't change, most of the brep files will stay the same, and even if your cache is large at start, it shouldn't grow much over time.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Storing FreeCAD files in a git repo

Post by Kunda1 »

Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
microartisan
Posts: 12
Joined: Fri Mar 23, 2018 11:52 am
Location: beijing
Contact:

Re: Storing FreeCAD files in a git repo

Post by microartisan »

checked you code in github.
It looks you don't unzip the freecad file?
right?
Kunda1 wrote: Wed Apr 25, 2018 3:55 pm WIP https://github.com/reox/FreeCAD_gitproject
reox wrote:poke
microartisan
Posts: 12
Joined: Fri Mar 23, 2018 11:52 am
Location: beijing
Contact:

Re: Storing FreeCAD files in a git repo

Post by microartisan »

Yeah, you are right, the whole size shouldn't grow much over time.
yorik wrote: Wed Apr 25, 2018 3:26 pm
Yes but 99% of what is inside a freecad file is text (the xml files, and the brep files). So if you have a large freecad file, but most of the shapes inside don't change, most of the brep files will stay the same, and even if your cache is large at start, it shouldn't grow much over time.
Post Reply