gitweb / READMEon commit gitweb.js: fix padLeftStr() and its usage (6821dee)
   1GIT web Interface
   2=================
   3
   4The one working on:
   5  http://git.kernel.org/
   6
   7From the git version 1.4.0 gitweb is bundled with git.
   8
   9
  10How to configure gitweb for your local system
  11---------------------------------------------
  12
  13See also the "Build time configuration" section in the INSTALL
  14file for gitweb (in gitweb/INSTALL).
  15
  16You can specify the following configuration variables when building GIT:
  17 * GIT_BINDIR
  18   Points where to find the git executable.  You should set it up to
  19   the place where the git binary was installed (usually /usr/bin) if you
  20   don't install git from sources together with gitweb.  [Default: $(bindir)]
  21 * GITWEB_SITENAME
  22   Shown in the title of all generated pages, defaults to the server name
  23   (SERVER_NAME CGI environment variable) if not set. [No default]
  24 * GITWEB_PROJECTROOT
  25   The root directory for all projects shown by gitweb. Must be set
  26   correctly for gitweb to find repositories to display.  See also
  27   "Gitweb repositories" in the INSTALL file for gitweb.  [Default: /pub/git]
  28 * GITWEB_PROJECT_MAXDEPTH
  29   The filesystem traversing limit for getting the project list; the number
  30   is taken as depth relative to the projectroot.  It is used when
  31   GITWEB_LIST is a directory (or is not set; then project root is used).
  32   Is is meant to speed up project listing on large work trees by limiting
  33   search depth.  [Default: 2007]
  34 * GITWEB_LIST
  35   Points to a directory to scan for projects (defaults to project root
  36   if not set / if empty) or to a file with explicit listing of projects
  37   (together with projects' ownership). See "Generating projects list
  38   using gitweb" in INSTALL file for gitweb to find out how to generate
  39   such file from scan of a directory. [No default, which means use root
  40   directory for projects]
  41 * GITWEB_EXPORT_OK
  42   Show repository only if this file exists (in repository).  Only
  43   effective if this variable evaluates to true.  [No default / Not set]
  44 * GITWEB_STRICT_EXPORT
  45   Only allow viewing of repositories also shown on the overview page.
  46   This for example makes GITWEB_EXPORT_OK to decide if repository is
  47   available and not only if it is shown.  If GITWEB_LIST points to
  48   file with list of project, only those repositories listed would be
  49   available for gitweb.  [No default]
  50 * GITWEB_HOMETEXT
  51   Points to an .html file which is included on the gitweb project
  52   overview page ('projects_list' view), if it exists.  Relative to
  53   gitweb.cgi script.  [Default: indextext.html]
  54 * GITWEB_SITE_HEADER
  55   Filename of html text to include at top of each page.  Relative to
  56   gitweb.cgi script.  [No default]
  57 * GITWEB_SITE_FOOTER
  58   Filename of html text to include at bottom of each page.  Relative to
  59   gitweb.cgi script.  [No default]
  60 * GITWEB_HOME_LINK_STR
  61   String of the home link on top of all pages, leading to $home_link
  62   (usually main gitweb page, which means projects list).  Used as first
  63   part of gitweb view "breadcrumb trail": <home> / <project> / <view>.
  64   [Default: projects]
  65 * GITWEB_SITENAME
  66   Name of your site or organization to appear in page titles.  Set it
  67   to something descriptive for clearer bookmarks etc.  If not set
  68   (if empty) gitweb uses "$SERVER_NAME Git", or "Untitled Git" if
  69   SERVER_NAME CGI environment variable is not set (e.g. if running
  70   gitweb as standalone script).  [No default]
  71 * GITWEB_BASE_URL
  72   Git base URLs used for URL to where fetch project from, i.e. full
  73   URL is "$git_base_url/$project".  Shown on projects summary page.
  74   Repository URL for project can be also configured per repository; this
  75   takes precedence over URLs composed from base URL and a project name.
  76   Note that you can setup multiple base URLs (for example one for
  77   git:// protocol access, another for http:// access) from the gitweb
  78   config file.  [No default]
  79 * GITWEB_CSS
  80   Points to the location where you put gitweb.css on your web server
  81   (or to be more generic, the URI of gitweb stylesheet).  Relative to the
  82   base URI of gitweb.  Note that you can setup multiple stylesheets from
  83   the gitweb config file.  [Default: gitweb.css]
  84 * GITWEB_LOGO
  85   Points to the location where you put git-logo.png on your web server
  86   (or to be more generic URI of logo, 72x27 size, displayed in top right
  87   corner of each gitweb page, and used as logo for Atom feed).  Relative
  88   to base URI of gitweb.  [Default: git-logo.png]
  89 * GITWEB_FAVICON
  90   Points to the location where you put git-favicon.png on your web server
  91   (or to be more generic URI of favicon, assumed to be image/png type;
  92   web browsers that support favicons (website icons) may display them
  93   in the browser's URL bar and next to site name in bookmarks).  Relative
  94   to base URI of gitweb.  [Default: git-favicon.png]
  95 * GITWEB_JS
  96   Points to the localtion where you put gitweb.js on your web server
  97   (or to be more generic URI of JavaScript code used by gitweb).
  98   Relative to base URI of gitweb.  [Default: gitweb.js]
  99 * GITWEB_CONFIG
 100   This Perl file will be loaded using 'do' and can be used to override any
 101   of the options above as well as some other options -- see the "Runtime
 102   gitweb configuration" section below, and top of 'gitweb.cgi' for their
 103   full list and description.  If the environment variable GITWEB_CONFIG
 104   is set when gitweb.cgi is executed, then the file specified in the
 105   environment variable will be loaded instead of the file specified
 106   when gitweb.cgi was created.  [Default: gitweb_config.perl]
 107 * GITWEB_CONFIG_SYSTEM
 108   This Perl file will be loaded using 'do' as a fallback if GITWEB_CONFIG
 109   does not exist.  If the environment variable GITWEB_CONFIG_SYSTEM is set
 110   when gitweb.cgi is executed, then the file specified in the environment
 111   variable will be loaded instead of the file specified when gitweb.cgi was
 112   created.  [Default: /etc/gitweb.conf]
 113
 114
 115Runtime gitweb configuration
 116----------------------------
 117
 118You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`
 119(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
 120as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
 121The most notable thing that is not configurable at compile time are the
 122optional features, stored in the '%features' variable.
 123
 124Ultimate description on how to reconfigure the default features setting
 125in your `GITWEB_CONFIG` or per-project in `project.git/config` can be found
 126as comments inside 'gitweb.cgi'.
 127
 128See also the "Gitweb config file" (with an example of config file), and
 129the "Gitweb repositories" sections in INSTALL file for gitweb.
 130
 131
 132The gitweb config file is a fragment of perl code. You can set variables
 133using "our $variable = value"; text from "#" character until the end
 134of a line is ignored. See perlsyn(1) man page for details.
 135
 136Below is the list of variables which you might want to set in gitweb config.
 137See the top of 'gitweb.cgi' for the full list of variables and their
 138descriptions.
 139
 140Gitweb config file variables
 141~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 142
 143You can set, among others, the following variables in gitweb config files
 144(with the exception of $projectroot and $projects_list this list does
 145not include variables usually directly set during build):
 146 * $GIT
 147   Core git executable to use.  By default set to "$GIT_BINDIR/git", which
 148   in turn is by default set to "$(bindir)/git".  If you use git from binary
 149   package, set this to "/usr/bin/git".  This can just be "git" if your
 150   webserver has a sensible PATH.  If you have multiple git versions
 151   installed it can be used to choose which one to use.
 152 * $version
 153   Gitweb version, set automatically when creating gitweb.cgi from
 154   gitweb.perl. You might want to modify it if you are running modified
 155   gitweb.
 156 * $projectroot
 157   Absolute filesystem path which will be prepended to project path;
 158   the path to repository is $projectroot/$project.  Set to
 159   $GITWEB_PROJECTROOT during installation.  This variable have to be
 160   set correctly for gitweb to find repositories.
 161 * $projects_list
 162   Source of projects list, either directory to scan, or text file
 163   with list of repositories (in the "<URI-encoded repository path> SP
 164   <URI-encoded repository owner>" line format; actually there can be
 165   any sequence of whitespace in place of space (SP)).  Set to
 166   $GITWEB_LIST during installation.  If empty, $projectroot is used
 167   to scan for repositories.
 168 * $my_url, $my_uri
 169   Full URL and absolute URL of gitweb script;
 170   in earlier versions of gitweb you might have need to set those
 171   variables, now there should be no need to do it.
 172 * $home_link
 173   Target of the home link on top of all pages (the first part of view
 174   "breadcrumbs").  By default set to absolute URI of a page ($my_uri).
 175 * @stylesheets
 176   List of URIs of stylesheets (relative to base URI of a page). You
 177   might specify more than one stylesheet, for example use gitweb.css
 178   as base, with site specific modifications in separate stylesheet
 179   to make it easier to upgrade gitweb. You can add 'site' stylesheet
 180   for example by using
 181      push @stylesheets, "gitweb-site.css";
 182   in the gitweb config file.
 183 * $logo_url, $logo_label
 184   URI and label (title) of GIT logo link (or your site logo, if you choose
 185   to use different logo image). By default they point to git homepage;
 186   in the past they pointed to git documentation at www.kernel.org.
 187 * $projects_list_description_width
 188   The width (in characters) of the projects list "Description" column.
 189   Longer descriptions will be cut (trying to cut at word boundary);
 190   full description is available as 'title' attribute (usually shown on
 191   mouseover).  By default set to 25, which might be too small if you
 192   use long project descriptions.
 193 * @git_base_url_list
 194   List of git base URLs used for URL to where fetch project from, shown
 195   in project summary page.  Full URL is "$git_base_url/$project".
 196   You can setup multiple base URLs (for example one for  git:// protocol
 197   access, and one for http:// "dumb" protocol access).  Note that per
 198   repository configuration in 'cloneurl' file, or as values of gitweb.url
 199   project config.
 200 * $default_blob_plain_mimetype
 201   Default mimetype for blob_plain (raw) view, if mimetype checking
 202   doesn't result in some other type; by default 'text/plain'.
 203 * $default_text_plain_charset
 204   Default charset for text files. If not set, web server configuration
 205   would be used.
 206 * $mimetypes_file
 207   File to use for (filename extension based) guessing of MIME types before
 208   trying /etc/mime.types. Path, if relative, is taken currently as
 209   relative to the current git repository.
 210 * $fallback_encoding
 211   Gitweb assumes this charset if line contains non-UTF-8 characters.
 212   Fallback decoding is used without error checking, so it can be even
 213   'utf-8'. Value must be valid encoding; see Encoding::Supported(3pm) man
 214   page for a list.   By default 'latin1', aka. 'iso-8859-1'.
 215 * @diff_opts
 216   Rename detection options for git-diff and git-diff-tree. By default
 217   ('-M'); set it to ('-C') or ('-C', '-C') to also detect copies, or
 218   set it to () if you don't want to have renames detection.
 219 * $prevent_xss
 220   If true, some gitweb features are disabled to prevent content in
 221   repositories from launching cross-site scripting (XSS) attacks.  Set this
 222   to true if you don't trust the content of your repositories. The default
 223   is false.
 224
 225
 226Projects list file format
 227~~~~~~~~~~~~~~~~~~~~~~~~~
 228
 229Instead of having gitweb find repositories by scanning filesystem starting
 230from $projectroot (or $projects_list, if it points to directory), you can
 231provide list of projects by setting $projects_list to a text file with list
 232of projects (and some additional info).  This file uses the following
 233format:
 234
 235One record (for project / repository) per line, whitespace separated fields;
 236does not support (at least for now) lines continuation (newline escaping).
 237Leading and trailing whitespace are ignored, any run of whitespace can be
 238used as field separator (rules for Perl's "split(' ', $line)").  Keyed by
 239the first field, which is project name, i.e. path to repository GIT_DIR
 240relative to $projectroot.  Fields use modified URI encoding, defined in
 241RFC 3986, section 2.1 (Percent-Encoding), or rather "Query string encoding"
 242(see http://en.wikipedia.org/wiki/Query_string#URL_encoding), the difference
 243being that SP (' ') can be encoded as '+' (and therefore '+' has to be also
 244percent-encoded).  Reserved characters are: '%' (used for encoding), '+'
 245(can be used to encode SPACE), all whitespace characters as defined in Perl,
 246including SP, TAB and LF, (used to separate fields in a record).
 247
 248Currently list of fields is
 249 * <repository path>  - path to repository GIT_DIR, relative to $projectroot
 250 * <repository owner> - displayed as repository owner, preferably full name,
 251                        or email, or both
 252
 253You can additionally use $projects_list file to limit which repositories
 254are visible, and together with $strict_export to limit access to
 255repositories (see "Gitweb repositories" section in gitweb/INSTALL).
 256
 257
 258Per-repository gitweb configuration
 259~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 260
 261You can also configure individual repositories shown in gitweb by creating
 262file in the GIT_DIR of git repository, or by setting some repo configuration
 263variable (in GIT_DIR/config).
 264
 265You can use the following files in repository:
 266 * README.html
 267   A .html file (HTML fragment) which is included on the gitweb project
 268   summary page inside <div> block element. You can use it for longer
 269   description of a project, to provide links (for example to project's
 270   homepage), etc. This is recognized only if XSS prevention is off
 271   ($prevent_xss is false); a way to include a readme safely when XSS
 272   prevention is on may be worked out in the future.
 273 * description (or gitweb.description)
 274   Short (shortened by default to 25 characters in the projects list page)
 275   single line description of a project (of a repository). Plain text file;
 276   HTML will be escaped. By default set to
 277     Unnamed repository; edit this file to name it for gitweb.
 278   from the template during repository creation. You can use the
 279   gitweb.description repo configuration variable, but the file takes
 280   precedence.
 281 * cloneurl (or multiple-valued gitweb.url)
 282   File with repository URL (used for clone and fetch), one per line.
 283   Displayed in the project summary page. You can use multiple-valued
 284   gitweb.url repository configuration variable for that, but the file
 285   takes precedence.
 286 * gitweb.owner
 287   You can use the gitweb.owner repository configuration variable to set
 288   repository's owner. It is displayed in the project list and summary
 289   page. If it's not set, filesystem directory's owner is used
 290   (via GECOS field / real name field from getpwiud(3)).
 291 * various gitweb.* config variables (in config)
 292   Read description of %feature hash for detailed list, and some
 293   descriptions.
 294
 295
 296Webserver configuration
 297-----------------------
 298
 299If you want to have one URL for both gitweb and your http://
 300repositories, you can configure apache like this:
 301
 302<VirtualHost *:80>
 303    ServerName git.example.org
 304    DocumentRoot /pub/git
 305    SetEnv      GITWEB_CONFIG   /etc/gitweb.conf
 306    RewriteEngine on
 307    # make the front page an internal rewrite to the gitweb script
 308    RewriteRule ^/$  /cgi-bin/gitweb.cgi
 309    # make access for "dumb clients" work
 310    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
 311</VirtualHost>
 312
 313The above configuration expects your public repositories to live under
 314/pub/git and will serve them as http://git.domain.org/dir-under-pub-git,
 315both as cloneable GIT URL and as browseable gitweb interface.
 316If you then start your git-daemon with --base-path=/pub/git --export-all
 317then you can even use the git:// URL with exactly the same path.
 318
 319Setting the environment variable GITWEB_CONFIG will tell gitweb to use
 320the named file (i.e. in this example /etc/gitweb.conf) as a
 321configuration for gitweb.  Perl variables defined in here will
 322override the defaults given at the head of the gitweb.perl (or
 323gitweb.cgi).  Look at the comments in that file for information on
 324which variables and what they mean.
 325
 326If you use the rewrite rules from the example you'll likely also need
 327something like the following in your gitweb.conf (or gitweb_config.perl) file:
 328
 329  @stylesheets = ("/some/absolute/path/gitweb.css");
 330  $my_uri = "/";
 331  $home_link = "/";
 332
 333
 334PATH_INFO usage
 335-----------------------
 336If you enable PATH_INFO usage in gitweb by putting
 337
 338   $feature{'pathinfo'}{'default'} = [1];
 339
 340in your gitweb.conf, it is possible to set up your server so that it
 341consumes and produces URLs in the form
 342
 343http://git.example.com/project.git/shortlog/sometag
 344
 345by using a configuration such as the following, that assumes that
 346/var/www/gitweb is the DocumentRoot of your webserver, and that it
 347contains the gitweb.cgi script and complementary static files
 348(stylesheet, favicon):
 349
 350<VirtualHost *:80>
 351        ServerAlias git.example.com
 352
 353        DocumentRoot /var/www/gitweb
 354
 355        <Directory /var/www/gitweb>
 356                Options ExecCGI
 357                AddHandler cgi-script cgi
 358
 359                DirectoryIndex gitweb.cgi
 360
 361                RewriteEngine On
 362                RewriteCond %{REQUEST_FILENAME} !-f
 363                RewriteCond %{REQUEST_FILENAME} !-d
 364                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
 365        </Directory>
 366</VirtualHost>
 367
 368The rewrite rule guarantees that existing static files will be properly
 369served, whereas any other URL will be passed to gitweb as PATH_INFO
 370parameter.
 371
 372Notice that in this case you don't need special settings for
 373@stylesheets, $my_uri and $home_link, but you lose "dumb client" access
 374to your project .git dirs. A possible workaround for the latter is the
 375following: in your project root dir (e.g. /pub/git) have the projects
 376named without a .git extension (e.g. /pub/git/project instead of
 377/pub/git/project.git) and configure Apache as follows:
 378
 379<VirtualHost *:80>
 380        ServerAlias git.example.com
 381
 382        DocumentRoot /var/www/gitweb
 383
 384        AliasMatch ^(/.*?)(\.git)(/.*)?$ /pub/git$1$3
 385        <Directory /var/www/gitweb>
 386                Options ExecCGI
 387                AddHandler cgi-script cgi
 388
 389                DirectoryIndex gitweb.cgi
 390
 391                RewriteEngine On
 392                RewriteCond %{REQUEST_FILENAME} !-f
 393                RewriteCond %{REQUEST_FILENAME} !-d
 394                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
 395        </Directory>
 396</VirtualHost>
 397
 398The additional AliasMatch makes it so that
 399
 400http://git.example.com/project.git
 401
 402will give raw access to the project's git dir (so that the project can
 403be cloned), while
 404
 405http://git.example.com/project
 406
 407will provide human-friendly gitweb access.
 408
 409This solution is not 100% bulletproof, in the sense that if some project
 410has a named ref (branch, tag) starting with 'git/', then paths such as
 411
 412http://git.example.com/project/command/abranch..git/abranch
 413
 414will fail with a 404 error.
 415
 416
 417
 418Originally written by:
 419  Kay Sievers <kay.sievers@vrfy.org>
 420
 421Any comment/question/concern to:
 422  Git mailing list <git@vger.kernel.org>