Difference between revisions of "User:Joelholdsworth/split-sigrok-repo.sh"
(Created page with "== Overview == <code>split-sigrok-repo.sh</code> is a simple bash script to do the upcoming repository splitting task. I'm very keen that we filter the project history, so tha...") |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
<code>split-sigrok-repo.sh</code> is a simple bash script to do the upcoming repository splitting task. I'm very keen that we filter the project history, so that we can retain the history of each subproject, but only show the work that was done on that submodule. | <code>split-sigrok-repo.sh</code> is a simple bash script to do the upcoming repository splitting task. I'm very keen that we filter the project history, so that we can retain the history of each subproject, but only show the work that was done on that submodule. | ||
This is an alternative to cloning sigrok.git N times, then making a commit in each clone that deletes all but one subproject. | |||
The benefits are... | |||
* It allows us to clearly show the history of each subproject, rather than having an earthquake in the history. | |||
* It reduces the amount of duplication for people taking git clones. | |||
* It means the ohloh lines-of-code history won't be messed up. I don't know if you care about it, but I'm keen to preserve it. | |||
== <code>split-sigrok-repo.sh</code> == | == <code>split-sigrok-repo.sh</code> == | ||
#!/bin/bash | #!/bin/bash | ||
set -e | |||
SRCDIR=sigrok | SRCDIR=sigrok | ||
Line 20: | Line 28: | ||
git remote rm origin | git remote rm origin | ||
# | # Move the full history of the HACKING file into the subproject | ||
git filter-branch --tag-name-filter cat \ | git filter-branch --tag-name-filter cat --index-filter " | ||
git ls-files -sz | | |||
perl -0pe \"s{\tHACKING}{\t${SUBDIR}/HACKING}\" | | |||
git update-index -z --clear --index-info | |||
" -- --all | |||
# Filter the subdirectory | |||
git filter-branch -f --tag-name-filter cat \ | |||
--prune-empty --subdirectory-filter $SUBDIR -- --all | --prune-empty --subdirectory-filter $SUBDIR -- --all | ||
Line 36: | Line 51: | ||
echo --------------- DONE --------------- | echo --------------- DONE --------------- | ||
du -sh $DSTDIR/* | du -sh $DSTDIR/* | ||
You might want to add some git push commands in the loop if you feel brave and want to automate uploading. | |||
== Usage == | |||
* '''Start with a clean git repository''' | |||
<code>git clone git://sigrok.git.sourceforge.net/gitroot/sigrok/sigrok</code> | |||
* Adjust <code>SRCDIR</code> and <code>DSTDIR</code> as necessary. | |||
* Then <code>bash split-sigrok-repo.sh</code> | |||
== Porting Work in Progress to Split Repositories == | == Porting Work in Progress to Split Repositories == | ||
For those working on branches from the currently combined repository, the procedure for rebasing over the split repository is fairly straightforward. This is my (untested) procedure: | For those working on branches from the currently combined repository, the procedure for rebasing over the split repository is fairly straightforward. This is my (untested) procedure: | ||
#Look at your repo - which subprojects have you been working on in your branches | #Look at your repo - which subprojects have you been working on in your branches? libsigrok, libsigrokdecode etc. ? | ||
#Make a copy of your local sigrok repo for each subproject e.g. repo-libsigrok, repo-libsigrokdecode etc. | #Make a copy of your local sigrok repo for each subproject e.g. repo-libsigrok, repo-libsigrokdecode etc. | ||
#For each repository do the following: | #For each repository do the following: | ||
## | ##Inside the subproject directory, filter the ''all'' commits to the subproject: <code>git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter $SUBDIR -- --all</code>. Where SUBDIR= the subproject: libsigrok, libsigrokdecode etc. | ||
##Add the new origin for the new subrepo remote <code>git remote add -mf git://sigrok.git.sourceforge.net/gitroot/sigrok/sigrok</code>. | ##Add the new origin for the new subrepo remote list: <code>git remote add -mf git://sigrok.git.sourceforge.net/gitroot/sigrok/sigrok</code>. | ||
##You can now rebase your branches on origin head. | ##You can now rebase your branches on origin head. | ||
##If you want to for garbage collection to clear space, you can follow the garbage collection instructions from <code>split-sigrok-repo.sh</code>. | ##If you want to for garbage collection to clear space, you can follow the garbage collection instructions from <code>split-sigrok-repo.sh</code>. | ||
Note that in filtering origin/master for the subproject, the commits you generate should exactly match those | Note that in filtering origin/master for the subproject, the local commits you generate should exactly match those from the split master repos. Therefore, the IDs of you master commits will exactly match the IDs of the origin repository's commits. Therefore, I don't believe that rebasing will actually be necessary, because your branches will already be based on origin. |
Latest revision as of 10:08, 6 October 2012
Overview
split-sigrok-repo.sh
is a simple bash script to do the upcoming repository splitting task. I'm very keen that we filter the project history, so that we can retain the history of each subproject, but only show the work that was done on that submodule.
This is an alternative to cloning sigrok.git N times, then making a commit in each clone that deletes all but one subproject.
The benefits are...
- It allows us to clearly show the history of each subproject, rather than having an earthquake in the history.
- It reduces the amount of duplication for people taking git clones.
- It means the ohloh lines-of-code history won't be messed up. I don't know if you care about it, but I'm keen to preserve it.
split-sigrok-repo.sh
#!/bin/bash set -e SRCDIR=sigrok DSTDIR=split mkdir -p $DSTDIR for i in $SRCDIR/*/; do SUBDIR=$(basename $i) DSTREPO=$DSTDIR/$SUBDIR git clone $SRCDIR $DSTREPO ( cd $DSTREPO # Remove the origin to prohibit pushing back there git remote rm origin # Move the full history of the HACKING file into the subproject git filter-branch --tag-name-filter cat --index-filter " git ls-files -sz | perl -0pe \"s{\tHACKING}{\t${SUBDIR}/HACKING}\" | git update-index -z --clear --index-info " -- --all # Filter the subdirectory git filter-branch -f --tag-name-filter cat \ --prune-empty --subdirectory-filter $SUBDIR -- --all # Do aggressive garbage collection git reset --hard git for-each-ref --format="%(refname)" refs/original/ | \ xargs -n 1 git update-ref -d git reflog expire --expire=now --all git gc --aggressive --prune=now ) done echo echo --------------- DONE --------------- du -sh $DSTDIR/*
You might want to add some git push commands in the loop if you feel brave and want to automate uploading.
Usage
- Start with a clean git repository
git clone git://sigrok.git.sourceforge.net/gitroot/sigrok/sigrok
- Adjust
SRCDIR
andDSTDIR
as necessary. - Then
bash split-sigrok-repo.sh
Porting Work in Progress to Split Repositories
For those working on branches from the currently combined repository, the procedure for rebasing over the split repository is fairly straightforward. This is my (untested) procedure:
- Look at your repo - which subprojects have you been working on in your branches? libsigrok, libsigrokdecode etc. ?
- Make a copy of your local sigrok repo for each subproject e.g. repo-libsigrok, repo-libsigrokdecode etc.
- For each repository do the following:
- Inside the subproject directory, filter the all commits to the subproject:
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter $SUBDIR -- --all
. Where SUBDIR= the subproject: libsigrok, libsigrokdecode etc. - Add the new origin for the new subrepo remote list:
git remote add -mf git://sigrok.git.sourceforge.net/gitroot/sigrok/sigrok
. - You can now rebase your branches on origin head.
- If you want to for garbage collection to clear space, you can follow the garbage collection instructions from
split-sigrok-repo.sh
.
- Inside the subproject directory, filter the all commits to the subproject:
Note that in filtering origin/master for the subproject, the local commits you generate should exactly match those from the split master repos. Therefore, the IDs of you master commits will exactly match the IDs of the origin repository's commits. Therefore, I don't believe that rebasing will actually be necessary, because your branches will already be based on origin.