synch_hg_p4/synch_hg_xxx.pl
author Simon Howkins <simonh@symbian.org>
Wed, 14 Apr 2010 12:58:22 +0100
changeset 219 d57b367400c0
parent 1 4a4ca5a019bb
permissions -rw-r--r--
Updated release notes generation: Added copyright message Proper command line parsing Usage message if inputs are not right Added explanatory preamble to output "NEW" FCLs are marked as such Merge changesets are included in output
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     1
#! perl
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     2
1
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     8
#
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
     9
# Initial Contributors:
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    11
# 
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    12
# Contributors:
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    13
#
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    14
# Description:
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    15
# Skeleton Perl script to synchronise a branch in an SCM system with a Mercurial repository
4a4ca5a019bb Add EPL license text to the synch_hg* scripts
William Roberts <williamr@symbian.org>
parents: 0
diff changeset
    16
# It's synch_hg_p4.pl with the Perforce-specific details removed.
0
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    17
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    18
use strict;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    19
use Getopt::Long;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    20
use File::Temp qw/ tempfile tempdir /;	# for tempfile()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    21
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    22
my $verbose;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    23
my $debug = 0;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    24
my $rootdir;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    25
my $help;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    26
my $remoterepo;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    27
my $hgbranch;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    28
my $sync_prefix = "sync_";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    29
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    30
# abandon_sync, all ye who enter here
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    31
# This should send a notification to someone, as it will probably mean manual repair
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    32
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    33
sub abandon_sync(@)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    34
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    35
	print "ERROR - synchronisation of $rootdir abandoned\n\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    36
	print @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    37
	print "\n\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    38
	exit(1);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    39
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    40
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    41
# utility to run an external command
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    42
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    43
sub run_cmd($;$)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    44
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    45
	my ($cmd,$failurematch) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    46
	print "--- $cmd\n" if ($verbose || $debug);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    47
	my @output = `$cmd`;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    48
	print @output,"\n---\n" if ($debug);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    49
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    50
	if (defined $failurematch)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    51
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    52
		if (grep /$failurematch/, @output)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    53
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    54
			abandon_sync("COMMAND FAILED: $cmd\n", @output,"\n\n",
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    55
				"Output matched $failurematch\n");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    56
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    57
		else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    58
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    59
			print "CMD OK - Didn't match /$failurematch/\n" if ($debug);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    60
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    61
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    62
	if ($?)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    63
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    64
		print @output,"\n---\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    65
		abandon_sync("COMMAND FAILED: exit status = $?\n",$cmd,"\n");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    66
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    67
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    68
	return @output;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    69
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    70
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    71
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    72
# -------------- hg section -------------
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    73
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    74
# Code relating to other SCM system is abstracted into 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    75
# functions to do relatively simple actions. This section
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    76
# contains the driving logic for the script, and all of the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    77
# manipulations of Mercurial
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    78
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    79
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    80
sub scm_usage();		# forward declarations
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    81
sub scm_options();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    82
sub scm_init($@);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    83
sub scm_checkout($);	# non-destructive, i.e. leave untouched any workspace files not managed in SCM
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    84
sub scm_checkin($$$$$$);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    85
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    86
sub Usage(;$)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    87
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    88
	my ($errmsg) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    89
	print "\nERROR: $errmsg\n" if (defined $errmsg);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    90
	scm_usage();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    91
	print <<'EOF';
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    92
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    93
General options:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    94
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    95
-root rootdir       root of the Mercurial gateway repository
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    96
-v                  verbose
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    97
-h                  print this usage information
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    98
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    99
Setting up a new synchronisation:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   100
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   101
-clone remoterepo   clones gateway from remote repository 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   102
-branch hgbranch    Mercurial branch name (if needed)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   103
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   104
EOF
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   105
	exit 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   106
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   107
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   108
Usage() if !GetOptions(
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   109
	'root=s' => \$rootdir,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   110
	'h' => \$help,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   111
	'v' => \$verbose,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   112
	'debug' => \$debug,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   113
	'clone=s' => \$remoterepo,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   114
	'branch=s' => \$hgbranch,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   115
	scm_options()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   116
	);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   117
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   118
Usage() if ($help);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   119
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   120
Usage("Must specify root directory for Mercurial gateway") if (!defined $rootdir);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   121
Usage("-branch is only used with -clone") if (defined $hgbranch && !defined $remoterepo);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   122
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   123
if ($verbose)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   124
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   125
	my @hgversion = run_cmd("hg --version");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   126
	print @hgversion;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   127
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   128
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   129
# utility to return the heads descended from a particular point
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   130
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   131
sub hg_heads($)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   132
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   133
	my ($rev_on_branch) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   134
	my @heads = run_cmd("hg heads --template {rev}\\t{tags}\\n $rev_on_branch");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   135
	return @heads;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   136
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   137
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   138
# return an unsorted list of synchronisation points, identified by
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   139
# tags beginning with "sync_"
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   140
# 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   141
sub hg_syncpoints(;$)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   142
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   143
	my ($tip_rev) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   144
	my @tags = run_cmd("hg tags");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   145
	my @syncpoints;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   146
	foreach my $tag (@tags)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   147
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   148
		if ($tag =~ /^tip\s+(\d+):\S+$/)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   149
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   150
			$$tip_rev = $1 if (defined $tip_rev);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   151
			next;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   152
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   153
		if ($tag =~ /^$sync_prefix(.*\S)\s+\S+$/)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   154
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   155
			push @syncpoints, $1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   156
			next
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   157
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   158
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   159
	if ($debug)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   160
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   161
		printf "Found %d syncpoints in %d tags:", scalar @syncpoints, scalar @tags;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   162
		print join("\n * ", "",@syncpoints), "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   163
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   164
	return @syncpoints;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   165
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   166
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   167
my $hg_updated = 0;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   168
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   169
# Update the Mercurial workspace to a given sync point
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   170
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   171
sub hg_checkout($)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   172
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   173
	my ($scmref) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   174
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   175
	my $tag = $sync_prefix.$scmref;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   176
	my @output = run_cmd("hg update --clean --rev $tag", "^abort:");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   177
	$hg_updated = 1;	# could check the output in case it didn't change anything
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   178
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   179
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   180
# 0. Create the gateway repository, if -clone is specified
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   181
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   182
if (defined $remoterepo)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   183
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   184
	Usage("Cannot create gateway because $rootdir already exists") if (-d $rootdir);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   185
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   186
	my $clonecmd = "clone";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   187
	$clonecmd .= " --rev $hgbranch" if (defined $hgbranch);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   188
	my @output = run_cmd("hg $clonecmd $remoterepo $rootdir");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   189
	$hg_updated = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   190
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   191
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   192
chdir $rootdir;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   193
Usage("$rootdir is not a Mercurial repository") if (!-d ".hg");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   194
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   195
my $something_to_push = 0;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   196
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   197
# 1. Prime the SCM system, and get the ordered list of changes available to 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   198
# convert into Mercurial commits
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   199
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   200
my $first_sync;		# is this the first synchronisation?
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   201
my $scm_tip_only;	# can we process a series of changes in the SCM system?
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   202
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   203
my $tip_rev = -1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   204
my @syncpoints = hg_syncpoints(\$tip_rev);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   205
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   206
if (scalar @syncpoints != 0)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   207
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   208
	$first_sync = 0;	# no - it's already synchronised
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   209
	$scm_tip_only = 0;	# so can allow sequence of SCM changes
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   210
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   211
else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   212
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   213
	print "First synchronisation through this gateway\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   214
 	$first_sync = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   215
	if ($tip_rev != -1)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   216
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   217
 		$scm_tip_only = 1;	# because there's already something in the repository
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   218
 		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   219
 	else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   220
 		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   221
		print "Mercurial repository is empty\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   222
		$scm_tip_only = 0;	# allow multiple SCM changes, because there's nothing to merge with
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   223
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   224
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   225
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   226
my $opening_scmtag;	# ancestor by which we judge the headcount of the result
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   227
my $latest_scmtag;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   228
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   229
my @scmrefs = scm_init($scm_tip_only, @syncpoints);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   230
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   231
if (scalar @scmrefs == 0)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   232
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   233
	print "No changes to process in local SCM\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   234
	$opening_scmtag = $tip_rev;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   235
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   236
else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   237
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   238
	$opening_scmtag = $sync_prefix.$scmrefs[0];
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   239
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   240
$latest_scmtag = $opening_scmtag;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   241
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   242
if ($scm_tip_only && scalar @scmrefs > 1)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   243
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   244
	print "ERROR - cannot handle multiple SCM changes in this situation\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   245
	exit(1);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   246
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   247
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   248
# 2. Process the SCM changes, turning them into Mercurial commits and marking with tags
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   249
# - we guarantee that there is at most one change, if this is the first synchronisation
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   250
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   251
foreach my $scmref (@scmrefs)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   252
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   253
	my ($user,$date,@description) = scm_checkout($scmref);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   254
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   255
	# commit the result
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   256
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   257
	my ($fh,$filename) = tempfile();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   258
	print $fh join("\n",@description), "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   259
	close $fh;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   260
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   261
	run_cmd("hg commit --addremove --date \"$date\" --user \"$user\" --logfile  $filename", "^abort\:");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   262
	$something_to_push = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   263
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   264
	unlink($filename);	# remove temporary file
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   265
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   266
	my $tag = $sync_prefix.$scmref;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   267
	run_cmd("hg tag --local $tag");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   268
	$latest_scmtag = $tag;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   269
	print "Synchronised $scmref into Mercurial gateway repository\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   270
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   271
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   272
# 3. Put the full Mercurial state into the SCM, if this is the first synchronisation
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   273
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   274
if ($first_sync)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   275
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   276
	my @traceback = run_cmd("hg log --limit 1 --template {rev}\\t{node}\\t{tags}\\n");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   277
	my $line = shift @traceback;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   278
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   279
	chomp $line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   280
	my ($rev,$node,$tags) = split /\t/,$line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   281
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   282
	if ($rev != 0)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   283
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   284
		# repository was not empty, so need to commit the current state back into Perforce
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   285
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   286
		my @description = run_cmd("hg log --rev $rev --template \"{author}\\n{date|isodate}\\n{desc}\"");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   287
		chomp @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   288
		my $author = shift @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   289
		my $date = shift @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   290
		my @changes = run_cmd("hg status --clean");	# include info on unmodified files
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   291
		@changes = sort @changes;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   292
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   293
		# Deliver changes to SCM
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   294
		my $scmref = scm_checkin($node,$author,$date,\@changes,\@description,$tags);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   295
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   296
		my $tag = $sync_prefix.$scmref;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   297
		run_cmd("hg tag --local $tag");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   298
		$latest_scmtag = $tag;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   299
		print "Synchronised $scmref from Mercurial gateway, to initialise the synchronisation\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   300
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   301
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   302
	$opening_scmtag = $latest_scmtag;	# don't consider history before this point
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   303
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   304
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   305
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   306
# 3. pull from Mercurial default path, deal with new stuff
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   307
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   308
my @pull_output = run_cmd("hg pull --update");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   309
$hg_updated = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   310
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   311
my @heads = hg_heads($opening_scmtag);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   312
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   313
if (scalar @heads > 1)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   314
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   315
	# more than one head - try a safe merge
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   316
	print "WARNING: multiple heads\n",@heads,"\nMerge is needed\n\n\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   317
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   318
	my @merge_output = run_cmd("hg --config \"ui.merge=internal:fail\" merge");	# which head?
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   319
	if ($merge_output[0] =~ / 0 files unresolved/)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   320
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   321
		# successful merge - commit it.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   322
		run_cmd("hg commit --message \"Automatic merge\"");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   323
		$something_to_push = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   324
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   325
	else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   326
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   327
		# clean up any partially merged files
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   328
		run_cmd("hg update -C");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   329
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   330
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   331
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   332
# 4. Identify the sequence of Mercurial changes on the trunk and put them into the SCM
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   333
# - Do only the head revision if this is the first synchronisation, to avoid copying ancient history
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   334
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   335
my $options = "--follow-first";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   336
$options .= " --prune $latest_scmtag";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   337
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   338
my @traceback = run_cmd("hg log $options --template {rev}\\t{node}\\t{tags}\\n");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   339
foreach my $line (reverse @traceback)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   340
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   341
	chomp $line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   342
	my ($rev,$node,$tags) = split /\t/,$line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   343
	if ($tags =~ /$sync_prefix/)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   344
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   345
		# shouldn't happen - it would mean that tip goes back to an ancestor
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   346
		# of the latest sync point
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   347
		abandon_sync("Cannot handle this structure\n",@traceback);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   348
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   349
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   350
	# Read commit information and update workspace from Mercurial
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   351
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   352
	my @description = run_cmd("hg log --rev $rev --template \"{author}\\n{date|isodate}\\n{desc}\"");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   353
	chomp @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   354
	my $author = shift @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   355
	my $date = shift @description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   356
	my @changes = run_cmd("hg status --rev $latest_scmtag --rev $rev");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   357
	@changes = sort @changes;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   358
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   359
	run_cmd("hg update -C --rev $rev");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   360
	$hg_updated = 1;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   361
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   362
	# Deliver changes to SCM
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   363
	my $scmref = scm_checkin($node,$author,$date,\@changes,\@description,$tags);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   364
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   365
	# Tag as the latest sync point
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   366
	my $tag = $sync_prefix.$scmref;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   367
	run_cmd("hg tag --local $tag");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   368
	$latest_scmtag = $tag;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   369
	print "Synchronised $scmref from Mercurial gateway\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   370
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   371
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   372
# 3. push changes to the destination gateway
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   373
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   374
if ($something_to_push)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   375
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   376
	my @output = run_cmd("hg -v push --force --rev $latest_scmtag");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   377
	print "\n",@output,"\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   378
	print "Destination Mercurial repository has been updated\n"; 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   379
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   380
else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   381
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   382
	print "Nothing to push to destination Mercurial repository\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   383
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   384
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   385
# 4. Check to see if we are in a clean state
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   386
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   387
@heads = hg_heads($opening_scmtag);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   388
if (scalar @heads > 1)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   389
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   390
	print "\n------------------\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   391
	print "WARNING: Mercurial repository has multiple heads - manual merge recommended\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   392
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   393
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   394
exit(0);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   395
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   396
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   397
# -------------- SCM section -------------
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   398
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   399
# Code relating to non-Mercurial SCM system.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   400
# This version implements the sync with XXX
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   401
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   402
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   403
# Utility functions you might want to call are:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   404
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   405
# run_cmd($cmd)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   406
# - Function which runs the specified command in a subshell and returns the stdout output as a list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   407
#   of strings. The whole script will terminate if the command returns with a non-zero exit status.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   408
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   409
# abandon_sync(@messagelines)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   410
# - Terminate the synchronisation script and pass on the message to someone who might care...
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   411
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   412
# $hg_updated
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   413
# - Global variable set to 1 if Mercurial changes the content of the workspace. This can be used to
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   414
#   optimise the XXX system processing during initialisation, because it indicates when the workspace
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   415
#   can be considered "clean" by the XXX system. Should be set to 0 whenever the XXX system knows the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   416
#   state of the workspace.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   417
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   418
# hg_checkout($scmref)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   419
# - Function to call "hg update" to the sync label associated with $scmref. Used during the scm_init
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   420
#   function as part of getting the workspaces in harmony before transferring changes. Will set
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   421
#   $hg_updated to 1.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   422
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   423
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   424
# scm_usage()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   425
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   426
# This function is called to supply the main "usage" statement for the script, as the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   427
# interesting description is all about the interaction between Mercurial and XXX. It takes no
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   428
# arguments and should return nothing.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   429
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   430
sub scm_usage()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   431
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   432
	print <<'EOF';
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   433
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   434
perl sync_hg_xxx.pl -root rootdir [options]
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   435
version 0.7
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   436
 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   437
Synchronise a branch in XXX with a branch in Mercurial.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   438
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   439
The branch starts at rootdir, which is a local Mercurial repository.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   440
The Perforce clientspec is assumed to exist, to specify modtime & rmdir, 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   441
and to exclude the .hg directory from the rootdir.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   442
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   443
The tool will sync rootdir/... to the specified changelist, and
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   444
then reflect all changes affecting this part of the directory tree into
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   445
Mercurial.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   446
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   447
The -first option is used to specify the first sync point if the gateway
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   448
has not been previously synchronised, e.g. when -clone is specified.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   449
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   450
Perforce-related options:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   451
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   452
-m maxchangelist    highest changelist to consider
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   453
                    defaults to #head
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   454
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   455
EOF
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   456
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   457
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   458
my $max_changelist;			# put XXX-specific global variables here
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   459
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   460
sub scm_options()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   461
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   462
	# set defaults
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   463
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   464
	$max_changelist = "#head";		# initialise the XXX global variables here, otherwise it doesn't happen
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   465
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   466
	# return the GetOpt specification
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   467
	return (
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   468
		'm|max=s' => \$max_changelist,		# add your own bits of GetOpt arguments
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   469
		);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   470
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   471
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   472
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   473
# scm_init ($tip_only, @syncpoints)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   474
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   475
# The main code calls this routine once, passing two arguments, and expects to get a 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   476
# list of identifiers to XXX changes which could be synchronised as individual Mercurial
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   477
# commits. These references can be anything which can be used as part of a Mercurial tag name,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   478
# and the main code will call back into this routine supplying the references one at a time
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   479
# in the list order.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   480
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   481
# If $tip_only is true, then the synchronisation can only handle the most recent version
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   482
# of the code in the XXX system, and will not be able to sync intermediate steps. This usually
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   483
# means that this is the first synchronisation of this branch with Mercurial. At most one identifier
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   484
# should be returned.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   485
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   486
# @syncpoints contains a list of identifiers extracted from the local sync_* tags which mark a change
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   487
# that was synchronised with Mercurial in some previous run. This information allows the XXX system
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   488
# to ignore changes which have previously been processed, and to set itself into a state where
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   489
# the workspace corresponds to the contents of the XXX system at that point.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   490
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   491
# The function returns the list of change identifiers for changes to be taken out of XXX and applied
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   492
# to Mercurial. This list can be empty if there are no new changes since the last synchronisation point,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   493
# or if there is no content in the branch.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   494
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   495
sub scm_init($@)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   496
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   497
	my ($tip_only, @syncpoints) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   498
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   499
	my $first_changelist;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   500
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   501
	if ($tip_only)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   502
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   503
		# Script says we must synchronise from the XXX tip revision
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   504
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   505
		# Find the first changelist
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   506
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   507
		if (!defined $first_changelist)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   508
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   509
			print "XXX branch contains no changes\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   510
			return ();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   511
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   512
		print "Synchronisation from tip ($first_changelist)\n" if ($verbose);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   513
		# fall through to complete the initialisation
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   514
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   515
	else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   516
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   517
		# deduce the last synchronisation point from the @syncpoints list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   518
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   519
		$first_changelist = some_function_of(@syncpoints);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   520
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   521
		# Get Mercurial & XXX into the synchronised state
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   522
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   523
		hg_checkout($first_changelist);		# call back to Mercurial to update from hg repository
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   524
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   525
		# get XXX into state associated with $first_changelist
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   526
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   527
		## NB this is a bit Perforce specific - you might prefer to separate tip_only processing
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   528
		## from the normal "changes since last synchronisation" processing
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   529
		##
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   530
		$first_changelist += 1;		# we've already synched that one
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   531
		##
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   532
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   533
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   534
	# enumerate the changelists available from the XXX system & return as an ordered list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   535
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   536
	my @scmrefs = some_function($first_changelist);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   537
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   538
	if ($verbose)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   539
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   540
		printf "Found %d new changelists to process\n", scalar @scmrefs;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   541
		print join(", ", @scmrefs), "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   542
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   543
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   544
	return @scmrefs;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   545
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   546
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   547
# scm_checkout($scmref)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   548
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   549
# Update the workspace to reflect the given SCM reference
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   550
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   551
# This update should not change files which are not currently managed by the XXX system, but
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   552
# should delete workspace files if the XX change involved deleting files. It is useful, but not essential,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   553
# for empty directories to be removed if they become empty due to deletions recorded in the XXX change.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   554
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   555
# The function returns a list containing three things:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   556
# 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   557
# $change_user - the username to be recorded for the Mercurial commit
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   558
# $change_date - the date to be recorded for the Mercurial commit (yyyy-mm-dd hh:mm:ss format)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   559
# @change_description - the commit message to be used in Mercurial, as a list of lines of text
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   560
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   561
# The lines in the change description should not contain end of line markers, as these will be supplied
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   562
# by the main code.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   563
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   564
sub scm_checkout($)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   565
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   566
	my ($scmref) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   567
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   568
	my @change_description;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   569
	my $change_date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   570
	my $change_user;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   571
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   572
	# obtain the user , date and description for the given change identifier
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   573
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   574
	# apply the change to the workspace, ready for Mercurial to deduce with "hg commit --addremove"
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   575
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   576
	return ($change_user,$change_date,@change_description);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   577
	}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   578
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   579
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   580
# scm_checkin($hgnode,$author,$date,$changes,$description,$tags)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   581
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   582
# Describe the changes to the workspace as an SCM change, and return the new identifier (for use in a tag)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   583
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   584
# The function receives 6 parameters, all of which are associated with the Mercurial commit
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   585
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   586
# $hgnode      - Mercurial commit reference, as a globally unique hexadecimal identifier
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   587
# $author      - the author recorded in the commit
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   588
# $date        - the date recorded in the commit, in ISO date format (yyyy-mm-dd hh:mm:ss)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   589
# $changes     - Perl reference to the list of file changes (more information below)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   590
# $description - Perl reference to the list of lines in the commit message
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   591
# $tags        - Perl reference to the list of (non-local) tags associated with this commit
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   592
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   593
# The changes come from the Mercurial "hg status" command, and consist of a filename relative to the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   594
# root of the repository, prefixed by a single letter code and a space. The codes that this routine
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   595
# must handle are M = modify, R = remove, A = add, and C = clean. The C codes are only used for the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   596
# first synchronisation, and so should be handled as "add if not already in XXX". All of the implied 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   597
# changes have already been applied to the files in the workspace - the R files have been deleted, 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   598
# the A files have been added and the M files contain the desired content.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   599
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   600
# The $hgnode should be recorded in the description in the XXX system, as should the $author and $date if
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   601
# they can't be used directly. 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   602
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   603
# The function returns the identifier for the completed change, which will be tagged in the Mercurial
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   604
# repository and reported to scm_init() in future synchronisation runs.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   605
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   606
# WARNING: The tag information isn't currently filtered properly, and it is likely that there will
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   607
# need to be a separate scm_tag() function to handle the important Mercurial tags explicitly. Don't try
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   608
# to do much with the tag information just yet.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   609
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   610
sub scm_checkin($$$$$$)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   611
	{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   612
	my ($hgnode,$author,$date,$changes,$description,$tags) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   613
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   614
	my @hg_tags = grep !/^tip$/, split /\s+/, $tags;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   615
	my @xxx_modify;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   616
	my @xxx_remove;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   617
	my @xxx_add;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   618
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   619
	# Separate the changes into lists of files for modify/add/remove
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   620
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   621
	foreach my $line (@$changes)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   622
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   623
		my $type = substr($line,0,2,"");	# removes type as well as extracting it
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   624
		if ($type eq "M ")
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   625
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   626
			push @xxx_modify, $line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   627
			next;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   628
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   629
		if ($type eq "A " || $type eq "C ")
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   630
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   631
			push @xxx_add, $line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   632
			next;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   633
			}		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   634
		if ($type eq "R ")
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   635
			{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   636
			push @xxx_remove, $line;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   637
			next;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   638
			}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   639
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   640
		abandon_sync("Unexpected hg status line: $type$line");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   641
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   642
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   643
	# Create an XXX system change object to record the changes (if necessary)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   644
	# process the lists of files
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   645
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   646
	if (scalar @xxx_add)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   647
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   648
		# add the files in the xxx_add list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   649
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   650
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   651
	if (scalar @xxx_modify)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   652
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   653
		# process the list of modified files
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   654
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   655
		
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   656
	if (scalar @xxx_remove)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   657
		{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   658
		# remove the files in the xxx_remove list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   659
		}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   660
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   661
	# Create the change description from the @$description list
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   662
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   663
	# Include the $hgnode as part of the description
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   664
	# Use the $author and $date if possible (by might just have to be more descriptive text
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   665
	# TODO: Do something with the interesting tags?
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   666
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   667
	my $scmref = some_function();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   668
	
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   669
	return $scmref;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   670
	}