ClientUser::Merge( FileSys *, FileSys *, FileSys *, FileSys *, Error * )

Call an external merge program to merge three files during resolve.

Virtual?

Yes

 

Class

ClientUser

 

Arguments

FileSys *base

the "base" file

 

FileSys *leg1

the "theirs" file

 

FileSys *leg2

the "yours" file

 

FileSys *result

the final output file

 

Error *e

an Error object

Returns

void

 

Notes

Merge() is called if the “m” option is selected during an interactive resolve. Merge() does not call the merge program; it merely invokes external merge programs (including P4Merge as well as third-party tools). External merge programs must be specified by an environment variable, either P4MERGE or MERGE. Merge() returns after the external merge program exits.

As in Diff(), the external program is invoked using ClientUser::RunCmd().

See also

ClientUser::RunCmd()

Example

When the "merge" option is selected during an interactive resolve, the file arguments to Merge() are as follows:

Argument Value

base

A temp file built from the depot revision that is the "base" of the resolve.

leg1

A temp file built from the depot revision that is the "theirs" of the resolve.

leg2

The local workspace file that is the "yours" of the resolve.

result

A temp file in which to construct the new revision of "yours".

These file arguments correspond exactly to the command-line arguments passed to the merge tool.

After you "accept" the merged file (with “ae”), the "result" temp file is copied into the “leg2” or "yours" workspace file, and this is the file that is submitted to the depot.

To change the way that external merge programs are called during a resolve, create a subclass of ClientUser with an alternate implementation of Merge().

For example, suppose that one of your favorite merge tools, “yourmerge”, requires the “result” file as the first argument. Rather than wrapping the call to the merge tool in a script and requiring your users to set P4MERGE to point to the script, you might want to provide support for this tool from within your application as follows:

void MyClientUser::Merge(
    FileSys *base,
    FileSys *leg1,
    FileSys *leg2,
    FileSys *result,
    Error *e )
{
    char *merger;

    if ( !( merger = enviro->Get( "P4MERGE" ) ) &&
         !( merger = getenv( "MERGE" ) ) )
    {
        e->Set( ErrClient::NoMerger );
        return;
    }

    if ( strcmp( merger, "yourmerge" ) == 0 )
    {
        RunCmd( merger, result->Name(), base->Name(),
                leg1->Name(), leg2->Name(), 0, e );
    }
    else
    {
        RunCmd( merger, base->Name(), leg1->Name(),
                leg2->Name(), result->Name(), 0, e );
    }
}