dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / library / perforce / include / clientmerge.h
blob8f2ccf30e7ee7e68a367e9c5f6d976f20ad64aed
1 /*
2 * Copyright 1995, 1996 Perforce Software. All rights reserved.
4 * This file is part of Perforce - the FAST SCM System.
5 */
7 #ifndef __CLIENTMERGE__
8 #define __CLIENTMERGE__
11 * ClientMerge - client side merge controller
13 * ClientMerge
15 * A ClientMerge object handles the client-side merge process,
16 * taking the server-generated merge stream and writing out the
17 * base, yours, theirs, and merge files. A ClientMerge also has
18 * both a command line resolve implementation as well as hooks
19 * to allow other resolve implementations.
21 * ClientMerge is almost purely virtual, allowing for varying
22 * implementations that deal with the varying server-generated
23 * merge streams (basically 2 and 3 way merges).
25 * Half of ClientMerge's methods are for handling the server merge
26 * stream; the other half are for the user interface.
28 * Virtual member functions - Server merge stream handling
30 * ClientMerge::SetNames() - provides the user-recognisable names
31 * for the base, theirs, and yours.
33 * ClientMerge::SetShowAll() - turns on verbose merging.
35 * ClientMerge::Open() - state name of client file and prepare to
36 * process merge pipe.
38 * ClientMerge::Write() - write a block of the merge pipe. See
39 * diffmerge.h for the meaning of bits.
41 * ClientMerge::Close() - close file(s) at end of merge pipe.
43 * ClientMerge::Select() - move user-selected result into place
45 * ClientMerge::Chmod() - set permissions on the target file;
46 * generally, set to rw before and ro after.
48 * Virtual member functions - User interface hooks
50 * ClientMerge::AutoResolve() - take a guess at which version
51 * (theirs, yours, result) should be the result of the
52 * merge, using the chunk counts as hints.
54 * ClientMerge::Resolve() - let the user select which version
55 * should be the result of the merge.
57 * ClientMerge::IsAcceptable() - returns 1 if the result file
58 * has no merge markers (generated by the merge stream
59 * handler) left in it.
61 * ClientMerge::GetBaseFile()
62 * ClientMerge::GetYourFile()
63 * ClientMerge::GetTheirFile()
64 * ClientMerge::GetResultFile()
65 * Return a FileSys * to the desired file. 2 way merges
66 * return 0 for Base/Result files: only Yours/Theirs is
67 * available.
69 * ClientMerge::GetYourChunks()
70 * ClientMerge::GetTheirChunks()
71 * ClientMerge::GetBothChunks()
72 * ClientMerge::GetConflictChunks()
73 * Returns the number of chunks in the merge stream.
74 * 2 way merges return 0 for all.
76 * The actual caller of the ClientMerge class is in clientservice.cc.
77 * It uses the stream handling functions to produce 2 or 4 files on
78 * the client (yours/theirs, yours/theirs/base/result), and then calls
80 * MergeType ClientUser::Resolve( ClientMerge *merger )
82 * The default ClientUser::Resolve() merely calls merger->Resolve()
83 * to carry out the command-line resolve interaction, but a subclassed
84 * ClientUser::Resolve() can use the other merger methods to gain
85 * access to the files and performs its own resolve.
88 enum MergeType {
89 CMT_BINARY, // binary merge
90 CMT_3WAY, // 3-way text
91 CMT_2WAY // 2-way text
92 } ;
94 enum MergeStatus {
95 CMS_QUIT, // user wants to quit
96 CMS_SKIP, // skip the integration record
97 CMS_MERGED, // accepted merged theirs and yours
98 CMS_EDIT, // accepted edited merge
99 CMS_THEIRS, // accepted theirs
100 CMS_YOURS // accepted yours,
103 enum MergeForce {
104 CMF_AUTO, // don't force // -am
105 CMF_SAFE, // accept only non-conflicts // -as
106 CMF_FORCE // accept anything // -af
109 class ClientUser;
111 class ClientMerge : public LastChance {
113 public:
114 static ClientMerge *Create(
115 ClientUser *ui,
116 FileSysType type,
117 MergeType m );
119 virtual ~ClientMerge();
121 // User interface: AutoResolve is called if any of the -a flags
122 // are passed to 'p4 resolve'. Resolve() is used otherwise. The
123 // Resolve()'s often call AutoResolve() to provide the user with
124 // a default selection.
126 virtual MergeStatus AutoResolve( MergeForce forceMerge ) = 0;
127 virtual MergeStatus Resolve( Error *e ) = 0;
129 virtual int IsAcceptable() const = 0;
131 virtual FileSys *GetBaseFile() const = 0;
132 virtual FileSys *GetYourFile() const = 0;
133 virtual FileSys *GetTheirFile() const = 0;
134 virtual FileSys *GetResultFile() const = 0;
136 virtual int GetYourChunks() const = 0;
137 virtual int GetTheirChunks() const = 0;
138 virtual int GetBothChunks() const = 0;
139 virtual int GetConflictChunks() const = 0;
141 // Server merge stream handling
143 virtual void SetNames( StrPtr *b, StrPtr *t, StrPtr *y ) {};
144 virtual void CopyDigest( StrPtr *digest, Error *e ) {};
145 virtual void SetShowAll() {};
146 virtual void SetDiffFlags( const StrPtr *flags ) {};
148 virtual void Open( StrPtr *name, Error *e, CharSetCvt * = 0 ) = 0;
149 virtual void Write( StrPtr *buf, StrPtr *bits, Error *e ) = 0;
150 virtual void Close( Error *e ) = 0;
151 virtual void Select( MergeStatus stat, Error *e ) = 0;
152 virtual void Chmod( const_char *perms, Error *e ) = 0;
154 protected:
156 ClientUser *ui;
157 static const char *const confirm; // confirm overwrite
159 int Verify( const Error *message, Error *e );
163 # endif /* __CLIENTMERGE__ */