Retrieving Commit Number in Git

As I moved from Mercurial to Git I got hit with annoying problem. You see, in mercurial it is trivial to get commit number and commit hash. All you need is:

FOR /F "delims=" %%N IN ('hg id -i 2^> NUL') DO @SET HG_NODE=%%N%
FOR /F "delims=+" %%N IN ('hg id -n 2^> NUL') DO @SET HG_NODE_NUMBER=%%N%

Yes, it is not the most beautiful code but it does get the job done. With -i parameter we get hash and -n is what gives us commit number. And commit number is so useful for automated builds. Yes, hash will uniquely identify the build but humans tend to work better with numbers - e.g. setup-53-1d294c0f2737.exe is much better than setup-1d294c0f2737.exe alone. If numbers are there it becomes trivial to determine what is the latest build.

Mercurial has also one more trick in its sleeve. If changes are not committed yet, it will add small plus sign to its output, e.g. setup-53-1d294c0f2737+.exe. Now with one glance in a full directory you can determine order in which builds were done, what branch are they on, and if all changes were committed at the time of build.

How do you do the same in Git?

Getting revision number is trivial. Just ask git to count them all:

FOR /F "delims=" %%N IN ('git rev-list --count HEAD') DO @SET VERSION_NUMBER=%%N%

Getting hash is similarly easy:

FOR /F "delims=" %%N IN ('git log -n 1 --format^=%%h') DO @SET VERSION_HASH=%%N%

But there is one problem here. Hash is exactly the same whether all changes are committed or not, i.e. there is no plus sign if there are some uncommitted changes during build. And I believe such indication is crucial for any automated build environment. Fortunately Git will give you wanted information with a bit effort:

git diff --exit-code --quiet
IF ERRORLEVEL 1 SET VERSION_HASH=%VERSION_HASH%+

So final code to get Git hash and commit number equivalent to what I had in Mercurial was:

FOR /F "delims=" %%N IN ('git log -n 1 --format^=%%h') DO @SET VERSION_HASH=%%N%
git diff --exit-code --quiet
IF ERRORLEVEL 1 SET VERSION_HASH=%VERSION_HASH%+

Windows 10 USB Install

Illustration

Installing Windows 10 via Windows Update works surprisingly well. However, such upgrade leaves you stuck with partition layout you might not like. Sometime best course is installing from scratch.

First step to prepare installation is getting .iso file and Microsoft always provides a way to do it. With Windows 10 it is Microsoft Media Creation Tool.

Second step is to prepare bootable USB drive. This step can be done by tools but, if you want UEFI boot, you want to do it manually. Most of tools currently available format disk as NTFS and that file system is not supported by UEFI boot process. Yes, most BIOSes still have support for legacy mode but you do lose some boot speed improvements and there are security implications.

In regards to UEFI do notice that it isn’t really important if your processor supports 64-bit OS or not - if your UEFI system is 32-bit you better install 32-bit Windows too. This weird situation of having 32-bit UEFI only with 64-bit capable processor often happens with Atom tablets. Just treat them as 32-bit system and you’ll be fine. On more capable laptops and desktops UEFI usually has support for both or rarely for 64-bit only. Rule of the thumb is to get 32-bit .iso if you are dealing with tablet and 64-bit otherwise.

Procedure is actually simple. Just write DISKPART on start screen and you will be greeted with security prompt after which you will have old-fashioned textual interface. In my case USB was disk 3 (you can deduce it based on size) but your case will probably differ. Double check which disk you are selecting because DISKPART does destroy data:

DISKPART> LIST DISK
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          476 GB      0 B        *
  Disk 1    Online          931 GB      0 B
  Disk 2    Online         7168 MB      0 B
  Disk ^^3^^    Online         7648 MB      0 B

DISKPART> SELECT DISK ^^3^^
Disk 3 is now the selected disk.

DISKPART> CLEAN
DiskPart succeeded in cleaning the disk.

DISKPART> CREATE PARTITION PRIMARY
DiskPart succeeded in creating the specified partition.

DISKPART> FORMAT FS=FAT32 QUICK
  100 percent completed

DiskPart successfully formatted the volume.

DISKPART> ACTIVE
DiskPart marked the current partition as active.

DISKPART> EXIT

Assuming that your, newly created and empty, USB drive is under letter U: and your Windows installation disk is at W:, you can use XCOPY to transfer files. Press + to get a prompt where you can enter following command:

XCOPY W:*.* /e /f U:\

Last step is to boot machine while pressing <F2> (or some other key; <Del> used to be popular) to enter BIOS. Since boot is extremely fast, I always need a few attempts to get inside. :)

Depending on the BIOS, option might have a slightly different name but most of them have “Boot override” section somewhere. Your new UEFI USB drive should appear there. Just select it and boot should ensue.

Enjoy your clean installation.

PS: Same procedure actually works for any UEFI system - from Windows Vista onward.

QText 4.00

Illustration

For its 4.00 version QText has received major refactoring with almost 100 changes separating it from the previous release.

Visually it is easy to see where some time went as there is new application icon together with new high-resolution toolbar icons. Yes, QText had high-DPI support for some time now but that always meant dealing with blurry toolbar buttons. With new graphics you should be greeted with crisp graphics no matter which resolution you’re using. It was a long overdue improvement.

Due to its internal structure, detecting external changes in files was not always straightforward as it should have been. Due to this experience with DropBox or similar file syncing software was not ideal. Long hours have been put into this version to recognize many external changes. Whether it is simple file edit in another editor or folder rename, QText will have you covered.

Lastly there was a push to cleanup some of the old and annoying bugs. All these changes should make QText more comfortable to use.

As always, you can download new version directly or use built-in upgrade menu.

PS: Order of your tabs will be reset to alphabetic with this version. This is a one-time change. QText will continue remembering tab order once you (re)order them again.

Books

Cover

Those more observant among you might have noticed there is a books tab up there. Yep, I am a published author now.

While both books are more of a reference material than what you would usually consider a book they did require quite a lot of work - especially getting formatting and publishing just right. Those interested in that aspect can view what raw sources looks like and what goes into making a proper e-book.

(73) AF7RG

Error While Powering on VMware Player on Windows 10

Illustration

As I went through one of the many Windows 10 beta updates, my VMware Player started throwing “Error while powering on: Internal error.” After reboot everything started working again so I just assumed it was simply some fluke in the upgrade process. And then it happened again a bit later. This time a single restart didn’t help but it did start working after a few of them. Every restart was like a coin toss. It smelled like a race condition.

One of things I checked was status of VMware’s services. There I noticed that, although startup type was set to Automatic, VMware Authorization Service was not running at times. And I could match the times when it was not running with the error. Even better, error would disappear as soon as I would manually start that service. My best guess, based on observed behavior, was that VMware Authorization Service needed some other service to start beforehand. However, dependencies for that service were missing. All VMware’s service needed was a bit more time.

Fortunately, Windows has one great feature enabling just that ever since Windows Vista. All needed is to change startup type to Automatic (Delayed Start) and your service will wait a bit extra time before starting. Original idea of this feature was to alleviate system load at startup by postponing some tasks for just a bit later when CPU had a chance to breathe. But, as a side effect, we can be sure that pretty much all important system services are already up by the time delayed start kicks in.

Might not be an ideal solution but I had no issues with it.

PS: Proper solution would be to find the missing dependency and add it to service. But setting up dependencies is not an easy task and pretty much becomes just trial-and-error adventure unless you know the product on the source code level. Not worth it.