Skip to content
Lionel Henry edited this page Oct 30, 2018 · 22 revisions

Setup instructions

Cloning this repository is the same as with any other git repository.

git clone https://github.com/wch/r-source.git
cd r-source

To clone the repository without fetching the entire history of the project, you can do a shallow clone, with:

# Get just the last commit
git clone https://github.com/wch/r-source.git --depth 1

Shallow clones are quick, but it is often useful to clone the full history locally. This allows you to search the history, blame, etc.

These are some useful commands on your local clone of the repository:

git branch -a                     # Show all branches (including remote branches)
git checkout origin/R-2-15-branch # Checkout a branch
git checkout origin/tags/R-2-15-1 # Checkout a tag (this is how svn tags are represented)
git checkout trunk                # 'trunk' is the only local branch; it tracks origin/trunk

Adding SVN information

As of revision 62183, R must either be built from a svn checkout, or from the tarball generated by make dist (which must in turn be built from a svn checkout). Attempts to do otherwise will result in an error.

There are two ways around this. The first works with bare git clones but has some limitations (it makes it harder to build in an external folder), while the second transforms your git repo into a git-svn one, which prevents you from running certain git operations like pull.

Add SVN-REVISION manually

Normally, you would do something like this to build R from source:

# Download recommended packages
tools/rsync-recommended
./configure
make

You can work around the SVN revision check by adding these commands between ./configure and make:

# Download recommended packages
tools/rsync-recommended

./configure

(cd doc/manual && make front-matter html-non-svn)

# Create the SVN-REVISION file:
echo -n 'Revision: ' > SVN-REVISION
git log --format=%B -n 1 \
  | grep "^git-svn-id"    \
  | sed -E 's/^git-svn-id: https:\/\/svn.r-project.org\/R\/[^@]*@([0-9]+).*$/\1/' \
  >> SVN-REVISION
echo -n 'Last Changed Date: ' >>  SVN-REVISION
git log -1 --pretty=format:"%ad" --date=iso | cut -d' ' -f1 >> SVN-REVISION

make

Initialising git-svn

Transforming your git repo to a git-svn repo has several benefits: you don't have to worry about the SVN-REVISION file, it allows you to build R in an external folder, and you get the latest changes to svn that haven't yet been pushed to Github (this repository is updated once per hour). However, it is easy to corrupt your git-svn repo if you run commands like git pull. Once you have switched to git-svn, you can create branches and push them to your local github repo, but you should always use git svn rebase to fetch new revisions.

Use git svn init to transform your repo:

# Prefix should match remote repo name with a trailing slash
git svn init --prefix=origin/ -s https://svn.r-project.org/R/

To our knowledge, there is no reliable way to recover the full history of a shallow clone once you've initialised git-svn. So be sure to run git pull --unshallow before git svn init if you'd like to work with the full history (recommended).

Git-SVN repositories work a little differently than normal git repos because SVN has no support for non-linear history. To work around this, git-svn commands avoid any pulling or merging. The main command to know about is git svn rebase which fetches fromnew revisions from the subversion server for the current branch (typically trunk), and rebase any unpushed commits on top of it. In normal workflows, we don't have any unpushed commits on trunk, so the net effect of rebasing is to set our local trunk branch to point to the latest svn revisions:

git svn rebase

Check that git-svn is correctly initialised:

git svn info

Rebasing automatically fetches revisions for the current branch, which you can do manually with:

git svn fetch --parent

To fetch for all branches, remove --parent. The first time will take a long time because it needs to build the mappings from SVN revisions to git hashes for all SVN branches and tags. Also, this command fetches all unfetched branches and thus will take an even longer time if you've cloned with --depth=1 (unless you've also passed --no-single-branch to git clone):

git svn fetch

Important: Once you've initialised git-svn, never use git pull again, or you will cause trouble to your repo. Always use git svn rebase. If you see "Unable to determine upstream SVN information from working tree history", that's probably because you've used git pull.

Building R from source

Here is the minimal procedure for building an R:

# Download recommended packages
tools/rsync-recommended

./configure && make all && make install

However, building in the repo root is not optimal because all the build files (autotools files, compiled object files, test artifacts, ...) are created in place and end up cluttering the working directory. It is recommended to create all build artifacts in a separate directory. To do so, just call the configure script from that location. Here we're going to create a build directory inside the repository and gitignore it, but it could just as well be located outside the repo:

mkdir build
echo "build/" >> .git/info/exclude

cd build
../configure && make all && make install

Every subsequent actions take place inside the build directory. For instance, make check-devel inside build/tests/ to run the tests, make inside build/src/main to recompile changes to .c files, etc.

Build instructions for specific platforms

Contributing patches to R core

See Contributing.

Other mirrors

There is another r-source repository on GitHub, which has one commit per R release. This can be useful if you're just interested in seeing the changes between versions: https://github.com/SurajGupta/r-source