Merges versions of a text-file element or a directory
ClearCase (cleartool subcommand), Attache (command)
The merge command calls an element-type-specific program (the merge method) to merge the contents of two or more files, or two or more directories. Typically the files are versions of the same file element. A directory merge must involve versions of the same directory element.
When used to merge directory versions in a snapshot view, this command also updates the directory (and subdirectories, if necessary). (See update.)
You can also perform a subtractive merge, which removes from a version the changes made in one or more of its predecessors.
merge uses ClearCase's type manager mechanism to select a merge method. For details, see the type_manager reference page. merge methods are supplied only for certain element types.
This command merges the contents of two or more files, or two or more directories. Typically the files are versions of the same file element. A directory merge must involve versions of the same directory element.
merge presumes that all files are text files, using the built-in textual diff and merge, and bypassing the ClearCase type manager mechanism. Any missing file contributors are downloaded temporarily to the workspace. For a directory merge, the text file encodings of the directories are downloaded. If the merge is successful and should have a merge hyperlink created, a remote merge -ndata command is issued to create the hyperlink. The merged result is not uploaded to the view until a checkin or put of the result occurs. Local directories are not updated after a directory merge; you must issue get commands to update merged directories.
You can also perform a subtractive merge, which removes from a version the changes made in one or more of its predecessors.
A merge is a straightforward extension of a file comparison. Instead of displaying the differences, the merge method (ClearCase) or merge (Attache) analyzes them (sometimes with your help) and copies sections of text to the output file:
------------[changed 3-4]----|--------[changed to 3-4 file 2]--- |
(In ClearCase, the -qall option turns off automatic acceptance of this kind of change.)
[changed 10] | [changed to 10 file 2]--- |
Be sure to verify that the changes you accept produce consistent merged output. For example, after performing a merge involving file util.c, you can compare files util.c.contrib (which contains its previous contents) and the new util.c (which contains the merge output).
If all the contributors are versions of the same element, merge determines the base contributor automatically. It examines the element's "merge-enhanced" version tree, which is the directed graph consisting of the actual version tree along with all the merge arrows created by previous merge operations. This examination reveals the relationships among versions from the standpoint of their contents (which versions contributed their data to me?), rather than from the standpoint of their creation order (which versions were created before me?). merge selects the closest common ancestor in this enhanced version tree as the base contributor.
If no merges have been performed in the element, the actual common ancestor (A) of the contributors (C) in the version tree is selected to be the base contributor. Figure 13 illustrates some common cases.
Figure 13 Determination of the Base Contributor for a Merge
If the contributors are not all versions of the same element, there is no base contributor. This means that you must resolve all discrepancies among the contributors. In ClearCase only, the -qall option is enabled automatically.
Under certain circumstances, cleartool or Attache records the merge by creating one or more merge arrows (hyperlinks of type Merge):
If all these conditions hold, cleartool or Attache draws an arrow from each contributor version (except the base contributor) to the target version.
In ClearCase, you can view merge arrows with the Version Tree Browser by clicking Versions ` Show version tree.
The find and lsvtree -merge commands can locate versions with Merge hyperlinks. The describe command lists all of a version's hyperlinks, including merge arrows:
cmd-context describe util.c@@\main\3
version "util.c@@\main\3"
.
.
.
Hyperlinks:
Merge@278@\vob_3 \vob_3\src\util.c@@\main\rel2_bugfix\1
-> \vob_3\src\util.c@@\main\3
Each version of a ClearCase directory element contains the names of certain file elements, directory elements, and VOB symbolic links. merge can process two or more versions of the same directory element, producing a directory version that reflects the contents of all the contributors. The algorithm is similar to that for a file merge: merge compares a base contributor (common ancestor) version with each other contributor, producing a set of differences. It applies these differences to the base contributor as automatically as possible, prompting for user interaction only when two or more of the contributors are in conflict. (See the diff reference page for more on this algorithm.)
One of the directory versions-the merge target, specified with the -to option-must be checked out. (Typically, it is the version in your view.) merge updates the checked-out directory by adding, removing, and changing names of elements and/or links.
NOTE: In ClearCase, a directory merge does not leave behind a .contrib file, with the premerge contents of the target version.
We recommend that you use this procedure when merging directories:
This procedure makes it easy to determine exactly what the merge accomplished: enter a diff -predecessor command on the checked-out version, which has just been updated by merge.
ClearCase and Attache implement directory merges using VOB hard links. You can use the ClearCase or Attache ln and rmname commands to perform full or partial merges manually. See the ln and rmname reference pages for details.
This section presents common scenarios for performing merges. See also EXAMPLES.
A common use of this command is to combine the changes made on a subbranch (for example, a bugfix branch) of a file element with changes made on the main branch. Figure 14 shows such a merge.
The target is C1, the checked-out version on the main branch, and the other contributor is C2, the latest version on a bugfix branch. cleartool or Attache determines that version B is the common ancestor, to be used as the base file. The merged result replaces the contents of the target, C1.
Figure 14 Merging from a Branch
Another common use of this command arises from the unreserved checkout capability: you perform an unreserved checkout and edit the file, but someone else checks in a successor version ahead of you. You can check in your work only if you first merge with the version that was already checked in.
Figure 15 shows a merge in which the target is C1, an unreserved, checked-out version. The other contributor is C2, the version that was checked before C1. cleartool or Attache determines that version B is the common ancestor, to be used as the base file. The result of the merge replaces the contents of the target, C1. cleartool or Attache allows C1 to be checked in when it sees the merge arrow from C2 to C1.
Figure 15 Merging into an Unreserved Checkout
merge has options that invoke special kinds of merges: selective and subtractive.
By default, merge takes into account an entire, cumulative sequence of changes. For example, a merge from version\main\bugfix\4 to the main branch involves the changes made in version 3, and also the changes made in versions 2 and 1 on that branch. In some cases, however, you may want to incorporate only the changes made in one specific version (or a range of versions), disregarding the changes made in its predecessors. The -insert option implements a selective merge capability, as illustrated in Figure 16. In each merge, the shaded versions are the ones whose changes are merged to the main branch. (The commands in the following examples are wrapped to conserve space. Enter commands on a single line.)
In a selective merge, no merge arrow is created; ClearCase uses merge arrows to indicate that all of a version's data has been merged.
The -delete option invokes a subtractive merge, which is the opposite of a selective merge:
For example, to undo the changes made in versions 5 - 9 of file foo.c, while retaining all the changes made before version 5 and after version 9, you can issue this command:
cmd-context merge -to foo.c -delete -ver \main\5 \main\9 (ClearCase only)
cmd-context merge -abort -to foo.c -delete -ver \main\5 \main\9 (Attache only)
Permissions Checking: Special permissions apply for creation of a merge arrow only. For each object processed, you must be one of the following: element group member, element owner, VOB owner, member of the ClearCase group. See the permissions reference page.
Locks: An error occurs if any of the following objects are locked: VOB, element type, element, branch type, branch, hyperlink type.
DESTINATION OF MERGE OUTPUT. Default: None.
| |
cleartool: Error: ... | |
|
PERFORMING A GRAPHICAL MERGE. Default: Performs the merge in the command window and uses the default display font.
INTERACTIVE MERGES NOT SUPPORTED IN ATTACHE. You must specify -ndata or -abort from below.
OUTPUT FORMAT. Default: Displays output in the format described in the diff reference page.
SPECIFYING THE BASE CONTRIBUTOR. Default: Uses the procedure described in Determination of the Base Contributor.
SPECIFYING SPECIAL MERGES. Default: A standard merge is performed: all the differences between the base contributor and each non-base contributor are taken into account.
SUPPRESSING PARTS OF THE MERGE PROCESS. Default: merge stores its results in the workspace location specified by -to or -out; with -to, it also creates merge arrows.
REPLACING A PREVIOUS MERGE. Default: An error occurs if a merge arrow is already attached to any version where merge would create one.
CONTROLLING USER INTERACTION. Default: Works as automatically as possible, prompting you to make a choice only when two or more non-base contributors differ from the base contributor.
NOTE: In Attache, the -query and -qall options are available only when performing a graphical merge (-graphical).
SPECIFYING A COMMENT FOR THE MERGE ARROW. Default: Attaches a comment to each merge arrow (hyperlink of type Merge) with commenting controlled by your .clearcase_profile file (default: -nc). See CUSTOMIZING COMMENT HANDLING in the comments reference page. Comments can be edited with chevent.
PASSING THROUGH OPTIONS TO THE 'MERGE' METHOD. Default: Does not pass any special options to the underlying merge method (in ClearCase, implemented by the cleardiff utility for all predefined element types).
-hea·ders_only | |
-headers_only lists only the header line of each difference. The -quiet suppresses the file summary from the beginning of the report. | |
-b·lank_ignore | |
Ignores extra white space characters in text lines: leading and trailing white space is ignored; internal runs of white space are treated like a single SPACE character. | |
-vst·ack | |
-vst·ack stacks the difference panes vertically, with the base contributor at the top. | |
SPECIFYING THE DATA TO BE MERGED. Default: None.
Examples including wildcards or quoting are written for use in cleartool interactive mode. If you use cleartool single-command mode, you may need to change the wildcards and quoting to make your command interpreter process the command appropriately.
In cleartool single-command mode, cmd-context represents the command interpreter prompt. In cleartool interactive mode, cmd-context represents the interactive cleartool prompt. In Attache, cmd-context represents the workspace prompt.
cmd-context merge -to util.c -narrows -version \main\rel2_bugfix\LATEST ^
\main\test\LATEST (ClearCase only)
cmd-context merge -to util.c -abort -narrows -version \main\rel2_bugfix\LATEST \main\test\LATEST (Attache only/this command must be entered on a single line)
cmd-context merge -out \tmp\proj.out util.c@@\main\3 \jk_fix\users_hw\src\util.c
cmd-context merge -abort -out /tmp/proj.out util.c@@\main\3 util.c
cmd-context merge -to util.c -abort -delete -version util.c@@\main\3
cmd-context merge -to util.c -graphical -version \main\rel2_bugfix\LATEST
describe, diff, find, findmerge, rmmerge, update
|
Feedback on the documentation in this site? We welcome any comments!
Copyright © 1999 by Rational Software Corporation. All rights reserved. |