GIT Filter
Using git filters to extract or separate FreeBSD components into their own git repos.
This is still a work in progress. Two examples will be provided.
git-filter-repo
git-filter-repo is a handy port that will rewrite git history, including separating FreeBSD components from the tree. Following is how I separated telnet (telnetd, libtelnet, and telnet) into its own repo.
- git clone a fresh copy of src.
- git tag -l | xargs git tag -d
- git filter-repo --path contrib/telnet --path lib/libtelnet --path libexec/telnetd --path usr.bin/telnet
- git reflog expire --all --expire-unreachable=0
- git repack -A -d
- git prune
This resulted in a 1 MB git repo containing only telnet.
Another example is the extraction of sbin/routed and usr.sbin/route6d.
- git clone a fresh copy of src.
- git tag -l | xargs git tag -d
- git filter-repo --path sbin/routed --path usr.sbin/route6d --path usr.sbin/rip6query --path libexec/rc/rc.d/routed --path libexec/rc/rc.d/route6d
- git reflog expire --all --expire-unreachable=0
- git repack -A -d
- git prune
- git gc --aggressive
This resulted in a 1.3 MB git repo containing only routed and route6d.
git-filter-repo is recommended by the authors of git. git-filter-branch displays a message suggesting that git-filter-repo be used.
git-filter-branch
As efficient as git-filter-repo is, I discovered it deleted files that should not have been deleted when extracting ftpd into its own repo.
It has turned out that isolating ftpd exposed a bug in git-filter-repo. I discovered it deleted files that should not have been deleted when extracting ftpd into its own repo. I had filed a bug at https://github.com/newren/git-filter-repo/issues/261. It was fixed today.
Prior to the git-filter-repo bug being fixed I used the other tool at our disposal, git-filter-branch. It is already packaged with git. Though git warns about git-filter-branch caveats and the possibility of repo corruption, it was the only solution to separate ftpd into its own repo at the time. The steps I used are:
- git clone a fresh copy of src.
- git filter-branch --subdirectory-filter libexec/ftpd
- git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch filename' --prune-empty -f -- --all
- rm -r .git/refs/original
- git reflog expire --expire=now --all
- git gc --prune=now
- git gc --aggressive
This resulted in a 448KB git repo only containing ftpd.
Hopefully this will be of use to someone.