Performing Historical Buildings Using Mercurial

Background

We use a central repository model to coordinate the presentation of code between all the developers on my team. Our automatic nightly build system shuts off the code every 3am every day when it pulls the latest code from the central repo into its own local repository.

A few weeks ago, an assembly was completed that included Revision 1 of the repo. At that time, the build system in no way tracked the revision of the repository that was used to complete the build (now this happens, fortunately).

-+------- Build Cut-Off Time | | O Revision 1 

An hour before the build shutdown, the developer separated from the repository and made a new revision in his local copy. They did not bring it to the central repo until the cutoff, and therefore it was not included in the assembly. This will be Revision 2 in the chart below.

  -+------- Build Cut-Off Time | | O Revision 2 | | | | |/ | O Revision 1 

An hour after the build, the developer pushed his changes back to the central repo.

  O Revision 3 |\ | | -+-+----- Build Cut-Off Time | | | O Revision 2 | | | | |/ | O Revision 1 

So, in editor 1, it was introduced into the assembly, while changes in revision 2 would be included the next morning (as part of revision 3). So far so good.

Problem

Now, today, I want to restore the original assembly. It would seem obvious steps for this -

  • determine the version that was in the original assembly,
  • update this revision and
  • complete assembly.

The problem is step 1. If there is no separately registered revision of the repository, how can I finally determine which repo revision was used in the original assembly? All revisions are in the same branch and no tags are used.

log command

  hg log --date "<cutoff_of_original_build" --limit 1 

gives Version 2 - not option 1, which was in the original assembly!

Now I understand why he does it. Version 2 is now the version closest to the cutoff time for the assembly, but this does not change the fact that I could not determine the correct version for which I had to rebuild.

Thus, if I cannot use the --date parameter of the log command to find the correct historical version, what other tools are available to determine the correct one?

+6
source share
3 answers

Sorry, this is probably a bad form to answer your own question, but there wasn’t enough room for the correct answer in the comment field.


Joel, a couple of things:

At first - and I mean it sincerely - thanks for your reply. You provided an option that was considered, but which was ultimately rejected, because it would be too difficult to apply to my build environment.

Secondly, you have a little preaching there. In this matter, it was clear that since there was no separate revision record for the repository, there would be “some effort” to figure out the correct revision. In response to Lance's comment (above), I agree that writing a 40-byte repository hash is the “right” way to archive the necessary assembly information. However, this question concerned what to do CAN if you do not have this information.

To be clear, I posted my question to StackOverflow for two reasons:

  • I figured that others should have come across this situation earlier and maybe someone might have identified the means to get the necessary information. Thus, it was worthy of attention.
  • Information exchange. If someone encounters this problem in the future, they will have an online link that clearly explains the problem and discusses viable fix options.

Decision

In the end, maybe my biggest thanks must have come to Chris Morgan, who made me think about using a central mercurial-server log server . Using these logs and some scripts, I was able to finally determine the set of revisions that were transferred to the central repository during the build. So, thanks to Chris and everyone who answered.

+1
source

Given what kind of history may have been in the undo files, has already disappeared (the only thing I can think of that can give an indication), I think the only way to narrow it down to a specific revision is the brute force approach.

If the range of possible revisions is a little large, and making changes to the building in size or another non-flying aspect, linear or close to linear, you can use bisect to basically perform a binary search to narrow down which revision you are looking for (or maybe just get closer to her). For every revision that bisect stops testing, you should build this revision and test any aspect that you use to compare with what was planned for that night. May not even require construction, depending on the test.

If it is really as simple as the graph you are depicting and the range of possibilities is short, you can simply start with the latest version, which it may be, and go back a few changes by testing the original assembly.

As for the final test comparing two assemblies, hashing of the test assembly and comparing it with the hash of the original assembly may work. If compiling the assembly machine on the night machine and compiling the same revision on your machine does not create binary identical assemblies, you may need to use binary differences (for example, with xdelta or bsdiff ) and find the smallest diff.


Mercurial does not have the necessary information:

Mercurial does not make a journal from its article and monitors all actions performed in relation to the repository, such as push , pull , update . If this were so, it would create a lot of registration information. It makes hooks available that you can use to do this if you wish.

It also doesn’t matter what you do with the contents of the working directory, for example, opening files or compiling, so of course it will not track this at all. This is simply not what Mercurial does.

It was a mistake not to know exactly how the planned assembly was built. You agree implicitly, because now you are registering this very information. The lack of this information earlier simply returned you to bite you, and there is no easy way out of this. Mercurial does not have the necessary information. If the central repo is only a shared directory, and not a repository hosted on the Internet that can track activity, the only information about what was built is in the compiled version. Whether this is some metadata declared in the source that becomes part of the assembly, a naive aspect like file size, or are you really stuck hashing files, you cannot get the answer without any effort.

You may not need to check every revision; there may be changes that you can be sure are not candidates. Knowing compilation time is simply a factor as the upper limit of the test revision range. You know that changes after this time could not be candidates. What you do not know is what was pressed on the server at the time the build server pulled it out. But you know that changes from this day are most likely. You also know that changes in parallel unnamed branches are less likely candidates than linear changes and merges. If there are many parallel unnamed branches, and you know that all your developers merge in a certain way, you can know if revisions should be tested under parent1 or parent2.

You may not even need to compile if there is metadata that you can parse from the source code to compare with what you know about a particular assembly.

And you can automate the search. It would be easier to do this with linear search: less heuristics for design.

The bottom line is that Mercurial does not have a magic button to help in this case.

+6
source

As Joel said, this is not possible. However, there are certain solutions that may help you:

  • maintain database of changes in the night version (date + changeet id)
  • the build server can automatically flag the revision it is based on (nightly /)
  • switches to Bazaar, it manages version numbers differently (branched versions are in the form REVISION_FORKED.BRANCH_NUMBER.BRANCH_REVISION , so your change number 2 will be 1.1.1
0
source

Source: https://habr.com/ru/post/891683/


All Articles