Push and pull

Reference Information:

I used Mercurial myself as a single user to track the changes that I made to my own code, and I think I'm familiar with the basic principles. However, now I am going to start working on a software project with someone else in my laboratory and want me to understand how to properly exchange codes with someone else using Mercurial.

Our situation is this: we have our own repository in the general volume (that is, different paths) in the Linux cluster, and we both have read and write access to our and each other's repositories.

We can name these two repositories: Bob and Alice repositories for discussion.

My understanding is that there are several ways to share Bob and Alice with their code, two of which are as follows:

Option 1: Pull Sharing

  • Bob pulls away from Alice whenever he wants to see her change.
  • Similarly, Alice pulls from Bob when she wants to see his changes.

Option 2: Click Sharing

  • Bob pro-active pushes his changes to Alice's repository whenever he wants to share his changes with her.
  • Similarly, Alice actively pushes her changes to Bob's repository when he wants to share her changes with her.

Questions:

My interpretation from reading Mercurial documentation and tutorials on the Internet is that the first option above is usually preferable to the second. One question I have is why?

Can the second option above lead to any problems? What happens if Bob commits to her repository, while Alice also pushes her changes simultaneously to Bob's repository?

thanks

+6
source share
3 answers

It either works, and in the end it really does not matter, because pushing / pulling does not update or merge to the recipient - it just moves the changeset to the base repo, and not to the working directory.

The first option, pulling, is most often performed, because:

  • usually you don’t have write access to other repositories (and probably shouldn't), and pulling along you need read-only access to each other's repositories
  • when you click revisions to someone, there is no notification that they received new changes. They will not detect it until hg summary (or hg heads or hg log ) starts, and then they will have to hg merge . That way, while the recipient has to take an explicit action (validation and merge) to receive your changes, they can simply pull and merge. This no longer works for them and less for you.

As others have pointed out, writing in repository mode will prevent push or pull from being performed during incoming operations.

+4
source

From what I read about the Hg file model, it handles simultaneous recording elegantly, so file corruption is not a problem.

The problem is with the workflow. There is no "simultaneous" because a later write operation will be locked until the previous write operation is completed. If Bob completes the transaction earlier, then Alice push (by default) fails because he will create a new head. She would have to push to create a new head in Bob repo, and then he would have to combine them. Or she can pull Bob out and drain, then press. If Alice push is earlier, then Bob commit will go through, creating a branch that it will have to merge. In any case, the merger should happen. What I don't like about this approach is that Bob will now be surprised by these new changes in his repo and he will have to do an hg update to bring them to his working copy anyway.

The model that we use in our team of 4 is to have a central repo from which everyone pulls / pushes. In addition, our CI server launches automatic builds. It works pretty smoothly for 11 months.

+2
source

Mercurial handles both scenarios easily. For me, the option is preferable, because it is easier to maintain. What if Alice does not want Bob to enter her repo? Then she has to worry about pushing him off. Where, as if Alice wants to pull Bob’s change, she clearly agreed to the craving and, as a result, the merger, and expects this. Most likely, she will be pulled into a separate repo before merging with her main repo to make sure that she really wants to integrate her changes.

Maybe it's just me, but interpreting the changes on someone else seems dirty. I would rather let them know that an update is available, and if they are interested, they can extract the changes from you.

As the saying goes, the way we manage here in the office is to force most of the codes to a central repo, to which everyone has access. Once it is approved through a code review, these changes will go into our real repo and become available to everyone else. Only in rather rare cases, developers directly pushed the code towards each other, and this usually happens when they closely interact with the same function.

+2
source

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


All Articles