Presentation is loading. Please wait.

Presentation is loading. Please wait.

Revision Control with TortoiseHg

Similar presentations


Presentation on theme: "Revision Control with TortoiseHg"— Presentation transcript:

1 Revision Control with TortoiseHg
Team version (Team use) CS2103 – Software Engineering Prepared by: Steve Teo Contributors: Tong Huu Khiem

2 Before we begin… Notes clarify things and provides more in-depth knowledge These gray boxes have notes inside These instructions is tested with version of TortoiseHg Red box means instructions. Follow them. Red, bold text are important things.

3 Moving on from individual use…
Version control is important for an individual developer. Regular revision control helps a developer manage his/her code, increasing productivity. The Mercurial Revision Control System offers the advantage of having a local repository With a local repository, commits and other repository operations can be done offline at any time. Developers, especially those who have used RCSs such as Subversion (which lacks the local repository feature), will find regular versioning with Mercurial a joy, not chore. However, you have yet to fully utilize the capabilities of a Revision Control System if you’re using it alone.

4 … to team use of a RCS RCS is used to manage the codebase of software development projects (which consists of teams of developers) in the industry, making it crucial to learn how to use it properly now. The Mercurial Revision Control System is fully capable of supporting team projects. Adopting a RCS for team use requires the establishment of a workflow and making sure team members follow it. In this first part, we shall learn a workflow to get a good grasp of it before proceeding with the practical itself.

5 Objectives Learn a single team repo model
Role of the team repository Basic team workflow Putting everything into practice Setup a Google Code Repository Checkout a remote repository Sync a local repository with a remote repo Configure username for identity purpose Push changesets Pull-Update changesets Merge changesets Resolve merge conflict Unleash Mercurial’s full power

6 Single Team Repo Model

7 Team Leader’s Local Repo
The missing link Every team member will have their own local repository. However, there is no mechanism yet to share code changes with one another. Team Leader’s Local Repo Member A’s Local Repo Team Leader Member A Member C’s Local Repo Member B’s Local Repo Member C Member B

8 Single Team Repo Model Team’s Central Repo Leader’s Local Repo
Member A’s Local Repo Team Leader Member A Member C’s Local Repo Member B’s Local Repo Member C Member B

9 Single Team Repo Model In the Single Team Repo Model, there is a central (remote) repository owned by the team Team members download (‘pull’) and upload (‘push’) changes between their own local repositories and the central repository. A team member’s local repository cannot share changes directly with other members’ local repositories. Developers can choose to push their changes to the central repository only when they are confident of their changes. Thus, it is not guaranteed that the central repository will always have the latest code. However, it is expected to contain the latest stable code.

10 Basic team workflow

11 Push Team’s Central Repo Member A’s Local Repo push changes
Update your changes from the local repo to a remote repo Member A’s Local Repo Team’s Central Repo push changes Touch on Commit and Push

12 Revision/changeset A revision is the set of changes whenever a push is performed. Each revision is given a number. A revision is also known as a changeset. In this tutorial, we will use both terms interchangeably. A revision contains other important information such as the author of the changes and the summary of each change. Each successful commit will result in a new revision. Each revision will definitely have one or more revision for its parent except for the first revision, which will have zero.

13 Pull Team’s Central Repo Member A’s Local Repo pull changes
Retrieve new changes from the remote repo to your local repo Member A’s Local Repo Team’s Central Repo pull changes Commit and Push, Commit and Push

14 Member A’s Working Copy
Update/Merge Pulling changes only retrieves changes from the remote repository into the local repository. However, the working copy is not updated in a Pull operation. You need to update the working copy to the latest version by using the Update command. If there are multiple heads (i.e. same file modified by multiple persons), you need to use the merge command instead. Member A’s Local Repo Member A’s Working Copy Commit and Push, Commit and Push update

15 Pull+update? There are a few ways of doing a pull and update in one shot. In Step 3 of “Putting everything into practice”, we will show you how you can set up such behavior using TortoiseHg itself. For the command line folks, you can use the hg fetch command to do pull and update in one shot (need to enable the fetch extension first).

16 Pulling and pushing (Diagram)
Member B Member B’s Local Repo Member A Member A’s Local Repo 2. push changes 3. Tells him to pull 1. makes some changes and commit Team’s CentralRepo 4. pull and merge

17 Pulling & pushing (explanation)
In the above model, Member A commits some changes and pushes them to the Central Repository. Member A then informs the team to pull his changes off the Central Repository. Member B decides to do so and merges the changes from the Central Repository into his own repository. If any other member wishes to have the latest stable code, all they have to do is to pull off the Central Repository.

18 Putting everything to practice

19 Setup a Google Code Repository
Step 1 Setup a Google Code Repository

20 Setup a Google Code Repository
In this guide, we shall use the excellent open source hosting site Google Code as an example. There are other Mercurial repository-hosting sites such as BitBucket at https://bitbucket.org/, which offers free repositories with various features and restrictions.

21 Setup a Google Code Repository
Sign up for a new project at Choose Mercurial as your version control system

22 Setup a Google Code Repository
Go to Source tab -> Checkout Remember to note down the repository URL Take note of your repository URL And your password (this is different from your Gmail password)

23 Setup a Google Code Repository
You need this password to push changeset to Google Code You can access all the project you have here

24 Setup a Google Code repository
Browse the code in your repository by going to Source tab-> Browse Files will shows up as you commit code

25 Setup a Google Code repository
View all the changes in your project by going to Source tab-> Changes A commit graph will shows up as you commit code

26 Setup a Google Code repository
Add your team members as owners or committers under the Administer tab -> Sharing s of your team members go here

27 Setup a Google Code repository
You can configure it to send activity notifications to your Google group under Administer tab-> Source Add your team’s google group here

28 Step 2 Clone a repository

29 Right-click on a new folder and select TortoiseHg - Clone
Clone a repository If you already have an existing repository of the project on Google Code (set up by one of your team members), you can clone it from the Google Code repository to your hard disk. Otherwise, skip to Step 3 Right-click on a new folder and select TortoiseHg - Clone

30 Clone a repository Cloning allows you to duplicate the entire repository, copying all the existing contents to the destination as well as the whole revision history. Paste the Google Code repo URL here. This slide explains where to find the Google code repo URL.

31 Sync a local repository with a remote repo
Step 3 Sync a local repository with a remote repo

32 Sync a local repository with a remote repo
If you have an existing local repository, you can also configure it to sync with the repo on Google Code Click Synchronize

33 Sync a local repository with a remote repo
Add the Google Code repository URL as the default path Choose https Use “code.google.com” Use the relative URL Save Use “default” for alias

34 Sync a local repository with a remote repo
You can also configure Post-Pull behavior for repositories Select Post Pull Update option will make TortoiseHg automatically update your repository whenever you pull some change

35 Configure username for accountability
Step 4 Configure username for accountability

36 Configure username for accountability
In a team setting, you need to identify yourself when committing so that you and your teammates know what you committed Select a repository and choose Repository Settings

37 Configure username for accountability
Unser Commit group, enter the username & that you want to associate your commits with Use “name < >” here

38 Configure username for accountability
You can also set the username in the global settings. If there are no repository-specific settings specified, Mercurial will use the global settings. This affects every repository on your computer

39 Configure username for accountability
From now on, your name will show up in subsequent commits This commit username can be different from your Google Code username Commits now have the author which you have just specified

40 Step 5 Push changeset

41 Right click on your local repo and choose Hg Workbench
Push changesets After making some commits to our local repository, we are ready to push all of them into our Central Repository for the first time. Right click on your local repo and choose Hg Workbench

42 Click here to preview which changes will be going to the repo
Push changesets In Hg Workbench, we will first preview the commits that are to be pushed. Click here to preview which changes will be going to the repo Click Detect outgoing changes. This will compare the local and remote repository, finding changes to be pushed

43 These are the changes that is going to be pushed
Push changesets TortoiseHg will find all the changes that need to be pushed Click Push to upload these to Google Code These are the changes that is going to be pushed

44 Push changesets Then you will need to authenticate TortoiseHg to reach your Google code repository Enter your Google code username

45 Push changesets And your Google code password, as well. This is not your Google password. This slide explains where to get this password. Enter your Google Code password

46 Push changesets If the commits are pushed successfully, there will be no errors. You can look at the output log for more info in any case. Success 

47 This directly push changes, without checking. Not recommended for now
Push changesets You can also do a quick verification of the success of your commits by detecting changes for pushing again This directly push changes, without checking. Not recommended for now Click here Your commit was pushed

48 Push changesets Go to your Google code repository, check the Source tab-> Changes You should see that your commits were pushed successfully here

49 Push changesets If you find it a chore to enter your login details every time you push changes or pull from a private repository which you have pull access from, you can store your login details using TortoiseHg. Click “Synchronize” to open the sync panel at the bottom Click on the lock to open the security panel Key in your Google account details

50 Pull & Update changeset
Step 6 Pull & Update changeset

51 Again, open Hg Workbench
Pull & update changes Let’s say Greg have pushed his code. Now his friend, Holly decides to pull the changes into her currently empty local repository. Again, open Hg Workbench

52 Pull & update changes In Hg Workbench, you can check for new changes from repository Check for changes from Google Code

53 Click to download changes below
Pull & update changes When new changes are detected, you can accept and download them Click to download changes below

54 Pull & update changes The changes have been pulled into the local repository. However, we still need to update the working copy to the latest changes. This means there are changes that is more up-to-date (2 and 3). You will need to update

55 Pull & update changes You can update in Hg Workbench or right-click on the repository and use the popup menu Click Update to open the update dialog

56 Pull & update changes Use the default option to update to the latest changes

57 Pull & update changes Here’s the view after the update.

58 Pull & Update changes Finding it so troublesome to pull and then update? You can configure TortoiseHg to update for you by simply configuring the Post-Pull behavior as listed in Step 3: Sync a local repository with a remote repo Summary: Pulling only pulls the changesets into the local repository. You still need to update the working copy with the new changesets. Keep repeating this to yourself: Pull and Update

59 Step 7 Merge changesets

60 Merge changesets You may encounter this common scenario Greg pushed his code to the repository. Then Holly & Rowley pulled and updated Greg’s code. Rowley then made some changes, committed and pushed them. Meanwhile, Holly also made her own changes and was about to push the code. This can be summarized in the following timeline

61 Team Repository (Google Code)
Merge changeset Team Repository (Google Code) Pushed Greg Pulled & Updated Commit new code Pushed Rowley Pulled & Updated Commit new code Try to push Holly time

62 Merge changesets In this situation, Rowley can’t push. He must merge his changes with Holly’s This is how Google Code look like after Rowley has pushed his code

63 Merge changesets Here, Holly check her code and detected one that need to be pushed

64 Merge changesets When she push, however, there was an error. This is because she needs to pull Rowley’s code first

65 Merge changesets Holly proceeds to pull Rowley’s code, seeing one changeset

66 The newly pulled changeset
Merge changesets After Holly have pulled Rowley’s code, the repository look like this Now, she need to merge her changes (4) with Rowley’s (5) The newly pulled changeset

67 Merge changesets Holly first select Rowley’s change and proceed with the merge Use Merge with local… to merge the new incoming changesets with yours

68 Merge changesets A summary of the upcoming merge is displayed on the 1st step of the merging process.

69 Merge changesets Mercurial proceeds to merge and the merge results are shown on the 2nd step of the merging process.

70 Merge changesets The process of Merging must be finalized with a commit to save the merge on the 3rd step of the merging process.

71 The commit for the merge
Merge changesets The merge is done. Holly will now need to push the finalized merge commit back to the repository on Google Code The commit for the merge

72 Merge changesets The merge commit and Holly’s own commits earlier are marked for pushing

73 Merge changesets And then they’re pushed to the remote repository

74 Merge changesets Has this whole section been mind-boggling? Remember, the goal of merging is to combine changes between changesets. Once the merge is complete, it has to be committed and then pushed back to the remote repository. Summary of merging steps : Pull the incoming changesets from the remote repository Merge the latest incoming changeset with the local working copy Commit the merge into the local repository Push the merge back to the remote repository Find out more about Mercurial’s merging: work.html

75 Resolve merge conflict
Step 8 Resolve merge conflict

76 Resolve merge conflict
The merging scenario which was described in Step 7 is an example of a happy flow. There were no merge conflicts and this should be the case most of the time. In some cases, a merge conflict can result when two people were working on the same file and decided to commit their changes. When Mercurial merges both of their work, it realizes it cannot do so automatically on its own and thus requires intervention from the one who initiates the merge. Merge conflicts are settled by a user selecting which portion of the changed code should be in the finalized file. Merge conflicts can be avoided in Software Projects through proper software engineering and individual ownership of classes. However, should such a conflict occur, Mercurial is capable of handling it.

77 Resolve merge conflict
Let’s look at a more specific example: Rowley and Holly both started with the same code. Rowley then edited one file, committed and pushed it. At the same time, Holly also edit that file, committed and was about to push it. This creates a situation where Holly need to merge her changeset and Rowley’s, as we have seen in the last section about merge Normally, if Holly and Rowley change different files, say file A for Rowley and file B for Holly, TortoiseHg will automatically merge, using the newer version of file A from Rowley and a newer version of file B from Holly However, since they both change one file, TortoiseHg can’t figure out whose version to use. This situation causes a merge conflict

78 Create version A of project.txt Create version B of project.txt
Merge changeset One file, project.txt for example Pulled & Updated Commit new code Pushed Create version A of project.txt Holly Pulled & Updated Commit new code Try to push Create version B of project.txt Rowley time

79 Resolve merge conflict
In this real example, Rowley and Holly started from Holly’s version of the code, where she add Stylizer.h and Stylizer.cpp They both started from this revision

80 Resolve merge conflict
Both Rowley and Holly decides to edit these files in their own way Stylizer.h Stylizer.cpp Added a function called Stylize [Stylizer.h], add: void Stylize(fstream one_file); [Stylizer.cpp], add: void Stylizer::Stylize(fstream one_file) { }; Added a function called Style_file void Style_file(fstream one_file); void Stylizer::Style_file (fstream one_file)

81 Resolve merge conflict
Holly has edited the file and pushed her changeset to Google Code Holly’s new changeset

82 Resolve merge conflict
While pushing his commit, Rowley got an error Then he proceeds to do a pull

83 Resolve merge conflict
After Rowley pulled, he saw that Holly have one changeset that he doesn’t Now he need to merge his change with Holly’s The changeset Rowley pulled

84 Resolve merge conflict
Again, this is done using the Merge with local option Use Merge with local… to merge the new incoming changesets with yours

85 Resolve merge conflict
A dialog box shows up, summarizing the upcoming merge

86 Resolve merge conflict
However, a conflict showed up while merging Rowley now need to resolve this before continuing Click here to resolve the merge conflict

87 Resolve merge conflict
The Resolve conflicts dialog shows up Actions: Mercurial Resolve – Let Mercurial resolve it automatically (trivial) Tool Resolve – Let the default merge tool resolve it Take Local – Takes the version of the file in local working copy. Take Other – Take the other version of the file which is not the local working copy. Mark as Resolved – Marks the file as resolved

88 Resolve merge conflict
For example, if you use Tool Resolve, TortoiseHg will launch kidff3 and you can resolve the conflict there

89 Resolve merge conflict
After all conflicts are resolved, close the dialog box and commit the merge, similar to Step 7: Merge changeset

90 Resolve merge conflict
And this is how it is in Google code repository The conflicted merge

91 Resolve merge conflict
The example above was the resolution of a simple merge conflict. Even though Jane and Steve edited the same file, their changes were on different lines. Mercurial or the default Diff program was smart enough to resolve it automatically on its own. Therefore, Steve did not need to choose which changes he wanted. In other complex cases, you and your team mates could have edited the same section of code. In those cases, you have to use the Diff program to select which sections of code you want in the final merged code.

92 Unleash Mercurial’s full power

93 Centralized Revision Control System
So far, you were introduced to a simple Single Team Repo Model. That model is an adaptation of the Centralized model supported by a group of RCS called Centralized Revision Control Systems (CRCS for short), of which the most notable is Subversion (SVN for short). In CRCS, there is a central repository hosted on a remote server but no local repositories. Developers synchronize changes directly to the central repository and a network connection is required for most repository operations.

94 Centralized Model Team’s Central Repo Team Leader Member A Member C
Compare this with the Central Repository Model on this slide. Team Leader Member A Team’s Central Repo Member C Member B

95 Distributed Revision Control System
Mercurial belongs to a group of RCS known as Decentralized Revision Control Systems (DRCS), which includes Git. DRCS uses the Decentralized Model: repositories are decentralized and repository configuration is flexible. Hence the workflow can vary differently from team to team. In the general model, every team member has his/her own remote repository in addition to their own local repository. There is no such thing as the central repository.

96 Pulling & Pushing in Decentralized Model
Member B Member B’s Local Repo Member A Member A’s Local Repo Member A’s Hosted Repo 1. pull and merge 3. push changes 4. sends pull request 2. makes some changes and commit Member B’s Hosted Repo 5. pull and merge 6. push changes

97 Pulling & Pushing in Decentralized Model
You can see that Member A pulls the latest changes off Member B’s hosted repository and merges the changes with his local repository. Now that his local repository is updated, he then commits his own changes and pushes them to his hosted repository. Member A then informs the team to pull his changes off his hosted repository. Member B decides to do so and merges the changes from Member A’s hosted repository into his own local repository. Each of the members does not pull off from one another’s local repository. Instead, they pull off changes from one another’s hosted repository.

98 Advantages of DRCS in brief
Presence of the local repository allows you to commit code and push the changes only when you are ready No need for an Internet connection to commit changes or access your local repository, which means full benefits of version control anytime anywhere. Flexible organization of repositories as workflow does not always have to be centralized You can choose whether or not to pull from repositories and condemn your friend’s buggy code until it is fixed. And many many more…


Download ppt "Revision Control with TortoiseHg"

Similar presentations


Ads by Google