On Sun, 5 Oct 2003 01:46:40 +0200
Felix K�hling <[EMAIL PROTECTED]> wrote:

[snip]
> > The -kk didn't seem to help at all (cvs up -kk -d -j HEAD).  I still got
> > "C " in 537 files.
> 
> Same problems here. I'm trying to merge the trunk to the config branch.
> It is strange that cvs even attempts to merge files that I never
> committed any new revisions for on the branch. I also checked that I
> don't have any accidental local changes before I started. On some (many)
> of the files that I didn't change rcsmerge reports conflicts. I don't
> know what's going on. Is it a problem with my client or with the server?
> I can't imagine that this is normal CVS operation :-/ The fact that
> we're both having the same problems would point to the server.
> 
> I'm working on a TCL script that "resolves" conflicts automatically. It
> just copies the new versions and discards the old ones. To be used on
> directories that you are sure were not changed on the branch.
> 
> > 
> > -- 
> > Eric Anholt                                [EMAIL PROTECTED]          
> > http://people.freebsd.org/~anholt/         [EMAIL PROTECTED]
> > 
> 
> Felix

Ok, the script is ready and seems to be working. It uses CVS/Entries
files in order to traverse the working copy recursively considering only
files that are in CVS. I don't have time to resolve my conflicts now.
Anyway, maybe you want to try the script first ;-). The best procedure
is probably to resolve the real conflicts and then have the script
"resolve" the rest.

BTW, 'grep -rlI "<<<<<<<" *' gives me a count of 692 files with
conflicts :-/

Regards,
  Felix

------------    __\|/__    ___     ___       -------------------------
 Felix       ___\_e -_/___/ __\___/ __\_____   You can do anything,
   K�hling  (_____\�/____/ /_____/ /________)  just not everything
 [EMAIL PROTECTED]       \___/   \___/   U        at the same time.
#!/usr/bin/tclsh

proc resolveFile {filename} {
    set result [catch {
	set infile [open $filename "r"]
    } message]
    if {$result != 0} {
	puts stderr "Can't open $filename for reading: $message"
	return
    }
    set tmpname "$filename.~tmp_resolve~"
    set result [catch {
	set outfile [open $tmpname "w"]
    } message]
    if {$result != 0} {
	puts stderr "Can't open $tmpname for writing: $message"
	close $infile
	return
    }

    set nConflicts 0
    # states:
    # 0: normal text (copy)
    # 1: local (discard)
    # 2: new (copy)
    # 3: error (skip the whole file)
    set state 0
    while {![eof $infile]} {
	set count [gets $infile line]
	if {$count == 0 && [eof $infile]} {
	    break
	}
	if {[string match "<<<<<<< *" "$line"]} {
	    if {$state == 0} {
		set state 1
		continue
	    } else {
		puts stderr "$filename: Error: unexpected line: $line"
		set state 3
		break
	    }
	} elseif {[string match "=======" "$line"]} {
	    if {$state == 1} {
		set state 2
		continue
	    } else {
		puts stderr "$filename: Error: unexpected line: $line"
		set state 3
		break
	    }
	} elseif {[string match ">>>>>>> *" "$line"]} {
	    if {$state == 2} {
		set state 0
		incr nConflicts
		continue
	    } else {
		puts stderr "$filename: Error: unexpected line: $line"
		set state 3
		break
	    }
	}
	if {$state != 1} {
	    if {[eof $infile]} {
		puts -nonewline $outfile "$line"
		break
	    } else {
		puts $outfile "$line"
	    }
	}
    }

    close $infile
    close $outfile

    if {$state != 0 && $state != 3} {
	puts stderr "$filename: Error: there were unmatched conflict markers."
	set state 3
    }
    if {$state == 3} {
	puts stderr "$filename: Incomplete resolution left in $tmpname."
	return
    }

    if {$nConflicts > 0} {
	puts stderr "$filename: Resolved $nConflicts conflicts."
	file rename -force -- $tmpname $filename
    } else {
	file delete $tmpname
    }
}

proc resolveDir {dir} {
    if {[file exists "$dir/CVS/Entries"]} {
	set result [catch {
	    set entries [open "$dir/CVS/Entries" "r"]
	} message]
	if {$result != 0} {
	    puts stderr "Can't open $dir/CVS/Entries: $message"
	    return
	}
	while {![eof $entries]} {
	    set origEntry [gets $entries]
	    set entry [split $origEntry "/"]
	    if {[lindex $entry 0] == "D"} {
		if {[lindex $entry 1] != ""} {
		    resolveDir $dir/[lindex $entry 1]
		}
	    } elseif {[lindex $entry 0] == ""} {
		if {[lindex $entry 1] != ""} {
		    resolveFile $dir/[lindex $entry 1]
		}
	    } else {
		puts stderr "Invalid entry: $origEntry"
	    }
	}
	close $entries
    }
}

resolveDir "."

Reply via email to