Skip to content

Instantly share code, notes, and snippets.

@oxan
Last active December 17, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxan/5564835 to your computer and use it in GitHub Desktop.
Save oxan/5564835 to your computer and use it in GitHub Desktop.
DirectShowFilters extraction code
#!/bin/bash
cd MediaPortal-1
test -d .git || exit 1
# get a unique list of all files in the root and in the mediaportal/ and TvEngine3/ directory
tmp=$(mktemp)
git rev-list HEAD | xargs -n1 -I%rev -- git ls-tree --name-only --full-name %rev ./ mediaportal/ TvEngine3/ > $tmp
# remove everything but the (TvEngine3|mediaportal)/Filters and DirectShowFilters directory
# TODO: check whether there really isn't anything from another directory moved to DirectShowFilters
remove=$(cat $tmp | sort -u | egrep -v "^((TvEngine3|mediaportal)/Filters|DirectShowFilters|$)" | sed "s%^\(.*\)$%'\1'%" | tr '\n' ' ')
git filter-branch --index-filter "git rm -q -r --cached --ignore-unmatch $remove" --prune-empty -- HEAD
# clone the repo, so we don't mess up the result of the awfully-long taking previous step
cd ..
git clone --no-hardlinks MediaPortal-1 dsfrepo
cd dsfrepo
git remote rm origin
# remove all tags, as those still reference the old objects
# TODO: do we want to keep tags?
git tag -l | xargs -r -n1 -- git tag -d
# remove binaries
git filter-branch -f --index-filter 'git rm -q -r --cached --ignore-unmatch dummy $(git ls-files | egrep "\.(ax|dll|pdb)$")' --prune-empty -- HEAD
# remove empty merge commits
git filter-branch -f --parent-filter "sed 's/-p //g' | xargs -r -- git show-branch --independent | sed 's/^\(.*\)$/-p \1/' | tr '\n' ' '" --prune-empty -- HEAD
# remove the backups made by git filter-branch
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# remove old revisions from the repo and recompress everything
git reflog expire --expire=now --all
git repack -ad
git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment