all repos — aaoth.xyz @ c52fa1d2c7ab61a3ef1e1c55341bb59433fac875

aaoth.xyz website

_posts/2020-12-06-fossil-to-git.md (view raw)

 1---
 2title: fossil export to git
 3author: la-ninpre
 4tags: fossil git tutorial
 5---
 6
 7i was trying to export my website repo to fossil using suggested method from
 8[fossil website][1]:
 9
10```
11git fast-export --all | fossil import --git repo.fossil
12```
13
14[1]:https://www.fossil-scm.org/home/doc/trunk/www/inout.wiki
15
16but i didn't like that fossil recognizes my email as username and so commit
17messages user was `user@example.com` instead of `user`.
18
19<!--more-->
20
21i then read a bit about options of `git fast-export` and found `--anonymize`
22flag. but it's results weren't satisfying either.
23
24when i looked on a raw output of `git fast-export`, i noticed that commit author
25is specified there as 
26
27```
28author user <user@example.com>
29```
30
31and then it's flashed in my head: why not pipe git export through sed and just 
32replace the contents of `<>` with username instead of email.
33
34so the final command looks like this:
35
36```
37git fast-export --all | \
38    sed -E 's/^((author)|(committer))[[:blank:]]+([[:graph:]]+)[[:blank:]]+(<[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+>)/\1 \4 <\4>/' | \
39    fossil import --git repo.fossil
40```
41
42and it converts
43
44```
45author user <user@example.com>
46```
47
48to 
49
50```
51author user <user>
52```
53
54which is odd, but fine for fossil import.
55
56---
57
58update: i tested this on a bigger repo with older history and found that this
59regexp was not perfect, i updated it to handle situations like
60`user@example.co.uk` and also names that consist of more than one word.
61
62```
63git fast-export --all | \
64    sed -E 's/^((author)|(committer))[[:blank:]]+([[:graph:]]+([[:blank:]]+[[:graph:]]+)*)[[:blank:]]+(<[[:graph:]]+@[[:graph:]]+(\.[[:graph:]]+)+>)/\1 \4<\4>/' | \
65    fossil import --git repo.fossil
66```
67
68it's veery evil looking horrible thing, but it works.