diff options
| author | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2011-04-07 05:35:57 -0500 |
|---|---|---|
| committer | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2011-04-07 06:01:05 -0500 |
| commit | 1e2affe72b316038a8d6a54ee91183e2a01c0103 (patch) | |
| tree | 2c566b696c0578ba21f083b60d54056cd2776bf0 | |
| parent | 6f4fa7ba7e61b6365302ed5c7d416face8ccc2f2 (diff) | |
Add script to graft a repo based on commit message
| -rwxr-xr-x | qt-bundle/git-qt-grafts | 138 | ||||
| -rw-r--r-- | qt-bundle/git-qt-grafts.bat | 42 |
2 files changed, 180 insertions, 0 deletions
diff --git a/qt-bundle/git-qt-grafts b/qt-bundle/git-qt-grafts new file mode 100755 index 0000000..516a1d7 --- /dev/null +++ b/qt-bundle/git-qt-grafts @@ -0,0 +1,138 @@ +#!/usr/bin/perl -w +#################################################################################################### +# +# git-qt-grafts +# +# Sets up the proper grafts for a Qt repository +# +# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +# Contact: Nokia Corporation (qt-info@nokia.com) +# +#################################################################################################### + +use File::Basename; +use Cwd 'abs_path'; +use strict; + +my $history_location; + +# Syntax: fileContents(filename) +# Returns: String with contents of the file, or empty string if file +# doens't exist. +sub fileContents { + my ($filename) = @_; + my $filecontents = ""; + if (-e $filename) { + open(I, "< $filename") || die "Could not open $filename for reading, read block?"; + local $/; + binmode I; + $filecontents = <I>; + close I; + } + return $filecontents; +} + +sub fileContains { + my ($filename, $text) = @_; + # purposely not using perl grep here + foreach my $line (split /\n/, fileContents("$filename")) { + return 1 if ("$line" eq "$text"); + } + return 0; +} + +sub showUsage { + my $prg = basename($0); + print "Usage: $prg <path to Qt history>:\n"; +} + +while ( @ARGV ) { + my $arg = shift @ARGV; + if ($arg eq "-?" || $arg eq "-h" || $arg eq "-help" || $arg eq "?") { + showUsage(); + exit 0; + } elsif (!$history_location) { + $history_location = $arg; + } else { + print "Unknown option: $arg\n\n"; + showUsage(); + exit 1; + } +} + +# Get current git-dir +my $git_dir = `git rev-parse --git-dir`; +chomp $git_dir; +if (!$git_dir) { + print "Cannot find any Git dir!\n"; + exit 1; +} + +# validate path for history repo +if (!$history_location || !-e $history_location) { + print "You need to provide a path to the monolithic Qt repo!\n"; + exit 1; +} +my $history_alternates_objects = `cd $history_location && git rev-parse --git-dir`; +chomp $history_alternates_objects ; +if (!$history_alternates_objects || !-e "$history_alternates_objects/objects") { + print "Monolithic Qt repo path is not a valid Git repo!\n"; + exit 1; +} +$history_alternates_objects = abs_path("$history_location/$history_alternates_objects/objects");; + +# check if we already point to this alternate object store +my $git_alternates_file = "$git_dir/objects/info/alternates"; +my $found_alternate = fileContains($git_alternates_file, $history_alternates_objects); + +# get first commit SHA1 of this repo which mentions branching from a commit +my $GIT_REVLIST; +my $git_pid = open(GIT_REVLIST, "git rev-list --reverse --grep='Branched from .*at commit' HEAD |"); +my $first_commit = <GIT_REVLIST>; +chomp $first_commit; +close(GIT_REVLIST); + +# find the graft point which the first commit mentions +my $first_commit_msg = `git show -s --format=%B $first_commit`; +my $graft_to_commit = $first_commit_msg; +$graft_to_commit =~ s/^.+Branched from .+at commit\n([a-f0-9]+)\n.*/$1/s; +if (!$graft_to_commit || $graft_to_commit eq $first_commit_msg) { + $first_commit_msg =~ s/\n([^\n])/\n $1/g; #indent msg + print "This repo does not refer to a graft point, so no grafts added!\n"; + print "\nFirst commit message of this repo:". + "\n----------------------------------\n ". + $first_commit_msg; + exit 0; +} + +# check that we don't already have this graft already setup +my $graft_file = "$git_dir/info/grafts"; +my $graft_line = "$first_commit $graft_to_commit"; +my $found_graft = fileContains($graft_file, $graft_line); +if ($found_graft) { + print "This repo already grafts to the proper commit\n"; + exit 0; +} + +# verify that alternate object store contains the commit we want to graft to +my $validated_object = `cd $history_location && git rev-parse --verify $graft_to_commit`; +chomp $validated_object; +if ("$validated_object" ne "$graft_to_commit") { + print "History repo ($history_location) does not contain commit $graft_to_commit!\n"; + exit 1; +} + +# if our alternates file didn't contain the "history repo" path already +# add its path now +if (!$found_alternate) { + open(I, ">> $git_alternates_file") || die "Could not open $git_alternates_file for writing, wrong permissions?"; + print I "$history_alternates_objects\n"; + close(I); +} + +# add graft +open(I, ">> $graft_file") || die "Could not open $graft_file for writing, wrong permissions?"; +print I "$graft_line\n"; +close(I); + +print "Grafted $first_commit -> $graft_to_commit\n"; diff --git a/qt-bundle/git-qt-grafts.bat b/qt-bundle/git-qt-grafts.bat new file mode 100644 index 0000000..58b63b7 --- /dev/null +++ b/qt-bundle/git-qt-grafts.bat @@ -0,0 +1,42 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +:: All rights reserved. +:: Contact: Nokia Corporation (qt-info@nokia.com) +:: +:: This file is part of the tools applications of the Qt Toolkit. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: No Commercial Usage +:: This file contains pre-release code and may not be distributed. +:: You may use this file in accordance with the terms and conditions +:: contained in the Technology Preview License Agreement accompanying +:: this package. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 2.1 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 2.1 requirements +:: will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +:: +:: In addition, as a special exception, Nokia gives you certain additional +:: rights. These rights are described in the Nokia Qt LGPL Exception +:: version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +:: +:: If you have questions regarding the use of this file, please contact +:: Nokia at qt-info@nokia.com. +:: +:: +:: +:: +:: +:: +:: +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +@rem ***** This assumes PERL is in the PATH ***** +@perl.exe %~dp0git-qt-grafts %* |
