git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 3/3] add autoupdate feature
Date: Wed, 28 Oct 2009 20:24:25 -0400	[thread overview]
Message-ID: <20091029002425.GC1057@sigill.intra.peff.net> (raw)
In-Reply-To: <20091029002229.GA986@sigill.intra.peff.net>

Users can't be bothered to keep their software up to date, so
we must do it for them.  Whenever any git command is
invoked, this patch checks for new releases of git at
kernel.org, and automatically upgrades your version of git.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Sam Vilain <sam@vilain.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Nick Edelen <sirnot@gmail.com>
Signed-off-by: "J.H." <warthog9@kernel.org>
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 .gitignore          |    1 +
 Makefile            |    1 +
 git-autoupdate.perl |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 git.c               |    9 +++++++-
 4 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100644 git-autoupdate.perl

diff --git a/.gitignore b/.gitignore
index cf0d8b9..5a2703d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ git-annotate
 git-apply
 git-archimport
 git-archive
+git-autoupdate
 git-bisect
 git-bisect--helper
 git-blame
diff --git a/Makefile b/Makefile
index ae4b9fc..ba386a4 100644
--- a/Makefile
+++ b/Makefile
@@ -335,6 +335,7 @@ SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
 
 SCRIPT_PERL += git-add--interactive.perl
+SCRIPT_PERL += git-autoupdate.perl
 SCRIPT_PERL += git-difftool.perl
 SCRIPT_PERL += git-archimport.perl
 SCRIPT_PERL += git-cvsexportcommit.perl
diff --git a/git-autoupdate.perl b/git-autoupdate.perl
new file mode 100644
index 0000000..c8ca10b
--- /dev/null
+++ b/git-autoupdate.perl
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+use LWP::Simple;
+use strict;
+
+my $ROOT = "http://kernel.org/pub/software/scm/git";
+
+my $us = our_git_version();
+my $them = latest_git_version();
+
+if (compare_versions($us, $them) < 0) {
+	print STDERR <<EOF;
+A new version of git is available! Auto-installing version $them.
+EOF
+}
+else {
+	exit 0;
+}
+
+upgrade($them);
+exit 42;
+
+sub our_git_version {
+	local $_ = `git version`;
+	/^git version (.*?)(\.\d+\.g[a-f0-9]+)?(\.dirty)?$/
+		or die "unable to read git version: $_";
+	return $1;
+}
+
+sub latest_git_version {
+	local $_ = get("$ROOT/");
+	my @versions = /git-([0-9.]+)\.tar\.gz/g
+		or die "unable to find any git versions at $ROOT";
+	# git version numbers have always sorted lexicographically so far,
+	# so let's just assume that will be the case forever
+	return (sort @versions)[-1];
+}
+
+sub compare_versions {
+	# let's assume lexicographical sorting again
+	return $_[0] cmp $_[1];
+}
+
+sub upgrade {
+	my $version = shift;
+	my $fn = "git-$version.tar.gz";
+	getstore("$ROOT/$fn", "/tmp/$fn") == 200
+		or die "unable to fetch $ROOT/$fn";
+	my $rc = system qq(
+		cd /tmp &&
+		gunzip -c $fn | tar xf - &&
+		cd git-$version &&
+		git config-mak >config.mak &&
+		make install
+	);
+	$rc == 0 or die "failed to upgrade git";
+	system("less /tmp/git-$version/RelNotes");
+}
diff --git a/git.c b/git.c
index 01ddf06..959ad52 100644
--- a/git.c
+++ b/git.c
@@ -462,10 +462,17 @@ int main(int argc, const char **argv)
 
 	if (!getenv("GIT_NOSPLASH") && !(argv[1] && !strcmp(argv[1], "splash"))) {
 		const char *a[] = { "splash", NULL };
-		const char *e[] = { "GIT_NOSPLASH=1", NULL };
+		const char *e[] = { "GIT_NOSPLASH=1", "GIT_NOAUTOUPDATE=1", NULL };
 		run_command_v_opt_cd_env(a, RUN_GIT_CMD, NULL, e);
 	}
 
+	if (!getenv("GIT_NOAUTOUPDATE")) {
+		const char *a[] = { "autoupdate", NULL };
+		const char *e[] = { "GIT_NOSPLASH=1", "GIT_NOAUTOUPDATE=1", NULL };
+		if (run_command_v_opt_cd_env(a, RUN_GIT_CMD, NULL, e) == 42)
+			exit(run_command_v_opt_cd_env(argv, 0, NULL, e));
+	}
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
-- 
1.6.5.1.3.g9d77a

  parent reply	other threads:[~2009-10-29  0:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-29  0:22 [PATCH 0/3] increase user-friendliness Jeff King
2009-10-29  0:24 ` [PATCH 1/3] add splash screen Jeff King
2009-10-29  1:28   ` Michael Witten
2009-10-29  2:25   ` A Large Angry SCM
2009-10-29 12:48   ` Paolo Bonzini
2009-10-29  0:24 ` [PATCH 2/3] add config-mak git command Jeff King
2009-10-29  0:24 ` Jeff King [this message]
2009-10-29 10:59 ` [PATCH 0/3] increase user-friendliness Johannes Schindelin
2009-10-30 18:29   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091029002425.GC1057@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).