ClearCase can't merge from a snapshot view - view

I am using IBM Rational Clear Case,
I have a snapshot view, with some checked-out files. This view is about to be obsolete, and I need these checked-out files to be merge to a new version (New view).
My problem: I am using ClearCase Version Tree Browser (clearvtree.exe) to do my merge. I opened the Version Tree for one of the checked-out files, on the view to which I want to merge the file. Now when ever I try to select the checked out file: right click -> and select "Merge to" I get the following error:
"The selected version is not accessible from this view".
Note that when doing the same procedure on Dynamic View it works fine.
I know I can copy these files manually, but I am trying to find a way to do this, using the ClearCase tools (such as the Merge Tool and off-course the Version Tree).

OK, I have written a script (Actually two - which might be merged to one) that do what I need: To automatically merge from a snapshot view into a dynamic view. I assume it will also work with any other combination - but dynamic to dynamic or dynamic to snapshot is already supported by the IBM ClearCase "Merge Manager" tool.
First Scrip will find all checkouts and format them accordingly, while adding them to files.txt:
#echo off
REM ------------------------------- synopsis ----------------------------------
REM This script creates a list of all checked out into files.txt under the
REM batch-file directory.
REM files in the following format:
REM \VOB1\file1.txt##\main\branch_v111\CHECKEDOUT##Comment for file1
REM \VOB2\file2.txt##\main\branch_v111\CHECKEDOUT##Comment for file2
REM \VOB2\file3.txt##\main\branch_v111\CHECKEDOUT##Comment for file3
REM ------------------------------- synopsis ----------------------------------
set source_view_path=C:\Snapshot\some-snapshot-john
set currentDirectory=%~dp0
set chekedOutOutputFile=%currentDirectory%find_co.txt
set resultFile=%currentDirectory%files.txt
#echo Getting checkouts of %source_view_path%
#echo %currentDirectory%
REM ---------------------------------------------------------------------------
REM The next code produces a find_co.txt intermediate file with the following
REM format of checkouts:
REM <File Full Path>##<Version ID>##<File Comment>
REM %n - for file Name (With full path)
REM %Vn - for file Version ID.
REM %c - for file Comment
REM
REM Example:
REM C:\MY_VIEW_PATH\VOB1\file1.txt##\main\branch_v111\CHECKEDOUT##Comment for file1
REM C:\MY_VIEW_PATH\VOB2\file2.txt##\main\branch_v111\CHECKEDOUT##Comment for file2
REM C:\MY_VIEW_PATH\VOB2\file3.txt##\main\branch_v111\CHECKEDOUT##Comment for file3
REM ---------------------------------------------------------------------------
pushd %source_view_path%
cleartool lsco -cview -avobs -fmt "%%n##%%Vn##%%c" > "%chekedOutOutputFile%"
popd
del /q "%resultFile%"
REM ---------------------------------------------------------------------------
REM The following code formats the find_co.txt into files.txt with the desired
REM result - <File VOB Path>##<Version ID>##<File Comment>
REM Example:
REM From -
REM C:\MY_VIEW_PATH\VOB1\file1.txt##\main\branch_v111\CHECKEDOUT##Comment for file1
REM C:\MY_VIEW_PATH\VOB2\file2.txt##\main\branch_v111\CHECKEDOUT##Comment for file2
REM C:\MY_VIEW_PATH\VOB2\file3.txt##\main\branch_v111\CHECKEDOUT##Comment for file3
REM To
REM \VOB1\file1.txt##\main\branch_v111\CHECKEDOUT##Comment for file1
REM \VOB2\file2.txt##\main\branch_v111\CHECKEDOUT##Comment for file2
REM \VOB2\file3.txt##\main\branch_v111\CHECKEDOUT##Comment for file3
REM ---------------------------------------------------------------------------
for /F "usebackq tokens=*" %%A in ("%chekedOutOutputFile%") do (
call ::removeSourceViewPath "%%%A"
)
goto endOfScript
REM ---------------------------------------------------------------------------
REM Manipulate the path of each file to exclude the view from it e.g:
REM C:\MY_VIEW_PATH\MY_VOB\file.txt -> \MY_VOB\file.txt
REM >>>-----------------> start of :removeSourceViewPath
:removeSourceViewPath
set str=%1
call set "resultStr=%%str:%source_view_path%=%%"
set resultStr=%resultStr:~1,-1%
#echo %resultStr%
#echo.%resultStr%>>"%resultFile%"
exit /b
REM <<<-----------------< end of :removeSourceViewPath
REM ---------------------------------------------------------------------------
:endOfScript
pause
#echo ------------------------------------------------------------------
The second script takes the files.txt and merges them from a source view to a target view:
#echo off
REM ------------------------------- synopsis ----------------------------------
REM This script takes a list of all files from the files.txt which is under
REM this batch-file directory and merges them from TARGET to SOURCES views
REM files in the following format:
REM <File VOB Path>##<Version ID>##<File Comment>
REM are merged from <SOURCE_VIEW>\<File VOB Path> to
REM <TARGET_VIEW>\<File VOB Path> with the <File Comment> as comment.
REM ------------------------------- synopsis ----------------------------------
setlocal
set TARGET_VIEW=V:\v11-john-local-nt
set SOURCE_VIEW=C:\Snapshot\some-snapshot-john
REM ---------------------------------------------------------------------------
REM The following takes the line:
REM <File VOB Path>##<Version ID>##<File Comment> and checks out the target
REM file, then it automatically merges the file from source to target.
REM Note that the version is not required here (it might be required if we
REM want to merged from a version which is not the latest one in the branch).
REM ---------------------------------------------------------------------------
for /f "tokens=1,2,3 delims=##" %%i in (files.txt) do (
cleartool co -unreserved -c "%%k" %TARGET_VIEW%%%i
cleartool merge -to %TARGET_VIEW%%%i %SOURCE_VIEW%%%i
)
endlocal
pause
Both of this scripts merged all the file I needed from the source View to the target View.
Notes:
You can create a batch file that get the SOURCE_VIEW and TARGET_VIEW
in the command line as %1 and %2,
I splittend this into two scripts so I can remove some files from the
list, before actually doing the merge.
The scripts will preserve the original comment of the file.
%~dp0 - This is how I can force working in the current batch file
directory.
Feel free to comment. If you have a better solution I will be glad to
move my V to yours :-)

Since it is a snapshot view, its checked out files are only accessible in the actual view path, not in its view storage (like a dynamic view)
If you have access to the snapshot view path, you can use clearfsimport in order to automatically import the modified/new files from said snapshot view to your current view.
See a clearfsimport example here.

The description seems to contradict itself. Are you in ONE snapshot view and attempting to merge FROM a checked out version in another one? That generally will not work for the reason #VonC mentioned. The ClearCase core doesn't officially "know" where the most recent snapshot view workspace is for that other view, so it can't access the view-private copy. This could also fail for a dynamic view depending on view permissions.
If you are trying to merge TO an arbitrary version FROM your checked out version, you should be getting "element already checked out in this view" (Or words to that effect) since only one version of an element can be checked out in a given view.

Related

Trying to make a menu in a windows command prompt

I have a batch file that gets run by the user typing:
usercompile filename
usercompile is a batch file that does this:
copy /y %1.txt lib\incoming_file.txt
and then starts the compiler:
compiler.exe
The compiler has the "incoming_file" name hard-coded into linked source (this can't be chaged), so the current method is simply to copy the user file in and rename it to the known name and run the compiler.
I'd like to present the user with a list of files that are generated when a batch file is run, then the batch file would copy the selected file in, rename it (just like is done now).
So it would look like this:
Please choose a file to compile:
1) matthews_build
2) marks_build
3) lukes_build
and then the user would type 1 or 2 or 3 (in this case) and press enter. The batch file would copy that file to the known file name and launch the compiler. The one good thing is that the files that need to be listed all have a unique extension (.jal).
Any ideas?
I changed my approach and consider my previous answer a bad practice: re-listing the files with a second dir command unnecessarily reads the disk again, not to mention the rare but possible case if a file is added/removed between the 2 dir's and makes the whole thing unreliable.
Based on this brilliant solution I did a possible implementation with dynamic array:
#echo off
set /a counter=0
setlocal enabledelayedexpansion
FOR /f "delims=|" %%i IN ('dir /b /on "yourpath*.jal"') DO (
set /a counter+=1
rem echo !counter!^) %%~ni
set FileList[!counter!]=%%~ni & rem This is an array element, a dinamically created variable
)
rem Iterate through variables:
FOR /l %%i IN (1,1,!counter!) DO (
echo %%i^) !FileList[%%i]!
)
set /p option="Choose an option: "
echo !FileList[%option%]!
endlocal
This makes the file list available for any number of following commands.
One possible solution is to list all .jal files and give them an option number, store the result, and based on user input, look up the file based on the option number. As I know no way of storing such a result in memory (no array/hash table data type), only in a file, if a file can not be used, then the listing should be repeated in a deterministic way so that if we re-assign the option numbers, we get the same result. We can do it ensuring alphabetical ordering.
Here is one implementation:
BLOCK 1
setlocal enabledelayedexpansion
FOR /f "delims=|" %%i IN ('dir /b /on "yourpath\*.jal"') DO (
set /a counter+=1
echo !counter!^) %%~ni
)
endlocal
The nested dir command ensures alphabetical ordering (reference.)
A remark why I put a pipe (|) as a delimiter: if you don't define a delimiter, the default space will be used. If your file name contains space then it would be truncated. So I picked a character that is not valid in file names ensuring the whole file name is returned.
Now if you get a number from the user by this:
set /p option=Choose your option:
after this command (evaluating and possibly re-requesting the input) to do a lookup for the file you can repeat BLOCK 1 but replace the echo line with examining the option like this:
if !counter! == %option%
and put those commands in the if block to do whatever you want to do with the file (for debugging, put back the echo command).

How to find the new files after a specific time point in windows ?(command line)

I know there is a way in linux to filter all file generated after a specific time.
But how could we do that in windows command line ? Or in bash .
For example, I have three files in a folder. After 10/10/2016, 12:12:54, a new files was generated into this folder and I need to know the new file's name,size and path.
Or,
I don't know when the new files will be generated. I want to check each 10 mins. If there are some new files generated after a specific , I can get the file's name, path and size.
I search something about that , I know I can use forfiles /P directory /S /D +08/01/2013 to do that. But it will displays all the files which are modified after 08/01/2013 under directory. But I want it displays the folders in directory and all files in directory folder(not in its sub directory).
Although you did not show any own efforts to solve your task, I decided to provide a script that returns a list of files created since the previous execution. It does not check the file creation time stamp, because date/time maths is not natively supported in pure batch-file solutions. Instead it generates a list of files, stores it in a temporary file and compares it with a previously saved list.
Opposed to relying on file time stamps, this will for sure recognise every new files. When checking the time stamps, files may be considered as new since the last run erroneously or new files may not be recognised erroneously, particularly such files that are created during execution of the script.
So here is the code:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "TARGET=D:\Data" & rem // (path to the directory to observe)
set "PATTERN=*.*" & rem // (search pattern for matching files)
set "LIST=%TEMP%\%~n0" & rem // (file base name of the list files)
set "FIRSTALL=#" & rem /* (defines behaviour upon first run:
rem set to anything to return all files;
rem set to empty to return no files) */
rem /* Determine which list file exists, ensure there is only one,
rem then toggle between file name extensions `.one`/`.two`: */
set "LISTOLD=%LIST%.two"
set "LISTNEW=%LIST%.one"
if exist "%LIST%.one" (
if not exist "%LIST%.two" (
set "LISTOLD=%LIST%.one"
set "LISTNEW=%LIST%.two"
) else (
erase "%LIST%.one"
if defined FIRSTALL (
> "%LIST%.two" rem/
) else (
erase "%LIST%.two"
)
)
) else (
if not exist "%LIST%.two" (
if defined FIRSTALL (
> "%LIST%.two" rem/
)
)
)
rem /* Create new list file, containing list of matching files
rem sorted by creation date in ascending order: */
> "%LISTNEW%" dir /B /A:-D /O:D /T:C "%TARGET%\%PATTERN%"
if not exist "%LISTOLD%" (
> nul 2>&1 copy /Y "%LISTNEW%" "%LISTOLD%"
)
rem // Search new list file for items not present in old one:
2> nul findstr /V /I /X /L /G:"%LISTOLD%" "%LISTNEW%"
if ErrorLevel 2 type "%LISTNEW%"
rem // Delete old list file:
erase "%LISTOLD%"
endlocal
exit /B
The first time the script runs, all files in the monitored directory are returned, unless you change set "FIRSTALL=#" to set "FIRSTALL=", in which case no files are returned the first time.
The core command is findstr which is configured so that the old list file provides literal search strings for being used to search the new list file and to return not matching lines, so the output are those lines of the new list file which do not occur in the old one.
Supposing the script is saved as new-files-since-last-run.bat, you could wrap around another tiny script that constitutes an endless loop with a polling rate of 10 minutes, like this:
#echo off
:LOOP
> nul timeout /T 600 /NOBREAK
call "%~dp0new-files-since-last-run.bat"
goto :LOOP
Setting up Windows Task Scheduler might be a better option though.

batch script to generate a list with file names newer than a saved date timestamp

I have a landing directory where we receive 10-15 files everyday. I then run a batch script to create a list with file names that have newly landed and then informatica reads the list of file names to process the new source files.
The problem here is, if a file is edited on same day after informatica loads the file. My batch script does not identify the updated file because the file has same date and name.
Is there a way to compare files based on timestamp and generate a file list? Any help will be greatly appreciated. Thanks!
The current batch script code:
rem this batch script is used to list all the files hosted newly to a xyz landing directory
set LandingDir=\\path\to\landing\directory\*.csv
set DateFile=%sys_var%\script\DateFile.txt
set LastRunDateFile=%sys_var%\scripts\LastRunDateFile.txt
set Temp_File_List=%sys_var%\scripts\Temp_File_List.txt
set File_List=%sys_var%\SrcFiles\File_List.txt
set /P _PreviousDate=<%DateFile%
type %DateFile% > %LastRunDateFile%
xcopy "%LandingDir%" /l /s /d:%_PreviousDate% .>%Temp_File_List%
type %Temp_File_List% | findstr /v File(s)>%File_List%
echo %date:~4,2%-%date:~7,2%-%date:~10,4% >%DateFile%
On Windows there is the archive attribute always set on a file automatically if a file is modified in any way.
Using the archive file attribute makes the task much easier than storing last modification files times of all files processed and comparing last modification file times on next run.
All needed to be done is removing archive attribute on file being already processed, i.e. added to the file list.
Example:
#echo off
setlocal
set "FilePattern=*.csv"
set "sys_var=C:\Temp\Test"
set "File_List=%sys_var%\SrcFiles\File_List.txt"
set "LandingDir=\\server\share\path\to\landing\directory"
if exist "%File_List%" del "%File_List%"
for /F "delims=" %%I in ('dir "%LandingDir%\%FilePattern%" /AA-D /B 2^>nul') do (
echo %LandingDir%\%%I>>"%File_List%"
%SystemRoot%\System32\attrib.exe -a "%LandingDir%\%%I"
)
if not exist "%File_List%" echo No new file!
endlocal
The command DIR returns because of /AA-D just files (not directories) with archive attribute set in bare format because of /B.
So output by DIR and processed by FOR are just the names of the files with archive attribute set without path and always without surrounding double quotes even if the file name contains a space or another special character.
The file names would be returned by DIR with full path on using additionally DIR option /S for listing recursively all files in specified directory and in all subdirectories matching the file pattern (and having archive attribute set).
Each file name is written into the file list file and then the archive attribute is removed from the file to ignore this file automatically on next run of the batch file except the archive attribute is set again because the file was modified in the meantime.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
attrib /?
del /?
dir /?
echo /?
endlocal /?
for /?
set /?
setlocal /?
See also the Microsoft article Using command redirection operators for an explanation of >> and 2>nul with escaping > with ^ to be interpreted on execution of DIR instead of FOR.

How to create flat directory from folder hierarchy and handle duplicate files?

I want to parse a directory and its subdirectories and copy all files in a target directory ignoring the original folder structure. All files shall be copied directly in the target directory.
I found a nice solution here for the Windows command line:
for /r FolderA %f in (*) do #copy "%f" target
https://stackoverflow.com/a/1502183/772434
That in general works fine, but I have duplicate files in the source directory which have the same name. There are too many files, so I can not handle those exceptions by hand.
How can I handle those files in the script automatically?
Options:
overwrite files during copying
keep copies and rename file e. g. by adding "__123" a number at the end of the file name
compare files (MDS5 sum or similar) and create copy only if files are different.
I would prefer option 3 (compare file content and keep numbered copies only if files are really different), but I'm also interested in solutions for options 1 and 2 (more pragmatic).
Here's an approach. i haven't tested it, so i hope it works as expected.
There is a global variable called CURRENT_DUPLICATE_SUFFIX. every time a file with the same name is found, but with different content, this value gets incremented and appended to the resulting file name
#echo off
SET SOURCE_DIR=C:\temp\LogAnalyzer
SET TARGET_DIR=C:\temp\test\output
SET CURRENT_DUPLICATE_SUFFIX=1
for /r "%SOURCE_DIR%" %%f in (*) do CALL :SUB1 "%%f"
GOTO END
:SUB1
SET PURE_FILE_NAME=%~nx1
SET TARGET_FILE_NAME=%TARGET_DIR%\%PURE_FILE_NAME%
IF NOT EXIST "%TARGET_FILE_NAME%" (
COPY %1 "%TARGET_DIR%"
GOTO :EOF
)
REM if we are here, the target file exists.
echo n |comp %1 "%TARGET_FILE_NAME%" >NUL 2>NUL
REM in case the files have the same content
IF %ERRORLEVEL%==0 GOTO :EOF
SET TARGET_FILE_NAME=%TARGET_FILE_NAME%_%CURRENT_DUPLICATE_SUFFIX%
SET /A CURRENT_DUPLICATE_SUFFIX=%CURRENT_DUPLICATE_SUFFIX%+1
COPY %1 "%TARGET_FILE_NAME%
GOTO :EOF
:END

Creating a batch file to back up a specified folder

I am actually pretty new to this batch file thing. I know it's important to know at least the basic commands. How do I do the following?
Zipping a specified folder.
Move the folder to another place.
When zipping it, the ZIP file name will be the current date and
if there is another zipped file with the same name, it should be named like 20090924-2.
PS: 7-Zip is installed on my computer as an archive software.
The batch script listed below will do it (I have tested it
and it works to specifications). The directory to zip and
move is specified as its parent directory and the name of
the directory (PARENT_FOLDERTOZIP and FOLDERTOZIP in the
beginning) - I couldn't figure out how to copy entire
directories (I think XCOPY can only copy content of
directories and sub-directories.). The copy location is
specified as FOLDERTARGETLOCATION, and the directory to place
the compressed files in is specified as ZIPDIR.
The location of 7-Zip is configured through SEVENZIP_EXE.
Note also that getting the current date in the required
format depends on the short date format in regional
settings. I have listed three different versions for
ISO-8601, Central European and U.S.A. The active one in the
listing is for the U.S.A. (the "set FDATE=" line). If a
different one is needed then just copy-paste from one of the
other two.
That said it should be noted that this kind of thing is much
easier with Perl, Python or PowerShell.
#echo off
#title=Folder zip and move...
rem Parameters
rem Folder to zip and move
set PARENT_FOLDERTOZIP=T:\to delete
set FOLDERTOZIP=Folder to Compress
rem Target folder for moving the input folder to.
set FOLDERTARGETLOCATION=s:\move Here
rem Where to place compressed folders
set ZIPDIR=D:\toDelete\2009-09-24a
rem Configuration
set SEVENZIP_EXE=D:\Program Files\7-Zip\7z.exe
rem =================== Date ==============================================
rem There is no universal way inside batch itself to get a
rem date that is independent of regional settings (but is
rem quite trivial if an external program or script
rem (Perl/Python) is available).
rem
rem For short date formats:
rem
rem -------------------------------------------------------
rem
rem ISO-8601:
rem 0123456789
rem yyyy-MM-dd/ E.g.: 2009-09-24
rem
rem set FDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
rem
rem -------------------------------------------------------
rem
rem Central european:
rem 0123456789
rem dd/MM/yyyy E.g.: 24/09/2009
rem
rem set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
rem
rem -------------------------------------------------------
rem
rem US:
rem
rem 0123456789
rem MM/dd/yyyy E.g.: 09/24/2009
rem
rem set FDATE=%DATE:~6,4%%DATE:~0,2%%DATE:~3,2%
set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
set ZIPFILE=%ZIPDIR%\%FDATE%.7z
set FOLDERTOZIP_FULLPATH=%PARENT_FOLDERTOZIP%\%FOLDERTOZIP%
mkdir %FOLDERTARGETLOCATION%
rem Does a zip file already exist?
if exist "%ZIPFILE%" GOTO L_ZIPFILE_EXISTS
GOTO L_ZIPFILENAME_OK
rem Find a compressed file that does not already exist.
:L_ZIPFILE_EXISTS
set RNUM=0
:L_TRYANOTHER
set /a RNUM=%RNUM% + 1
set ZIPFILE=%ZIPDIR%\%FDATE%-%RNUM%.7z
echo Candidate: %ZIPFILE% ...
if exist "%ZIPFILE%" GOTO L_TRYANOTHER
rem Zip the folder!
:L_ZIPFILENAME_OK
"%SEVENZIP_EXE%" a %ZIPFILE% "%FOLDERTOZIP_FULLPATH%"
if exist "%ZIPFILE%" GOTO L_OKZIP
GOTO L_ERROREND
:L_OKZIP
rem Move folder: copy, then delete source.
set DEST_FOLDER=%FOLDERTARGETLOCATION%\%FOLDERTOZIP%
mkdir "%DEST_FOLDER%"
xcopy /Y /S "%FOLDERTOZIP_FULLPATH%"\*.* "%DEST_FOLDER%"\
rmdir /S "%FOLDERTOZIP_FULLPATH%"
GOTO L_END
:L_ERROREND
echo 7-Zipping failed !!!
:L_END
pause

Resources