source: modipsl/trunk/util/correct-cvs-diff.awk @ 2296

Last change on this file since 2296 was 1582, checked in by mmaipsl, 12 years ago

CVS diff files for use with patch.

correct-cvs-diff.awk try to correct files PATH in diff lines inside wrong

command :
correct-cvs-diff.awk [-d] cvs-diff-file

  • Property svn:executable set to *
  • Property svn:keywords set to Date,Author,Revision
File size: 2.7 KB
Line 
1#!/usr/bin/awk -f
2
3# correct-cvs-diff.awk try to correct files PATH in diff lines inside wrong
4# CVS diff files for use with patch.
5# CVS diff give header like :
6#
7# Index: src/myfile.f90
8# ===================================================================
9# RCS file: ...DIR/src/myfile.f90,v
10# retrieving revision 1.8
11# diff -U 2 -r1.8 myfile.f90
12# --- src/myfile.f90    28 Jan 2009 08:32:45 -0000      1.8
13# +++ src/myfile.f90    7 Oct 2010 16:04:00 -0000
14#
15# But the diff line is wrong because the path for myfile is incomplete.
16# The patch will ask for the true path :
17#
18# can't find file to patch at input line 23
19# Perhaps you should have used the -p or --strip option?
20# The text leading up to this was:
21# --------------------------
22# |Index: src/myfile.f90
23# |===================================================================
24# |RCS file: ...DIR/src/myfile.f90,v
25# |retrieving revision 1.8
26# |diff -r1.8 myfile.f90
27# --------------------------
28# File to patch:
29#
30# This script will correct the diff file by adding the minimal true PATH :
31# diff -U 2 -r1.8 src/myfile.f90
32#
33# command :
34# correct-cvs-diff.awk [-d] cvs-diff-file
35
36#**************************************************************
37# Author: Martial.Mancip
38# Contact: Martial.Mancip_ipsl.jussieu.fr
39# $Date:
40# $Author: $
41# $Revision: $
42# IPSL (2006)
43#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
44# History:
45# Modification:
46#
47#**************************************************************
48
49#==========================
50function myprint(str) {
51  if (debug) {
52     print str
53  }
54}
55
56
57#==========================
58BEGIN {
59#  print "traitement de " ARGV[1]
60
61  nbarg=ARGC
62
63  if (ARGV[1] == "-d") {
64    debug=1
65    file=ARGV[2]
66    delete ARGV[1] 
67    nbarg--
68  } else {
69    debug=0
70    file=ARGV[1]
71  }
72
73  exit_value=0
74  if (nbarg != 2) {
75        print "Usage: correct-cvs-diff.awk [-d] cvs-diff-file"
76        exit_value=-1
77        exit
78  }
79   
80  index_found=0
81  counter=0
82  errcounter=0
83  errorfile[1]=""
84}
85
86#==========================
87{
88
89  myprint($0) 
90
91  if (index_found == 0 && match($0, "Index:.*")) {
92    index_found=1
93    counter=counter+1
94
95    nb=split($0,index_line, " ")
96    myprint("Index " counter " found with nb : " nb)
97    for (elt in index_line) {
98        myprint("index " elt "- elt  :" index_line[elt])
99    }
100    myprint("Index_path : " index_line[2])
101    print $0
102  }
103  else if (index_found == 1 && match($0, "diff .*")) {
104    myprint("diff found")
105    index_found=0
106
107    nb=split($0,diff_line, " ")
108    myprint("nb  :" nb)
109    for (elt in diff_line) {
110        myprint("diff " elt "- elt  :" diff_line[elt])
111    }
112    myprint("diff_path : " diff_line[nb])
113
114    diff_line[nb]=index_line[2]
115    i=1
116    while (i <= nb) {
117        printf("%s ",diff_line[i])
118        i=i+1
119    }
120    printf("\n")
121  }
122  else {
123    print $0
124  }
125}
Note: See TracBrowser for help on using the repository browser.