my failed projects

How to Serve ~user UserDirs for Git With Apache

By default, gitweb only supports serving repos from one project root. For DragonFly we wanted not only to serve the main project repo in gitweb, but also serve the personal repos of developers. These repos are located in the users’ home directory in ~user/git. Turns out I could make this work without having to modify the gitweb source. By adding the following fragment to gitweb’s config file /etc/gitweb.conf, we can now serve the users’ personal repos:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Support for ~user git repo serving

# Does the url path start with /~user ?
if ($ENV{"PATH_INFO"} =~ m#^/~([^/]+)#) {
  my $username = $1;

  # check whether the user really exists
  my @pwent = getpwnam($username);
  if (@pwent) {
      # we only serve $HOME/git/
      $projectroot = $pwent[7] . "/git";

      # Fix up git's idea of the urls :/
      $my_url .= "/~$username";
      $my_uri .= "/~$username";
      $home_link .= "~$username";
      $home_link_str = $username."'s projects";
      $path_info =~ s#^/~[^/]+##;
  }
}