[SOLVED] Simple versioning?

Help with setting up and configuring custom user tools in UltraEdit (based on command line input)

[SOLVED] Simple versioning?

Postby fredtheman » Mon May 23, 2011 3:30 am

Hello,

Although I'm not really a developper, I often do work on small programs/scripts, and so would need some source control so I can try different things while keeping a history of steps I tried.

A real SCM, even as light as Fossil, seems a pretty heavy solution, and saving a file manually through eg. File > Make Copy/Backup > make new name with date+time > Save is a bit annoying.

I was wondering if someone had built some add-on to UltraEdit so that I could simply hit a menu item, and the current file would be saved as a revision and let me go on while providing a history of the changes I made at each milepoint?

Thank you.
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby Mofi » Mon May 23, 2011 6:29 am

UltraEdit has built-in support for version backup. Once enabled every save results in creating a new backup with a new version number. See Advanced - Configuration - File Handling - Backup.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Simple versioning?

Postby fredtheman » Mon May 23, 2011 9:17 am

Thanks, I didn't know UE could do that.

However, is there a way to manually save a new version? I hit CTRL-S very often just in case XP crashes, but I don't want to create a new version every time.
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby Mofi » Mon May 23, 2011 10:34 am

fredtheman wrote:However, is there a way to manually save a new version?

Yes, with a VBS or BAT file executed as a user tool with "%f" on the command line and option Save active file enabled. The user tool can be added to the toolbar or executed by hotkey. The VBS or BAT file has to find out itself the next number for the file with the name passed to the VBS or BAT file to create a copy of it with a new number.

But you have to take into account that the VBS or BAT file creates a copy of the just saved file and not of the last saved file before saving the file as UltraEdit does with version backup. So the last version backup created by the VBS or BAT file is equal the saved file when you close UltraEdit after running the user tool to create a version backup manually.

BTW: UltraEdit can restore file content on crash of UltraEdit or Windows. So it is quite safe to not save a modified file for hours because the temporary file used in the background is updated on hard disk nevertheless often (more or less on every change). You could also use automatic save in regular intervals if you want your files often saved for safety. As you can see on the options of version backup, UltraEdit does by default not create a version backup on automatic save. It is necessary to additionally enable version backup on automatic save.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Simple versioning?

Postby fredtheman » Mon May 23, 2011 5:59 pm

Thanks for the tip. I'll check it out.
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby mjcarman » Tue May 24, 2011 10:44 am

fredtheman wrote:I was wondering if someone had built some add-on to UltraEdit so that I could simply hit a menu item, and the current file would be saved as a revision and let me go on while providing a history of the changes I made at each milepoint?

I'd use either Subversion or Git. It's not quite a drop-in solution; a little configuration would be required.
Both can be integrated into UE by creating user tools (under Advanced->Tool Configuration) to invoke the command-line programs for whatever functionality you want. (commit, revert, etc.)
User avatar
mjcarman
Power User
Power User
 
Posts: 125
Joined: Thu Feb 10, 2005 12:00 am

Re: Simple versioning?

Postby fredtheman » Wed May 25, 2011 5:58 am

Thanks for the idea. The problem is that even a very simple SCM like Fossil requires sending different commands:

  1. Make a connection to the repository (C:\fossil.exe open c:\repo)
  2. If this is a new file, add it from UE into the repository (C:\fossil.exe add c:\Ultra Edit\myfile.txt)
  3. Check in the file before making some changes (C:\fossil.exe commit), which requires adding a comment
How do you guys use an SCM with UE? Is there an easier way?
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby mjcarman » Wed May 25, 2011 3:57 pm

fredtheman wrote:How do you guys use an SCM with UE?

The only SCM I currently have integrated into UE is ClearCase. I have user tools for
  • checkout: cleartool checkout -nc "%f"
  • checkin: cleartool checkin "%f"
  • revert: cleartool uncheckout -rm "%f"
  • ...and a few others
I created a custom toolbar and added these user tools to it (the icons are cribbed from ClearQuest).
clearquest_toolbar.png
Custom toolbar for ClearQuest user tools
clearquest_toolbar.png (1.25 KiB) Viewed 3125 times

You could do something similar for SVN. You wouldn't need a "checkout" command, the checkin command would be svn commit "%f", etc. Note that SVN supports file:/// URLs for repositories. That means that your repo can be a local folder. You don't need a server process and don't need to connect to anywhere. You would need to create a repository up front and create a "checkout" of it in another folder (wherever you want to work from). After that you would just add files/commit changes.

Using a real SCM is far superior to numbered extensions or folders and only slightly harder to set up.

If you're willing to forgo UE integration Tortoise SVN is pretty nice. It integrates into Windows Explorer as a shell extension. You still have to create a repo and initial checkout, but it's more user-friendly than using command-line utilities. You would do all SVN actions in Explorer instead of UE. (Tortoise SVN doesn't have the command-line utilities necessary to support UE integration. You could install the base SVN utilities to do it but then you have to be careful to keep the versions of SVN and Tortoise in sync.)
User avatar
mjcarman
Power User
Power User
 
Posts: 125
Joined: Thu Feb 10, 2005 12:00 am

Re: Simple versioning?

Postby fredtheman » Wed May 25, 2011 5:52 pm

Thanks much for the feedback.

After playing with Fossil, I think it could be good enough for what I need. I don't mind keeping all UE-editable files on a given partition, so I just need to create a new repository at the root of the partition, "open" it once, and from then on, I just need to add new files/commit existing files for Fossil to handle versioning.

Just one thing, though: Since adding a file that is already in the repository does nothing negative, I can simplify things in UE by simply calling the two commands one after the other, ie. Add, followed by Commit.
But is it possible to call two commands in the "Command Line" item in the Tool Configuration dialog? Something like "fossil.exe add "%f" ; fossil.exe commit -m "some comment"".

I suspect it's not possible, in which case I'll have to write a script and call it through the Advanced menu.

Thank you.
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby Mofi » Thu May 26, 2011 12:07 am

fredtheman wrote:But is it possible to call two commands in the "Command Line" item in the Tool Configuration dialog? Something like "fossil.exe" add "%f" ; fossil.exe commit -m "some comment".

It is not possible to run two commands from a command line in one user tool. But you can call a batch file which executes both commands.

Command line of user tool: "Path to batch file\AddAndCommit.bat" "%f"

Content of AddAndCommit.bat:

@echo off
fossil.exe add %1
fossil.exe commit -m "some comment"


%1 references the first parameter of the batch file which is the full file name in double quotes according to command line of the user tool.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Simple versioning?

Postby fredtheman » Thu May 26, 2011 3:03 am

Thanks, it worked fine without displaying the DOS box. I'll just add a second command to the UE menu so I can go back to the previous revision in case what I tried didn't work.

I have another question: I'd like to add a "Revert" item in UE, so the user can... discard the changes he made to the live file and revert to the last revision in the repository.

Problem is, Fossil requires passing the full path to the file, but without the drive name.

For instance, after adding "d:\some\where\myfile.txt" to the repository, its path in the repo is "some/where/myfile.txt", so if I want to retrieve the latest revision, I must type:

Code: Select all
c:\fossil.exe revert "some/where/myfile.txt"

According to the CHM help file, in the "Tool Configuration command (Advanced menu)", UE (15.10) doesn't provide the full path to a file without its prepented drive name.

Does the latest version of UE provide this, or must I write a second batch file to remove the drive name?

Thank you.
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm

Re: Simple versioning?

Postby Mofi » Thu May 26, 2011 10:34 am

Again no problem with a batch file:

@echo off
set FileName=%~pnx1
set FileName=%FileName:~1%
set FileName=%FileName:\=/%
c:\fossil.exe revert "%FileName%"
set FileName=


First line converts first parameter string from "d:\some\where\myfile.txt" to \some\where\myfile.txt

Second line removes the first backslash. Third line replaces every backslash by a slash.

Because the string value of environment variable FileName does not contain anymore double quote characters around the UNIX file name with path without drive letter, it is necessary to use double quote characters in the call of fossil.exe in case the string contains a space anywhere inside.


Where to get the information to manipulate strings in a batch file?

Execute in UltraEdit Advanced - DOS Command with the command for /? to get help of DOS command for captured by UltraEdit into a text file and read that help to understand %~pnx1.

Execute in UltraEdit Advanced - DOS Command with the command set /? to get help of DOS command set captured by UltraEdit into a text file and read that help to understand %FileName:~1% and %FileName:\=/%.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Simple versioning?

Postby fredtheman » Thu May 26, 2011 6:10 pm

Thanks a bunch. I can now successfully try something in a script file, and either commit or revert back to the previous revision :)
User avatar
fredtheman
Basic User
Basic User
 
Posts: 18
Joined: Sun Sep 05, 2004 11:00 pm


Return to Custom User Tools/Tool Configuration