Skip to content

Commit

Permalink
git/fs: move mount point to $repo/.git/fs
Browse files Browse the repository at this point in the history
Moving the mount point to within the repo
directory means that we can have multiple
git repos mounted at once with no conflict.
  • Loading branch information
oridb committed May 25, 2021
1 parent ca837be commit d84d6af
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 67 deletions.
48 changes: 24 additions & 24 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ And start committing!
Structure
---------

The git/fs program provides a file system mounted on /mnt/git. It
provides a read-only view into the repository contents to allow
The git/fs program provides a file system mounted on $repo/.git/fs.
It provides a read-only view into the repository contents to allow
scripts to inspect the data. Surrounding scripts and binaries will
manipulate the repository contents directly. These changes will be
immediately mirrored in the file system.

Scripts will generally mount git/fs as needed to do
their work, but if you want to browse the repository
manually, run it yourself. You'll get `/mnt/git` mounted,
manually, run it yourself. You'll get `$repo/.git/fs` mounted,
with the following contents:

/mnt/git/object: The objects in the repo.
/mnt/git/branch: The branches in the repo.
/mnt/git/ctl: A file showing the status of the repo.
$repo/.git/fs/object: The objects in the repo.
$repo/.git/fs/branch: The branches in the repo.
$repo/.git/fs/ctl: A file showing the status of the repo.
Currently, it only shows the current branch.
/mnt/git/HEAD An alias for the currently checked out
$repo/.git/fs/HEAD An alias for the currently checked out
commit directory.

Visible Differences
Expand Down Expand Up @@ -104,7 +104,7 @@ Some usage examples:
git/log
cd subdir/name
git/add foo.c
diff bar.c /mnt/git/HEAD/
diff bar.c $repo/.git/fs/HEAD/
git/commit foo.c
git/push

Expand All @@ -119,30 +119,30 @@ contents:

So, for example:

% ls /mnt/git/branch/heads/master
/mnt/git/branch/heads/master/author
/mnt/git/branch/heads/master/hash
/mnt/git/branch/heads/master/msg
/mnt/git/branch/heads/master/parent
/mnt/git/branch/heads/master/tree
% cat /mnt/git/branch/heads/master/hash
% ls $repo/.git/fs/branch/heads/master
$repo/.git/fs/branch/heads/master/author
$repo/.git/fs/branch/heads/master/hash
$repo/.git/fs/branch/heads/master/msg
$repo/.git/fs/branch/heads/master/parent
$repo/.git/fs/branch/heads/master/tree
% cat $repo/.git/fs/branch/heads/master/hash
7d539a7c08aba3f31b3913e0efef11c43ea9

# This is the same commit, with the same contents.
% ls /mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef
/mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/author
/mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/hash
/mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/msg
/mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/parent
/mnt/git/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/tree
% ls $repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef
$repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/author
$repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/hash
$repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/msg
$repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/parent
$repo/.git/fs/object/7d539a7c08aba3f31b3913e0efef11c43ea9f9ef/tree

# what git/diff will hopefully do more concisely soon, filtering
# out the non-git files.
ape/diff -ur /mnt/git/branch/heads/master/tree .
ape/diff -ur $repo/.git/fs/branch/heads/master/tree .
Only in .: .git
Only in .: debug
diff -ur /mnt/git/branch/heads/master/tree/fold.myr ./fold.myr
--- /mnt/git/branch/heads/master/tree/fold.myr Wed Dec 31 16:00:00 1969
diff -ur $repo/.git/fs/branch/heads/master/tree/fold.myr ./fold.myr
--- $repo/.git/fs/branch/heads/master/tree/fold.myr Wed Dec 31 16:00:00 1969
+++ ./fold.myr Mon Apr 1 21:39:06 2019
@@ -6,6 +6,8 @@
const foldexpr : (e : expr# -> std.option(constval))
Expand Down
2 changes: 1 addition & 1 deletion add
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for(f in $files){
# git/walk doesn't think this came from
# a checkout.
if(! test -e $addpath)
if(~ $add 'tracked' || test -e /mnt/git/HEAD/tree/$f)
if(~ $add 'tracked' || test -e $gitfs/HEAD/tree/$f)
touch $addpath
rm -f $delpath
}
Expand Down
6 changes: 3 additions & 3 deletions branch
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ deleted=()
if(~ $#* 0){
if(~ $#listall 0)
awk '$1=="branch"{print $2}' < /mnt/git/ctl
awk '$1=="branch"{print $2}' < $gitfs/ctl
if not
cd .git/refs/ && walk -f heads remotes
exit
Expand Down Expand Up @@ -95,8 +95,8 @@ for(m in $cleanpaths){
}
for(ours in $dirtypaths){
common=/mnt/git/object/$orig/tree/$ours
theirs=/mnt/git/object/$base/tree/$ours
common=$gitfs/object/$orig/tree/$ours
theirs=$gitfs/object/$base/tree/$ours
merge1 $ours $ours $common $theirs
}
Expand Down
3 changes: 2 additions & 1 deletion clone
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if(test -e $local)
fn clone{
flag +e
mkdir -p $local/.git
mkdir -p $local/.git/fs
mkdir -p $local/.git/objects/pack/
mkdir -p $local/.git/refs/heads/
Expand Down Expand Up @@ -76,7 +77,7 @@ fn clone{
}
'} |[3] tr '\x0d' '\x0a' || die 'could not clone repository'
tree=/mnt/git/HEAD/tree
tree=.git/fs/HEAD/tree
lbranch=`{git/branch}
rbranch=`{echo $lbranch | subst '^heads' 'remotes/origin'}
echo checking out repository...
Expand Down
12 changes: 6 additions & 6 deletions commit
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ fn whoami{

fn findbranch{
branch=`{git/branch}
if(test -e /mnt/git/branch/$branch/tree){
if(test -e $gitfs/branch/$branch/tree){
refpath=.git/refs/$branch
initial=false
}
if not if(test -e /mnt/git/object/$branch/tree){
if not if(test -e $gitfs/object/$branch/tree){
refpath=.git/HEAD
initial=false
}
if not if(! test -e /mnt/git/HEAD/tree){
if not if(! test -e $gitfs/HEAD/tree){
refpath=.git/refs/$branch
initial=true
}
Expand Down Expand Up @@ -79,7 +79,7 @@ fn editmsg{
fn parents{
if(! ~ $#revise 0)
parents=`{cat /mnt/git/HEAD/parent}
parents=`{cat $gitfs/HEAD/parent}
if not if(test -f .git/index9/merge-parents)
parents=`{cat .git/index9/merge-parents | sort | uniq}
if not if(~ $initial true)
Expand Down Expand Up @@ -129,8 +129,8 @@ if(~ $#msg 1)
echo $msg >$msgfile.tmp
if not if(~ $#revise 1){
msg=1
echo revising commit `{cat /mnt/git/HEAD/hash}
cat /mnt/git/HEAD/msg >$msgfile.tmp
echo revising commit `{cat $gitfs/HEAD/hash}
cat $gitfs/HEAD/msg >$msgfile.tmp
}
files=()
Expand Down
7 changes: 5 additions & 2 deletions common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@ fn gitup{
gitroot=`{git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitfs=$gitroot/.git/fs
gitrel=`{pwd | subst '^'$"gitroot'/?'}
if(~ $#gitrel 0)
gitrel='.'
cd $gitroot
startfs=()
if(! test -e /mnt/git/ctl)
if(! test -d $gitfs)
mkdir -p $gitfs
if(! test -e $gitfs/ctl)
startfs=true
if(! grep -s '^repo '$gitroot'$' /mnt/git/ctl >[2]/dev/null)
if(! grep -s '^repo '$gitroot'$' $gitfs/ctl >[2]/dev/null)
startfs=true
if(~ $#startfs 1)
git/fs
Expand Down
16 changes: 8 additions & 8 deletions extra/gitls
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn htcat {
fn resolveref {
if(~ $refname HEAD)
echo $refname
if not if(test -d /mnt/git/branch/$refname/tree)
if not if(test -d $gitfs/branch/$refname/tree)
echo branch/$refname
if not if(test -d /mnt/git/object/$refname/tree)
if not if(test -d $gitfs/object/$refname/tree)
echo object/$refname
if not
status='bad ref'
Expand Down Expand Up @@ -87,7 +87,7 @@ case 'tar'
echo '<b>invalid ref '$refname'</b>'
exit
}
bind /mnt/git/$ref/tree /mnt/$repo
bind $gitfs/$ref/tree /mnt/$repo
cd /mnt
tar cz $repo
}
Expand Down Expand Up @@ -120,15 +120,15 @@ case 'info'
echo '<b>invalid ref '$refname'</b>'
exit
}
cd /mnt/git/$ref/tree
hash=`{cat /mnt/git/$ref/hash}
cd $gitfs/$ref/tree
hash=`{cat $gitfs/$ref/hash}
prelude $repo $ref $repo
echo ' <h1><a href="/git/repos.html">Git</a>: <a
href=/git/'$repo'/'$ref'/info.html>'$repo'</a></h1>
<p>'$repo' @ <a href='/git/$repo/$hash/f.html'>'$hash'</a>
<pre id="desc">'
htcat /mnt/git/object/$hash/msg
htcat $gitfs/object/$hash/msg
echo ' </pre>
<h2>Code</h2>
<p>
Expand Down Expand Up @@ -175,10 +175,10 @@ case 'view'
echo '<b>invalid ref '$refname'</b>'
exit
}
cd /mnt/git/$ref/tree
cd $gitfs/$ref/tree
if(~ $file '')
file='.'
hash=`{cat /mnt/git/$ref/hash}
hash=`{cat $gitfs/$ref/hash}
prelude
echo ' <h1><a href="/git/repos.html">Git</a>: <a
Expand Down
15 changes: 11 additions & 4 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ char *qroot[] = {

char gitdir[512];
char *username;
char *mtpt = "/mnt/git";
char *mntpt = ".git/fs";
char **branches = nil;
Cache uqidcache[512];
vlong nextqid = Qmax;
Expand Down Expand Up @@ -839,15 +839,22 @@ main(int argc, char **argv)
{
gitinit();
ARGBEGIN{
case 'd': chatty9p++; break;
default: usage(); break;
case 'd':
chatty9p++;
break;
case 'm':
mntpt = EARGF(usage());
break;
default:
usage();
break;
}ARGEND;
if(argc != 0)
usage();

username = getuser();
branches = emalloc(sizeof(char*));
branches[0] = nil;
postmountsrv(&gitsrv, nil, "/mnt/git", MCREATE);
postmountsrv(&gitsrv, nil, mntpt, MCREATE);
exits(nil);
}
4 changes: 2 additions & 2 deletions git.1.man
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ This suite of
tools provides a file interface to the
.I .git
directory mounted on
.I /mnt/git.
.I $repo/.git/fs.
Modifications to the repository are done directly to the
.I .git
directory, and are reflected in the file system interface.
Expand Down Expand Up @@ -304,7 +304,7 @@ flag serves repositories relative to

.PP
.B Git/fs
serves a file system on /mnt/git.
serves a file system on $repo/.git/fs.
For full documentation, see
.IR gitfs (4)

Expand Down
4 changes: 2 additions & 2 deletions gitfs.4.man
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Git/fs serves a file system interface to a git repository in the
current directory.
This file system provides a read-only view into the repository contents.
By default, it is mounted on
.B /mnt/git.
.B $repo/.git/fs.
It does not cache mutable data, so any changes to the git repository will immediately be reflected in git/fs.

.PP
Expand Down Expand Up @@ -83,7 +83,7 @@ The git repository being expected.
.B .git/HEAD
A reference to the current HEAD.
Used to populate
.B /mnt/git/HEAD
.B $repo/.git/fs/HEAD
.TP
.git/config
The per-repository configuation for git tools.
Expand Down
4 changes: 2 additions & 2 deletions import
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ fn apply @{
msg=''
parents='-p'^`{git/query HEAD}
branch=`{git/branch}
if(test -e /mnt/git/branch/$branch/tree)
if(test -e $gitfs/branch/$branch/tree)
refpath=.git/refs/$branch
if not if(test -e /mnt/git/object/$branch/tree)
if not if(test -e $gitfs/object/$branch/tree)
refpath=.git/HEAD
if not
die 'invalid branch:' $branch
Expand Down
6 changes: 3 additions & 3 deletions merge
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ rfork ne
. /sys/lib/git/common.rc

fn merge{
ourbr=/mnt/git/object/$1/tree
basebr=/mnt/git/object/$2/tree
theirbr=/mnt/git/object/$3/tree
ourbr=$gitfs/object/$1/tree
basebr=$gitfs/object/$2/tree
theirbr=$gitfs/object/$3/tree

all=`$nl{{git/query -c $1 $2; git/query -c $2 $3} | sed 's/^..//' | \
subst -g '^('$ourbr'|'$basebr'|'$theirbr')/*' | sort | uniq}
Expand Down
6 changes: 4 additions & 2 deletions query.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ main(int argc, char **argv)
{
int i, j, n;
Hash *h;
char *p, *e, *s;
char *p, *e, *s, *objpfx;
char query[2048], repo[512];

ARGBEGIN{
Expand All @@ -173,6 +173,8 @@ main(int argc, char **argv)
sysfatal("find root: %r");
if(chdir(repo) == -1)
sysfatal("chdir: %r");
if((objpfx = smprint("%s/.git/fs/object/", repo)) == nil)
sysfatal("smprint: %r");
s = "";
p = query;
e = query + nelem(query);
Expand All @@ -187,7 +189,7 @@ main(int argc, char **argv)
sysfatal("diff: need 2 commits, got %d", n);
diffcommits(h[0], h[1]);
}else{
p = (fullpath ? "/mnt/git/object/" : "");
p = (fullpath ? objpfx : "");
for(j = 0; j < n; j++)
print("%s%H\n", p, h[reverse ? n - 1 - j : j]);
}
Expand Down
2 changes: 1 addition & 1 deletion rebase
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ while(! ~ $#todo 0){
exit
case s squash
git/export $c | git/import -n
msg=`''{cat /mnt/git/HEAD/msg; echo; cat /mnt/git/object/$c/msg}
msg=`''{cat $gitfs/HEAD/msg; echo; cat $gitfs/object/$c/msg}
git/commit -rem $msg .
case f fixup
git/export $c | git/import -n
Expand Down
2 changes: 1 addition & 1 deletion revert
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gitup
flagfmt='c:query query' args='file ...'
eval `''{aux/getflags $*} || exec aux/usage
commit=/mnt/git/HEAD
commit=$gitfs/HEAD
if(~ $#query 1)
commit=`{git/query -p $query}

Expand Down
Loading

0 comments on commit d84d6af

Please sign in to comment.