Removed /usr/local from CDPATH
[clearscm.git] / cc / bin_rebase
1 #!ccperl
2 ################################################################################
3 #
4 # File:         bin_rebase
5 # Description:  This script will perform a rebase checking for any merge
6 #               conflicts and grouping them at the end. This allows the
7 #               majority of a large merge to happen and the user can resolve
8 #               the conflicts at a later time.
9 #
10 #               This script also assists in performing binary merges for the
11 #               common case. With a binary merge one cannot easily merge the
12 #               binary code. Most often it's a sitatution where the user will
13 #               either accept the source or the destination binary file as
14 #               a whole. In cases where there is only a 2 way merge, this
15 #               script offers the user the choice to accept 1 binary file
16 #               or the other or to abort this binary merge. Binary merges
17 #               conflicts greater than 2 way are not handled.
18 #
19 # Author:       Andrew@DeFaria.com
20 # Created:      Thu Nov  3 10:55:51 PST 2005
21 # Language:     Perl
22 #
23 # (c) Copyright 2005, Andrew@DeFaria.com, all rights reserved
24 #
25 ################################################################################
26 use strict;
27 use warnings;
28 use Getopt::Long;
29 use File::Spec;
30
31 my ($me, $SEPARATOR, $NULL);
32
33 BEGIN {
34   my ($abs_path, $lib_path);
35
36   # Extract relative path and basename from script name.
37   $0 =~ /(.*)[\/\\](.*)/;
38
39   $abs_path   = (!defined $1) ? "." : File::Spec->rel2abs ($1);
40   $me         = (!defined $2) ? $0  : $2;
41   $me         =~ s/\.pl$//;
42
43   # Remove .pl for Perl scripts that have that extension
44   $me         =~ s/\.pl$//;
45
46   # Define the path SEPARATOR
47   $SEPARATOR  = ($^O =~ /MSWin/) ? "\\"  : "/";
48   $NULL       = ($^O =~ /MSWin/) ? "NUL" : "/dev/null";
49
50   # Setup paths
51   $lib_path   = "$abs_path" . $SEPARATOR . ".." . $SEPARATOR . "lib";
52
53   # Add the appropriate path to our modules to @INC array.
54   unshift (@INC, "$abs_path");
55   unshift (@INC, "$lib_path");
56 } # BEGIN
57
58 use BinMerge;
59 use Display;
60 use Logger;
61
62 sub Usage {
63   my $msg = shift;
64
65   display "ERROR: $msg\n" if defined $msg;
66
67   display "Usage: $me [-u] [-v] [-d] -view <viewtag>
68           { -recommended | -baseline <baseline> }
69
70 Where:
71
72   -u:           Display usage
73   -v:           Turn on verbose mode
74   -d:           Turn on debug mode
75   -recommended: Rebase from recommended baselines
76   -baseline:    Rebase from this baseline
77 ";
78   exit 1;
79 } # Usage
80
81 my $baseline;
82 my $verbose     = 0;
83 my $debug       = 0;
84
85 while ($ARGV [0]) {
86   if ($ARGV [0] eq "-v") {
87     $verbose = 1;
88   } elsif ($ARGV [0] eq "-d") {
89     $debug = 1;
90   } elsif ($ARGV [0] eq "-recommended") {
91     # Nothing to do, leave $baseline undefined
92   } elsif ($ARGV [0] eq "-baseline") {
93     shift;
94     if (!$ARGV [0]) {
95       Usage "Must specify <baseline> after -baseline";
96     } else {
97       $baseline = $ARGV [0];
98     } # if
99   } elsif ($ARGV [0] eq "-u") {
100     Usage;
101   } else {
102     Usage "Unknown argument found: " . $ARGV [0];
103   } # if
104
105   shift (@ARGV);
106 } # while
107
108 Rebase $baseline, $verbose, $debug;