Here is a post describing a process I used to "change history" in a repo.
Perhaps it might be useful to someone at some point.

Two years ago I started using fossil to track my personal website / blog.
My plan at the time was to use a static site generator and to keep the
generated content under version control as well, to simplify the process of
pushing to my actual website after editing and building the blog.

As it turns out, this wasn't a great plan. As a result, I had a 200 MB
repository holding tons of build artifacts that I really didn't need to
keep around. So I decided to rebuild my repository, removing the cruft that
can be rebuilt on demand, and just keeping the other pieces.

In git this would be "no problem" of course (other than the problem that I
was using git). I could throw away stuff willy nilly.

Since I'm using Windows, I was inclined to just use a batch file to migrate
individual commits from the old repo to a new repo, excluding the pieces I
no longer wanted to keep track of. Before I could do that, I needed to
"clean up" the existing repo a little bit. I had used some special
characters in comments that would trip up batch processing (parentheses,
quotation marks, ampersands, percent signs, vertical bars and less than /
greater than symbols; anything else that would cause cmd.exe to choke), so
I edited the offending commit comments in the old repository. Maybe a dozen
or so in my case.

Next I opened a copy of old repository at the initial empty commit.

Then I created a new empty repository using the --date-override, --template
and --admin-user options to initialize the desired state.

I wrote the following batch file named donext.bat that would do the
annoying repetitive work:

**********

@echo off

pushd D:\path\to\old\checkout
fossil update next
fossil status > D:\path\to\temp.txt
popd

rem modify the /xf and /xd parameters as needed to exclude the parts you
don't want in the new repository
robocopy D:\path\to\old\checkout D:\path\to\new\checkout *.* /mir /xf
_FOSSIL_ /xf *.pyc /xd public

for /f "delims=" %%L in (D:\path\to\temp.txt) do call :getvar "%%L"

pushd D:\path\to\new\checkout
fossil addremove
fossil commit --date-override %dndatetime: =T% -m "%dncomment%"
rem the following isn't strictly necessary, but it gave me some idea where
I was in the process
fossil timeline
popd

goto :EOF

:getvar
set dnline=%~1
if "%dnline:~0,9%"=="checkout:" set dndatetime=%dnline:~55,-4%
if "%dnline:~0,8%"=="comment:" set dncomment=%dnline:~14,-14%
goto :EOF

**********

My old repository had 107 commits after the initial empty commit. So I ran
one final command line:

for /L %L in (1,1,107) do donext.bat

Which ran my donext.bat file 107 times, migrating all the commits to the
new repository without the generated artifacts.

I don't see this being something I'm likely to need again, but I wanted to
document it in case it was useful for someone else as an example of how it
might be done on a Windows platform (where "someone" might be me when I
find out I have another use for it but long since deleted the "trivial"
batch file). Certainly a lot easier than trying to do all those steps
manually 107 times.

In the end it "failed to commit" about 10 or so because there were no
differences (all the differences were in no omitted artifacts). And my
useful repository is about half the size it was before.

Note that this script is not a generic tool that will Just Work(TM) on your
repository setup. It makes assumptions likely unique to my configuration
(hard coded paths, a single user name being used for all commits, no
branches, maybe more). Still, it might be a useful reference.

-- 
Scott Robison
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to