Plastic SCM email notifications!

October 28, 2014

People love notifications! So let’s add some to Plastic SCM.

This is a DIY project; it’s not something you’ll find built-in with Plastic SCM. I came with this fast solution to get email notifications when certain Plastic SCM operations were triggered. If you want to have built-in notifications in Plastic, you know you can use the uservoice page to vote up for it.
Now, you can download the tool from here.

Triggers

The entry point for third party tools is the trigger system. Using triggers you can hook up important operations and customize their behavior.

I’ll take the following ones to start coding a simple notification center:

  • After-checkin
  • After-mkreview
  • After-editreview
  • After-mklabel

With the four triggers above, I will be able to get an email when a checkin is created, a new code review is created or edited and finally when a new label is created.

The Plastic SCM triggers provide extra information both before the operation is run (before triggers) and after it finished (after triggers). You can review all the details here. Consuming the standard input or reading the trigger environment variables will help you create smarter and customizable notifications, such us getting notified only when the “README.txt” file has been changed at the release branch by a certain user.

This is a high level diagram explaining how the tool works:

The tool

In order to attach the tool to a Plastic SCM trigger you will need to use the “cm mktrigger” command as follows:

cm mktrigger after-mklabel "mklabelnotifier" "C:\triggers\plasticnotifier.exe aftermklabel C:\triggers\mklabel.txt"

You need to specify the trigger type, a name to easily recognize the new trigger and the tool you want to run when the operation is triggered.

The “plasticnotifier.exe” tool only needs two parameters, the first one is the trigger type and then the configurator file for that trigger type.

Configuration files

The source code will understand three different file formats that will serve as an example that you can use to create additional ones.

Mail list

The most basic configuration file is the list of email recipients the trigger will use when fired. It looks like as follows:
developer1@yourCompany.com
developer2@yourCompany.com
admin1@yourCompany.com
This format is valid for the “aftermklabel” trigger. The “AftermklabelTrigger” class will read the entire list and will start sending emails.

Translation file

For some triggers you will need to provide a mechanism to translate the Plastic SCM user and get the email. This file will be used by the “AfteReviewTrigger” class to translate the code review assignee user and obtain the email to send the message.

This is the config file aspect:
dev1;developer1@yourCompany.com
dev2;developer2@yourCompany.com
dev3;developer3@yourCompany.com
Each line has two fields separated by a semicolon; the first one is the Plastic SCM user ID and the
second one the user email. The trigger will create an environment variable with the code review assignee user ID. The “plastic notifier” will use this file to obtain the email to send notifications to.

Complex file

The last file format has several fields and subfields, take the following content as an example:

%_%message%_%
Changeset {0} created with the "{1}" comment.\r\n
Changeset content:\r\n{2}
%_%subscribers%_%
developer1@yourCompany.com;br:/main/experimental;br:/main
admin1@yourCompany.com;*
This file format is used by the “AfterCheckinTrigger” class and has two parts: the message and the subscribers.

The message is the email body that you can customize.

Three extra fields are available for the message: “{0}”, “{1}” and “{2}” will be automatically replaced by the changeset specification, the changeset comment and the files changed. Again this information is provided by the trigger using environment variables and the standard output.

The subscribers part is similar to the “Mailing list” format we explained above, but this one has extra information. After the user mail you can write, separated by semicolons, the branches you are interested on for notifications. Using a star (*) you will get notification for all the checkin operations done in the server. In the example above, the user “developer1” will only get notifications for the /main and /main/experimental branches, but the user “admin1” will get an email for every single checkin done in the server.

Further work

With the tool provided, you can get notifications when:
  • A new label is created.
  • A new code review has been assigned to you.
  • A new checkin in a certain branch has been performed.
But this is just a small preview of what you can get if you continue working. Here come some suggestions:
  • Get an email when permissions are changed.
  • Get an email when somebody tries to remove a repository.
  • Get an email when certain files are changed.
The source code is written in C# but you can grab it and translate it to any other language. You can improve the code and complete it, and, if you do, please don’t forget to share it!

Happy notifying!





How the 2d version tree works

October 27, 2014

This article explains how the 2d version tree works and what it exactly renders.

We realized 2d-version-tree is one of the less understood features in Plastic, so a detailed explanation is definitely worth.

Item-level trees vs changeset trees

Plastic displays the evolution of a repository rendering the Branch Explorer. It is an overall view of what happened at a global level instead of going file per file.

While this is very useful in almost all cases, there are users who miss the old days of individual version trees. Maybe they have a pre-Plastic 4.0 background, maybe they come from good-ol ClearCase or maybe they just find it more natural.

Plastic SCM works on a changeset basis: changesets are the core of the system and not individual file histories. The reason is merge tracking: merges are tracked at the changeset level and not the individual file revision level.

We actually change this when we moved to version 4 a few years ago. Before that merges were tracked at the individual item (directory/revision) level.

What does it mean? Well, when you had to merge, let’s say 1200 files (or directories) Plastic 3.0 had to walk 1200 different history trees finding merge links and ancestors. In 4.0 and beyond it only walks one single tree. There’s no way for 3.0 to outperform 4.x (and later) in merge speed because the old version simply had to do tons of work. I won’t cover all the details, but this radical change didn’t only benefit merge performance but also the overall system speed and distributed features.

A simple 2d tree scenario

Let’s go through a very simple branch/merge scenario and let’s follow the history of a single file inside our repository. The following figure shows the Branch Explorer of our repo and where the file “foo.c” was modified.

As you can see the file was added in changeset 1, later branched and changed on changeset 5, and this change was merged back to “main” in changeset 7.

How does the version tree of the “foo.c” file looks like?

Look at the following figure: you probably expect something like the graphic on the right, but this is not how Plastic works. Plastic actually created only 2 revisions of “foo.c” so far: one created on changeset 1 and the second one created on changeset 5.

You may wonder what happened during the merge: well, changeset 7 simply includes the revision loaded by changeset 5 because there is no merge conflict and hence no need to create an extra revision for the file. This is what we call a “revision replacement” because changeset 7, which is a children of 4, simply replaces the loaded revision of “foo.c” as the result of the merge.

You probably expected something like the graphic on the right of the figure above and if fact this is how things worked on Plastic 3 and before, but the underlying merge tracking mechanism changed in 4.0 and beyond. There’s no need to create extra revisions of the file for trivial merges which greatly reduces the amount of operations to be performed.

Think about it: suppose you added 10k files on a branch and later merged them back to main: 3.0 was actually creating another 10k revisions of the files on main, while 4.x and beyond simply say “hey, load them on the main branch, that’s all” saving precious time.

So, how does the 2d-version-tree renders the previous case? Check the following figure:

As you can see the 2d-version-tree decorates the “real” version tree of the file with information from the Branch Explorer (changeset history) so you can better understand what is going on with the file.

The changesets marked as “U” mean the file was unchanged on this changeset, but it is still rendered so we can understand how the file evolved through the repo history. Looking at this diagram you can understand that the revision changed on branch1 was the one finally labelled as BL001. Looking at the “raw” tree (or the history of the file) you wouldn’t have enough info to understand it.

A slightly more complex 2d-tree scenario

Look now at the following Branch Explorer:

It is slightly more complex than the previous since it involves 3 branches and a couple of merges. Our file “foo.c” was simply added on changeset “1” and changed on “9”. Look how the “real” version tree looks like:

Looking at this tree you’d never understand what actually happened to the branch! How did it end up in branch2? Was it ever merged? You can’t tell.

Now, let’s look at the 2d-version-tree:

Still it explains there are only two revisions of the file, but by rendering the “unchanged changesets” where it was rendered you can now understand how the file evolved and how it end up being labelled in BL001.

A 2d-tree with a file concurrently changed

The cases so far didn’t run into merge conflicts: foo.c wasn’t modified in parallel and involved in a real merge.

The following Branch Explorer renders a third scenario where foo.c is finally modified in parallel and merged:

Now foo.c is added in 1 as before but changed both on 4 and 9.

This is how the raw version tree looks like:

Whenever we have a *real* merge we’ll be able to render a merge link between two revisions, which greatly helps understanding the scenario, but still, the graphic above falls short to explain what actually happens to the file, doesn’t it?

You didn’t do a merge from “branch2” to “main” so, why do you have such a merge link?

That’s why the 2d-version-tree solves the scenario as follows:

Conclusion

I hope that reading through the previous cases helps understanding how the 2d-version-tree works and getting a better idea of why it explain the history the way it does.

Don’t hesitate to reach us if you have any questions.



Directory Notifications to find changes

October 22, 2014

Pending Changes is now faster than ever because it doesn’t need to traverse the workspace anymore. We have implemented a new mechanism based on Windows Directory Notifications to detect workspace changes faster than ever.

It is available only on Windows but we’ll eventually implement it for Linux and Mac (based on their corresponding notification mechanisms).

What does it mean for you? Well, as soon as you install 5.0.44.608 or 5.4.15.604 (or higher) Pending Changes will be faster. You’ll clearly notice the speed up with really large workspaces (in number of files) and with slow disks. The slower the disk is, the clearer the speed up will be.

How Pending Changes works? (without directory notifications)

Whenever you click on “refresh” on Pending Changes Plastic triggers a search to find the files that have been modified on your workspace.

The diagram below describes the process in detail:

  • The process checks the “pending changes options” first: if only checkouts are requested, then there’s nothing to look for, just print the list. That’s why working with checkouts makes sense for huge workspaces (>400k files).
  • If the options to find changed files on disk are set, the directory walk will start.
  • For each directory starting on the root of the workspace Plastic will try to find changed files. It will compare the timestamp on disk with the stored timestamp on the wktree file: the plastic.wktree file (inside .plastic) stores the metadata of the file. It know “how it was” after the last update or checkin. So if the timestamp and size doesn’t match, the file was changed. If timestamp doesn’t match and size does, Plastic hashes the file. It is slower but it makes sure the file is different. Alternatively there’s an option to force Plastic to always find changes based on file contents (ignoring the timestamp) which is definitely slower but required on some scenarios.
  • At the end of the disk walk, Plastic has a list of all the modified files on your workspace.

The diagram doesn’t show the last step (if the option is set): find “moved and renamed files” by matching potential added and deleted files.

What I want to explain with the diagram is that there is at least one IO operation by directory. If you keep pressing “refresh” on the Pending Changes view, chances are the list will be filled quickly: after the first traversal the workspace will be loaded in the file system cache so the next reads will be blazing fast. But if your disk is not very fast, or your computer is performing a lot of IO, or using a lot of RAM, chances are that your workspace won’t be entirely loaded in the file system cache, and then walking it will take longer.

You probably noticed it when after some coding you go back to Plastic, click refresh, and it takes longer than usual. This is exactly what we wanted to improve with this feature.

How Pending Changes with Directory Notifications works?

It is rather simple: we use Windows directory notifications to listen to events on the workspace directory. Each time a file is written, deleted, added, moved or renamed inside the workspace, Plastic gets a notification.

So, while we perform an initial directory traversal the first time the Pending Changes view loads, no other full directory walk will be needed later, greatly speeding up the operation.

What we do is the following: after the first traversal we keep a tree with the metadata of what is on disk, and we invalidate parts of it (on a directory basis) each time a change happens inside it. This way Pending Changes only has to reload parts of the tree instead of walking the workspace entirely. It saves precious time while still being a robust solution.

One of the issues with Directory Notifications on Windows is that it can’t really notify file or directory moves, so you have to match pairs of added/deleted. Instead of trying to pair the notifications we just invalidate parts of the tree and let the regular Pending Changes code to do the rest.

So, there’s still room for improvement but our initial tests probed that the extra complexity of doing a more precise event tracking didn’t pay off compared to just invalidating parts of the tree.

Availability

Chances are you are already using it :-)

If you’re using 5.0.44.608 or higher or 5.4.15.604 or higher, you’re already enjoying the Directory Notifications powered Pending Changes view.



Branch differences

September 22, 2014

We’ve implemented a batch of improvements in the branch/cset/label diff window in the last months. Some of the improvements are pretty recent and some others have been around for months already. I’ll be walking through them and explaining how they help when running diffs on a daily basis.

Improved diff groups

Availability: 5.0.44.603 (Sep 12th 2014) and 5.4.15.605 (Sep 19th 2014).

The first feature is the ability to group together files and directories that only differ in file system permissions (typical scenario when some files get executable flag on Linux). Now the files that only differ in file system permissions are grouped together so you can better focus on what was actually modified.

The goal here is to let you focus on the real changes when diffing code for a review or when figuring out why a bug occurred, by grouping away potentially uninteresting changes.

The second feature is a slight modification since we released Item Merge Tracking last year. Now the files that were in changed/changed merge conflicts will show up in their own category:

And this is how the same info was grouped before:

As you can see now he highlight the “changed/changed” and put them at the very beginning of the list so you can focus first on the diffs of files which were modified by both contributors during a merge, and hence are potentially worth reviewing.

Analyze diffs

Availability: 5.0.44.536 (March 3rd 2014) and 5.4.7.538 (March 10th 2014).

There’s a story behind this feature: sometimes you find yourself reviewing a task where the developer modified a huge number of files, like 200 or so.

You launch the diff and then you see the counter with a big number on it: 100, 200, 250 files… whatever. Your feeling will be: “oh god! Let’s go and grab some coffee first”. Which, in short, means that huge reviews are extremely unproductive because you enter in this state of mood of “this will take a loooooong time”.

And sometimes that’s correct and you truly have to spend a long time.

But chances are that many of the files changed by your colleague only contain trivial changes. Like a rename on a method that affects a bunch of files, but all this files only have a trivial modification.

How can you figure out beforehand? Well, that’s why we’ve introduced “analyze changes”.

You click on the new “analyze differences” button and then Plastic will use cloc to calculate the lines of code being modified. You can see it running in my review with 284 files below:

And here goes the result once the changes were classified:

As you can see there’s a new SLOC column where you see a summary of the lines of code being added, changed and deleted (since it uses SLOC and not LOC, there will be cases where changes only affected comments or white lines and hence they’ll show up as zero changes!).

You can sort the column and then check how many files have really “big changes” and it will have a positive effect on your mood and willingness to go through the entire list, which at the end of the day means increased productivity :-)

In my screenshot you can see how the selected file just contains a namespace change… which is not a big deal to review and in fact in my example this refactor affected more than 180 files out of 280, not bad.

This is the first step towards true “semantic multi-file diff” :-)

Find in files

Available since: 5.0.44.574 (Jun 6th 2014) and 5.4.12.575 (July 1st 2014).

Sometimes you’re diffing a branch and then you would like to find something (a method call, a given text or comment) inside the files being diffed.

That’s why we added “find in files” to the diff window: click on the new “find in files” button or “CTRL+SHIFT+F” and the following panel will show up:

You can enter the pattern to find, then decide whether you want to search in both sides or only one of them, select the extension or whether you want to select the search to the filtered files in the diff window.

And the results are displayed as follows:

With the occurrences of the left and right sides separated to ease the navigation.

In my case I was looking for the word “comment” and it is clearly more common before the change, which means the word was deleted from the file.

Our plan is to implement another feature on top: “search only in diffs” to restrict the search to the text blocks which were really modified. This is useful, for instance, to see if a certain method call has been really used in the new code or not.

Annotate each contributor

Available since: 5.0.44.577 (Jun 18th 2014) and 5.4.13.578 (Jun 26th 2014).

We added the option to launch the annotate from within the diff view so you can instantly see the detailed information about each line of each of the two sides of a diff.

I find it especially useful when going through complex merges: look at the screenshot above. Do you see the “Yes” at the end of the annotate? It means this line was modified during a merge. Which means the two contributors to the merge don’t contain the line but it was actually edited during the merge (at least prior to the checkin). This information is very useful to figure out what was really changed manually and what simply comes directly from one of the merge contributors.

As it happens with some of the other features explained in this blog post, this is just a first step. We’re working on more improvements to item merge tracking to be able to display on files in the “changed-changed” group exactly which lines come from merges or were modified on the branch.

Info about binary files

Available since: 5.0.44.592 (Aug 6th 2014) and 5.4.14.593 (Aug 8th 2014).

Sometimes you’re diffing a branch and there are binary files that can’t be diffed. So far we were just displaying a message telling “diff not available” (although you can CTRL+D to launch the external diff, for images for instance). Now we display useful metadata to understand the change:

The date and size and author are especially useful to understand what is going on with the file.

For images our plan is to embed the Image Diff here (check the gallery to find out more about the tool).



Update progress

September 17, 2014

The update operation is the responsible of downloading files and directories from the repository into your workspace. It can be a time consuming action if there’s a high number of files to be downloaded (or updated) or if the overall size is big. The equivalent to “update” in Plastic is “checkout” in SVN and Git jargon.

We added a new “update progress” so that when there’s a lot to be downloaded you get more precise feedback:

The progress is updated in 4Mb blocks which is the transfer unit we use. It can be a chunk of a big file or a group of small files summing up to 4Mb.

Availability

This feature is only available in version 5.4 (5.4.13.578 - Jun 26th 2014 and higher). 5.0 won’t get this one merged since the code is built on top of some other changes and improvements developed for 5.4 only.



Improved checkin progress

September 15, 2014

We’ve improved the way in which the checkin progress is handled in the GUI so that it shows more details when the data is transferred through a slow network.

The default checkin scale uses megabytes, but if the network is too slow (sometimes checking in data through the VPN) it is equivalent to not having progress at all.

What we’ve done is to add a secondary progress bar that shows up only when the transfer is too slow. The secondary bar shows the progress of each 4Mb block being transferred. Remember Plastic splits the checkins in 4Mb chunks. The chunks can be just parts of a large file or groups of small files.

The following screencast shows how it works on a network with changing speed (we use WAMEm to modify the network bandwidth and hence overall speed). The example is not realistic but it is helpful to explain the new feature:

Availability

The improved checkin progress has been available for a while, since:

  • 5.0.44.577 - Jun 18th 2014
  • 5.4.11.568 - May 19th 2014


SyncView revisited – improved performance

September 13, 2014

We’ve improved the performance and usability of the SyncView: it is now able to exclude branches making the sync process much faster.

As you know, the SyncView is the view in the GUI that you can use to preview what needs to be replicated between different servers and then run the replicas.

Excluded branches have been added to improve sync performance

We have added “excluded branches”: branches that you don’t want to sync between your repo and the remote one.

In my case I run a Plastic server on my laptop (using a SQLite backend handling about 18Gb) but I don’t have full replicas of the central repositories. I just pull the branches I need (to develop, code review or manually test tasks before getting them released). It means there are a few thousand branches on the remote server that I’ll never pull. Some of them are already years old.

Since the SyncView calculates all the changesets that need to be pushed or pulled in order to let you preview them, it started to get slow with thousands of branches.

That’s why we added the “excluded branches” feature.

You can select the branches you won’t be syncing and just “exclude them”. The result is that the sync view will be much, much faster, saving precious time on each loop.

We also added an option to show the “excluded branches” so that you can include them again in the calculation in case you need them later on (expanding the excluded branches is way much faster in 5.4 than in 5.0 since we implemented a new server API call in 5.4 to speed up the calculation, while 5.0 API is frozen and can’t take advantage of it).

New behavior in the “refresh” button

Previously the refresh button in the “sync view details” lower panel just affected the expanded repositories. While it wasn’t an issue when you worked with small lists, it wasn’t effective dealing whith long lists like this:

So from now on the “refresh” will trigger the calculation of the entire list of syncs instead of just the expanded ones, while you can still refresh them individually using the context menu.

New “push visible” and “pull visible” buttons

Especially when you’re using Xlinks it is very useful to use the filter to push (or pull) all the branches with a given name, in different repositories.

We’ve added two new buttons: “push visible” and “pull visible” to launch the pull or push of all the branches selected by the filter.

Underlying format change

All the SyncView configuration is stored on a file named syncviews.conf. We’ve modified the file format to make it human readable and better structured than it was before. It will be automatically upgraded by the new 5.0 and 5.4 releases so no user action is required.

Availability

This feature has been available since:

  • 5.0.44.592 (August 6th 2014) and later.
  • 5.4.14.593 (Aug 8th 2014) and later.


Real Time Web Analytics