Package: vcs-repo-mgr
The Python packagevcs-repo-mgrprovides a command line program and Python
API to perform common operations (in the context of packaging/deployment) onversion controlrepositories. It’s currently tested on Python 2.6, 2.7, 3.4,
3.5 and 3.6 on Linux and Mac OS X.Bazaar,MercurialandGitrepositories
are supported.InstallationUsageUpdating repositoriesFinding revision numbers/idsExporting revisionsFuture improvementsKnown issuesProblematic dependenciesContactLicenseInstallationThevcs-repo-mgrpackage is available onPyPIwhich means installation
should be as simple as:$pipinstallvcs-repo-mgrThere’s actually a multitude of ways to install Python packages (e.g. theper
user site-packages directory,virtual environmentsor just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions ;-).You will also needBazaar,Mercurialand/orGitinstalled (depending on the
type of repositories you want to work with). Here’s how you install them on
Debian and Ubuntu based systems:$sudoapt-getinstallbzrmercurialgit-coreUsageThere are two ways to use thevcs-repo-mgrpackage: As the command line
programvcs-tooland as a Python API. For details about the Python API
please refer to the API documentation available onRead the Docs. The
command line interface is described below.Usage:vcs-tool [OPTIONS] [ARGS]Command line program to perform common operations (in the context of
packaging/deployment) on version control repositories. Supports Bazaar,
Mercurial and Git repositories.Supported options:OptionDescription-r,--repository=REPOSITORYSelect a repository to operate on by providing the name of a repository
defined in one of the configuration files ~/.vcs-repo-mgr.ini and
/etc/vcs-repo-mgr.ini.Alternatively the location of a remote repository can be given. The
location should be prefixed by the type of the repository (with a “+” in
between) unless the location ends in “.git” in which case the prefix is
optional.--rev,--revision=REVISIONSelect a revision to operate on. Accepts any string that’s supported by the
VCS system that manages the repository, which means you can provide branch
names, tag names, exact revision ids, etc. This option is used in
combination with the--find-revision-number,--find-revision-idand--exportoptions.If this option is not provided a default revision is selected: “last:1” for
Bazaar repositories, “master” for git repositories and “default” (not
“tip”!) for Mercurial repositories.--release=RELEASE_IDSelect a release to operate on. This option works in the same way as the--revisionoption. Please refer to the vcs-repo-mgr documentation for
details on “releases”.Although release identifiers are based on branch or tag names they
may not correspond literally, this is why the release identifier you
specify here is translated to a global revision id before being passed to
the VCS system.-n,--find-revision-numberPrint the local revision number (an integer) of the revision given with the--revisionoption. Revision numbers are useful as a build number or when a
simple, incrementing version number is required. Revision numbers should
not be used to unambiguously refer to a revision (use revision ids for that
instead). This option is used in combination with the--repositoryand--revisionoptions.-i,--find-revision-idPrint the global revision id (a string) of the revision given with the--revisionoption. Global revision ids are useful to unambiguously refer to
a revision. This option is used in combination with the--repositoryand--revisionoptions.--list-releasesPrint the identifiers of the releases in the repository given with the--repositoryoption. The release identifiers are printed on standard
output (one per line), ordered using natural order comparison.--select-release=RELEASE_IDPrint the identifier of the newest release that is not newer thanRELEASE_IDin the repository given with the--repositoryoption.
The release identifier is printed on standard output.-s,--sum-revisionsPrint the summed revision numbers of multiple repository/revision pairs.
The repository/revision pairs are taken from the positional arguments to
vcs-repo-mgr.This is useful when you’re building a package based on revisions from
multiple VCS repositories. By taking changes in all repositories into
account when generating version numbers you can make sure that your version
number is bumped with every single change.--vcs-control-fieldPrint a line containing a Debian control file field and value. The field
name will be one of “Vcs-Bzr”, “Vcs-Hg” or “Vcs-Git”. The value will be the
repository’s remote location and the selected revision (separated by a “#”
character).-u,--updateCreate/update the local clone of a remote repository by pulling the latest
changes from the remote repository. This option is used in combination with
the--repositoryoption.-m,--merge-upMerge a change into one or more release branches and the default branch.By default merging starts from the current branch. You can explicitly
select the branch where merging should start using the--rev,--revisionand--releaseoptions.You can also start by merging a feature branch into the selected release
branch before merging the change up through later release branches and the
default branch. To do so you pass the name of the feature branch as a
positional argument.If the feature branch is located in a different repository you can prefix
the location of the repository to the name of the feature branch with a “#”
token in between, to delimit the location from the branch name.-e,--export=DIRECTORYExport the contents of a specific revision of a repository to a local
directory. This option is used in combination with the--repositoryand--revisionoptions.-d,--find-directoryPrint the absolute pathname of a local repository. This option is used in
combination with the--repositoryoption.-v,--verboseIncrease logging verbosity (can be repeated).-q,--quietDecrease logging verbosity (can be repeated).-h,--helpShow this message and exit.The primary way to use thevcs-toolcommand requires you to create a
configuration file:$cat>~/.vcs-repo-mgr.ini<< EOF
[coloredlogs]
type = git
local = /tmp/coloredlogs
remote = git@github.com:xolox/python-coloredlogs.git
EOFBecause the-r,--repositoryoption accepts remote repository locations
in addition to names it’s not actually required to create a configuration file.
Of course this depends on your use case(s).Below are some examples of the command line interface. If you’re interested in
using the Python API please refer to theonline documentation.Updating repositoriesIf the configuration file defines a localandremote repository and the local
repository doesn’t exist yet it will be created the first time you update it:$vcs-tool--repositorycoloredlogs--update2014-05-0418:55:54INFOCreatingGitcloneofgit@github.com:xolox/python-coloredlogs.gitat/tmp/coloredlogs..Cloningintobarerepository'/tmp/coloredlogs'...remote:Reusingexistingpack:96,done.remote:Countingobjects:5,done.remote:Compressingobjects:100%(5/5),done.remote:Total101(delta0),reused0(delta0)Receivingobjects:100%(101/101),28.11KiB,done.Resolvingdeltas:100%(44/44),done.Later runs will pull the latest changes instead of performing a full clone:$vcs-tool--repositorycoloredlogs--update2014-05-0418:55:56INFOUpdatingGitcloneofgit@github.com:xolox/python-coloredlogs.gitat/tmp/coloredlogs..Fromgithub.com:xolox/python-coloredlogs*branchHEAD->FETCH_HEADFinding revision numbers/idsRevision numbers are integer numbers that increment with every added revision.
They’re very useful during packaging/deployment:$vcs-tool--repositorycoloredlogs--revisionmaster--find-revision-number24Revision ids (hashes) are hexadecimal strings that uniquely identify revisions.
They are useful to unambiguously refer to a revision and its history (e.g while
building a package you can embed the revision id as a hint about the origins of
the package):$vcs-tool--repositorycoloredlogs--revisionmaster--find-revision-idbce75c1eea88ebd40135cd45de716fe9591e348cExporting revisionsBy default the repositories created byvcs-repo-mgrdo not contain a working tree,
just the version control files (inGitterminology this is called a “bare
repository”). This has two reasons:Bare repositories help conserve disk space. This is insignificant for small
repositories, but on large repositories it can make a noticeable difference.
Especially if you’re using a lot of them :-)Bare repositories enforce the principle that the working tree shouldn’t be
used during packaging (instead you should export the tree at a specific
revision to a temporary directory and use that). This insistence on not
using the working tree during packaging has two reasons:The working tree can contain files which are not under version control.
Such files should certainlynotbe included in a package
unintentionally.If the working tree of a repository is used, this makes it impossible to
safely perform parallel builds from the same repository (the builds can
corrupt each other’s working tree).This means that if you want to do something with the files in the repository
you have to export a revision to a (temporary) directory:$vcs-tool--repositorycoloredlogs--export/tmp/coloredlogs-snapshot2014-05-0419:17:24INFOExportingrevisionmasterof/tmp/coloredlogsto/tmp/coloredlogs-snapshot..$ls-l/tmp/coloredlogs-snapshottotal28Kdrwxrwxr-x2peterpeter4.0KMay314:31coloredlogsdrwxrwxr-x3peterpeter4.0KMay314:31vim-rw-rw-r--1peterpeter1.1KMay314:31LICENSE.txt-rw-rw-r--1peterpeter56May314:31MANIFEST.in-rw-rw-r--1peterpeter5.4KMay314:31README.rst-rwxrwxr-x1peterpeter1.1KMay314:31setup.pyFuture improvementsThis section is currently a “braindump” which means I haven’t committed to any
of these improvements, I’m just thinking out loud ;-).Improve interactive repository selectionTwo improvements for interactive usage of thevcs-toolprogram:Automatically load a repository’s configuration when a pathname is given
that matches an entry in a configuration file (right now you need to give
the repository’s name in order to load its configuration).Do the obvious thing when no repository is specified on the command line but
the working directory matches a configured repository.Wildcard matching in configuration filesIt might be interesting to support shell wildcard matching against local
directory names to apply a default configuration to a group of repositories?Enable more extensive customizationRight now the version control commands are hard coded and not easy to
customize for those cases where the existing API gets you 90% of where you
want to be but makes that last 10% impossible. Technically this is already
possible through subclassing, but a more lightweight solution would
certainly be nice to have :-).Known issuesThis section documents known issues that users may run into.Problematic dependenciesBazaar and Mercurial are both written in Python and available on PyPI and as
such I included them in the installation requirements ofvcs-repo-mgr,
because I couldn’t think of a good reason not to.Adding support for Python 3 tovcs-repo-mgrmade things more complicated
because Bazaar and Mercurial didn’t support Python 3, leading to installation
errors. To cope with this problem the Bazaar and Mercurial requirements were
made conditional on the Python version:On Python 2 the Bazaar and Mercurial packages would be installed together
withvcs-repo-mgr.On Python 3 the user was instead responsible for making sure that Bazaar and
Mercurial were installed (for example using system packages).This works fine becausevcs-repo-mgronly invokes Bazaar and Mercurial using
the command line interfaces so it doesn’t matter whether the version control
system is using the same version of Python asvcs-repo-mgr.Since then the installation of the Bazaar package has started failing on PyPy,
unfortunately this time there is no reliable and backwards compatible way to
make the Bazaar dependency optional in wheel distributionsdue to bugs in
setuptools.When I investigated support for environment markers that match Python
implementations (refer to the link above) I decided that instead of writing a
setup script full of nasty and fragile hacks I’d rather just drop official
(tested) support for PyPy, as silly as the reason for it may be.ContactThe latest version ofvcs-repo-mgris available onPyPIandGitHub. The
documentation is hosted onRead the Docsand includes achangelog. For bug
reports please create an issue onGitHub. If you have questions, suggestions,
etc. feel free to send me an e-mail atpeter@peterodding.com.LicenseThis software is licensed under theMIT license.© 2018 Peter Odding.