Is there an easy way to check in which file version the function has been modified in Clearcase? In my current environment I have file where the function is modified in some prior check-ins. On doing compare with previous version, it is not the one. So I have to go and compare with all previous check-ins to figure out in which version this has been modified. So is there an easy way to do it?
You can check the cleartool annotate function
The annotate command lists the contents of a version, annotating each line to indicate when, and in which version, the line was added. You can customize the annotations using the –fmt option, which is described in the fmt_ccase reference page.
By default, annotate writes its output to a file whose file-name extension is .ann.
You can find an example in this answer.
See also "How to use ClearCase annotate sub-command?".
Related
I want to get list of files and directories affected by specific commit. I have no problem getting the commit itself but I rather don't know how to get affected files and directories.
Just to make it clear I need something like this:
file x - deleted
file y - added
file z - modified
Git is snapshot-based; each commit includes a full list of files and their state. Any notion of "affected" files needs another commit to compare it to. This is commonly done against its parents, which seems to be what you're asking about. You can figure out which files are different between two commits (or more exactly, their trees) by using the git_diff family of functions.
You can find an example of doing so in the examples listing for libgit2. There is also a more general annotated diff example. The second link also shows how to list individual files as well as their contents, if you need that. Check the reference for a a full listing of available function to work with diffs.
Note that this won't give you affected directorires by itself, as Git does not track directories, but only files.
You're looking for git diff.
The same function exists in libgit2, and the documentation for it is here.
If you're analyzing older commits, "git diff [commit1] [commitAfterCommit1]" will give you a list of changes that the second commit made from the first. You could prune this output to get yourself just the changed file names.
Is there a function equivalent to git diff FILE in libgit2? In other words, how to efficiently retrieve the diff of a single file without having libgit2 to look at other files in the working directory?
git diff FILE will display the changes you've made relative to the index.
This can be achieved through the use of the libgit2 git_diff_index_to_workdir() function.
This function accepts a git_diff_options structure as a parameter into which you can provide a pathspec, or a list of pathspecs, you're specifically interested in.
More information about this:
Documentation of this function.
Unit test leveraging this use case.
In my current working environment, I make use of eclipsed files extensively for testing purposes. When it comes time to formalize things, I have a script which generates a diff by comparing the file with a backup saved by my eclipse script.
I'd like to be able to work without the backup of the original file; is there any way I can retrieve the current version of the file that I can pass to diff? Even though the file is view-private, I see I can enter foo##/ and see a list of versions, but I'm not sure how to find which version is the latest. Everything I've tried using cleartool ls or describe with the file name tells me that it's not a VOB object (which is true, although cleartool ls does show it as eclipsed, so it must know, somehow, that there is an element there)
Thanks
Eclipsed file means dynamic view.
The simplest solution would to make a second dynamic view based on the same config spec.
Considering how cheap and quick those views are, this isn't an issue.
On that second dynamic view, you can do a
cleartool descr -fmt "%Xn" /path/to/element
In order to get the extended pathname of the file (see fmt_ccase for more on the %Xn syntax).
I am running the cleartool subcommand diffbl -versions between two baselines. But the output looks different depending on the view I am running the command from. The difference is in the path name of the elements. For example the same file my_filemane located in /vobs/my_component/my_directory/my_subdirectory/ as seen by two views on two streams my_stream_1 and my_stream_2 shows path names:
/vobs/my_component/my_directory/my_subdirectory/my_filename##/main/my_stream_1/1
/vobs/my_component/my_directory/my_subdirectory##main/my_stream_2/my_stream_1/10/my_filename/main/my_stream_1/1
In the fist case its easy to determine the location of the file, is there was no version control, by taking the substring between /vobs/ and ##. Is there any easy way (a cleartool subcommand maybe) to find the same from the second case?
The difference comes from the visibility of the file within the view from which you are doing the diffbl.
Considering the extended pathname from the second path mentions:
main/my_stream_2/my_stream_1/10
, your best move is to redo said diffbl from a view associated with stream1 in order to get a simpler path for that particular file.
But anyway, since that file has no version in stream2, it will always be displayed with a long and complicated extended pathname.
Because ClearCase updates directory version numbers when files inside are created, our config-spec generating script is failing (details omitted).
So, as an example, given a file such as "/proj/src/scripts/build.sh##/main/branch42/3", how can we determine the latest version of the scripts directory that contains that version of the build.sh file.
Note: we're looking for a unix command-line solution that can be scripted.
If you do a ls /proj/src/scripts##/main/branch42/*/build.sh/main/branch42/3 you should get a list of all versions of the scripts directory that contain version .../3 of build.sh. Then you should be able to pick out the latest of those.
The above is probably not a fool proof approach, so you might try something more like
cleartool find /proj/src/scripts --allversions --nonvisible -name build.sh -version 'brtype(branch42) && version(3)' -print
(I no longer have a clearcase environment to test in, so the above is from memory and is not an accurate command)
Another approach is to:
set a label on the right version of the build.sh script and its directory (you can move that label when needed)
have a second dynamic view always configured to select that label
element * SCRIPT_LABEL
element /proj/... .../branch42/LATEST
That way, you simply read the information you need from that second dynamic view.