Finally activate the skeleton of the ARexx port
[AROS.git] / scripts / merger.sh
blobe2f55e17de4a51b79359b89e1351f1916e9b0a18
1 #!/bin/sh
3 mydir=$1
4 olddir=$2
5 yourdir=$3
7 cp=cp
8 mkdirhier="mkdir -p"
9 #cp="echo cp"
10 #mkdirhier="echo mkdirhier"
12 export mydir olddir yourdir cp mkdirhier
14 rm -f conflicts.log added.log
16 # First try to merge all the changes from olddir to yourdir into mydir
17 # that means that only the files which are both in mydir, yourdir and olddir have to be processed
19 find $mydir -type f -exec sh -c \
20 'cur="`echo "{}" | cut -d/ -f2-`"; \
21 if [ -e $olddir/"$cur" ] && [ -e $yourdir/"$cur" ]; then \
22 echo processing "$cur"; \
23 merge -p $mydir/"$cur" $olddir/"$cur" $yourdir/"$cur" >merge.tmp; \
24 if [ $? -gt 0 ]; then \
25 echo "$cur" >> conflicts.log; \
26 fi; \
27 if ! cmp $mydir/"$cur" merge.tmp >/dev/null; then \
28 $cp merge.tmp $mydir/"$cur"; \
29 echo "$cur" has been updated; \
30 fi; \
31 fi' \
32 ';'
34 # Then copy all the files which are new into mydir. A file is "new" when it and all of its ancestors are
35 # not present in olddir nor in mydir. If a file is present in olddir but not in mydir it means that it's
36 # been removed and therefore doesn't have to be copied; if it's present both in mydir and olddir it means
37 # that if it needed to be modified it's already been modified by the previous part, therefore doesn't need to
38 # be copied either. All that means that if a file is present both in yourdir and olddir it doesn't need to be
39 # copied
41 find $yourdir -type f -exec sh -c \
42 'cur="`echo "{}" | cut -d/ -f2-`"; \
43 if ! [ -e $olddir/"$cur" ] && ! [ -e $mydir/"$cur" ] && \
44 ( \
45 count=1; \
46 oldcur2=""; \
47 while true; do \
48 cur2=`echo "$cur" | cut -d/ -f-$count`; \
49 if [ "$oldcur2" == "$cur2" ]; then \
50 exit 0; \
51 fi; \
52 if [ -e $olddir/"$cur2" ] && ! [ -e $mydir/"$cur2" ]; then \
53 exit 1; \
54 fi; \
55 oldcur2="$cur2"; \
56 count=$[$count + 1]; \
57 done \
58 ); then \
59 echo Adding "$cur"; \
60 dirname=`dirname "$cur"`; \
61 $mkdirhier $mydir/"$dirname"; \
62 $cp $yourdir/"$cur" $mydir/"$dirname"; \
63 echo "$cur" >> added.log; \
64 fi' \
65 ';'
67 echo Operation finished.
69 if [ -e conflicts.log ]; then \
70 echo There were `wc -l conflicts.log` conflicts. Have a look at conflicts.log to see in which files.; \
71 else \
72 echo There were no conflicts; \
75 if [ -e added.log ]; then \
76 echo `wc -l added.log` files have been added. Have a look at added.log to see which ones.; \
77 else \
78 echo No new files have been added; \