Removed /usr/local from CDPATH
[clearscm.git] / cc / bin_merge
1 #!ccperl
2 ################################################################################
3 #
4 # File:         bin_merge
5 # Description:  This script will perform a merge 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;
32
33 BEGIN {
34   # Set $lib_path
35   my $lib_path = $^O =~ /MSWin/ ? "\\\\brcm-irv\\dfs\\projects\\ccase\\SCM\\lib"
36                                 : "/projects/ccase/SCM/lib";
37
38   # Extract relative path and basename from script name.
39   $0 =~ /(.*)[\/\\](.*)/;
40
41   my $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
42   $me          = (!defined $2) ? $0  : $2;
43   $me          =~ s/\.pl$//;
44
45   # Remove .pl for Perl scripts that have that extension
46   $me         =~ s/\.pl$//;
47
48   # Add the appropriate path to our modules to @INC array.
49   unshift @INC, "$abs_path";
50   unshift @INC, $ENV {SITE_PERL_LIBPATH} if defined $ENV {SITE_PERL_LIBPATH};
51   unshift @INC, "$lib_path";
52 } # BEGIN
53
54 use BinMerge;
55 use Display;
56 use Logger;
57
58 sub Usage {
59   my $msg = shift;
60
61   display "ERROR: $msg\n" if defined $msg;
62
63   display "Usage: $me [-u] [-v] [-d] -branch <branch> -path <path(s)>
64
65 Where:
66
67   -u:           Display usage
68   -v:           Turn on verbose mode
69   -d:           Turn on debug mode
70   -branch       Branch to merge from
71   -path:        Path to consider (Default .)
72 ";
73   exit 1;
74 } # Usage
75
76
77 my $branch;
78 my $path        = ".";
79 my $verbose     = 0;
80 my $debug       = 0;
81
82 while ($ARGV [0]) {
83   if ($ARGV [0] eq "-v") {
84     $verbose = 1;
85   } elsif ($ARGV [0] eq "-d") {
86     $debug = 1;
87   } elsif ($ARGV [0] eq "-branch") {
88     shift;
89     if (!$ARGV [0]) {
90       Usage "Must specify <branch> after -branch";
91     } else {
92       $branch = $ARGV [0];
93     } # if
94   } elsif ($ARGV [0] eq "-path") {
95     shift;
96     if (!$ARGV [0]) {
97       Usage "Must specify <paths> after -path";
98     } else {
99       $path = join (" ", @ARGV);
100     } # if
101   } elsif ($ARGV [0] eq "-u") {
102     Usage;
103   } else {
104     Usage "Unknown argument found: " . $ARGV [0];
105   } # if
106
107   shift (@ARGV);
108 } # while
109
110 Usage "Must specify a branch" if !defined $branch;
111
112 Merge $branch, $path, $verbose, $debug;