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.

  1. git clone a fresh copy of src.
  2. git tag -l | xargs git tag -d
  3. git filter-repo --path contrib/telnet --path lib/libtelnet --path libexec/telnetd --path usr.bin/telnet
  4. git reflog expire --all --expire-unreachable=0
  5. git repack -A -d
  6. 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.

  1. git clone a fresh copy of src.
  2. git tag -l | xargs git tag -d
  3. 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
  4. git reflog expire --all --expire-unreachable=0
  5. git repack -A -d
  6. git prune
  7. 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. The other tool at our disposal is git-filter-branch, which 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. The steps I used are:

  1. git clone a fresh copy of src.
  2. git filter-branch --subdirectory-filter libexec/ftpd
  3. git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch filename' --prune-empty -f -- --all
  4. rm -r .git/refs/original
  5. git reflog expire --expire=now --all
  6. git gc --prune=now
  7. git gc --aggressive

This resulted in a 448KB git repo only containing ftpd.

Hopefully this will be of use to someone. I will expound on the above at a later date as time permits.

git-filter (last edited 2024-04-16T17:31:27+0000 by CySchubert)