Next: , Previous: Synchronising Databases, Up: Tutorial


2.10 Making Changes

Abe decides to do some work on his part of the code. He has a copy of Jim's database contents, but cannot edit any of that data yet. He begins his editing by checking out the head of the jp.co.juicebot.jb7 branch into a workspace, so he can edit it:

     $ mtn --db=abe.mtn --branch=jp.co.juicebot.jb7 checkout .

Monotone unpacks the set of files in the head revision's manifest directly into Abe's current directory. (If he had specified something other than . at the end, monotone would have created that directory and unpacked the files into it.) Abe then opens up one of the files, src/apple.c, and edits it:

     $ vi src/apple.c
     <Abe writes some apple-juice dispensing code>

The file src/apple.c has now been changed. Abe gets up to answer a phone call, and when he returns to his work he has forgotten what he changed. He can ask monotone for details:

     $ mtn diff
     #
     # old_revision [2e24d49a48adf9acf3a1b6391a080008cbef9c21]
     #
     # patch "src/apple.c"
     #  from [2650ffc660dd00a08b659b883b65a060cac7e560]
     #    to [e2c418703c863eabe70f9bde988765406f885fd0]
     #
     ============================================================================
     --- src/apple.c 2650ffc660dd00a08b659b883b65a060cac7e560
     +++ src/apple.c e2c418703c863eabe70f9bde988765406f885fd0
     @ -1,7 +1,10 @
      #include "jb.h"
     
      void
      dispense_apple_juice()
      {
     -  /* Fill this in please, Abe. */
     +  spoutctl(APPLE_SPOUT, FLOW_JUICE, 1);
     +  while (spoutctl(APPLE_SPOUT, POLL_JUICE, 1) == 0)
     +    usleep (1000);
     +  spoutctl(APPLE_SPOUT, FLOW_JUICE, 0);
      }

Satisfied with his day's work, Abe decides to commit.

     $ mtn commit
     mtn: beginning commit on branch 'jp.co.juicebot.jb7'

Abe neglected to provide a --message option specifying the change log on the command line and the file _MTN/log is empty because he did not document his changes there. Monotone therefore invokes an external “log message editor” — typically an editor like vi — with an explanation of the changes being committed and the opportunity to enter a log message.

     polling implementation of src/apple.c
     MTN:
     MTN: ----------------------------------------------------------------------
     MTN: Enter Log.  Lines beginning with `MTN:' are removed automatically
     MTN:
     MTN: format_version "1"
     MTN:
     MTN: new_manifest [b33cb337dccf21d6673f462d677a6010b60699d1]
     MTN:
     MTN: old_revision [2e24d49a48adf9acf3a1b6391a080008cbef9c21]
     MTN:
     MTN: patch "src/apple.c"
     MTN: from [2650ffc660dd00a08b659b883b65a060cac7e560]
     MTN:   to [e2c418703c863eabe70f9bde988765406f885fd0]
     MTN:
     MTN: ----------------------------------------------------------------------
     MTN:

Abe enters a single line above the explanatory message, saying “polling implementation of src/apple.c”. He then saves the file and quits the editor. Monotone deletes all the lines beginning with “MTN:” and leaves only Abe's short message. Returning to the shell, Abe's commit completes:

     mtn: committed revision 70decb4b31a8227a629c0e364495286c5c75f979

Abe then sends his new revision back to Jim:

     $ mtn sync
     mtn: connecting to jim-laptop.juicebot.co.jp
     mtn: finding items to synchronize:
     mtn:   certs |    keys | revisions
     mtn:       8 |       2 |         2
     mtn: bytes in | bytes out | revs in | revs out | revs written
     mtn:      615 |      2822 |       0 |        1 |            0
     mtn: successful exchange with jim-laptop.juicebot.co.jp

Beth does a similar sequence. First she syncs her database with Jim's:

     $ mtn --db=beth.mtn sync jim-laptop.juicebot.co.jp "jp.co.juicebot.jb7*"
     mtn: setting default server to jim-laptop.juicebot.co.jp
     mtn: setting default branch include pattern to 'jp.co.juicebot.jb7*'
     mtn: setting default branch exclude pattern to ''
     mtn: connecting to jim-laptop.juicebot.co.jp
     mtn: first time connecting to server jim-laptop.juicebot.co.jp:4691
     mtn: I'll assume it's really them, but you might want to double-check
     mtn: their key's fingerprint: 9e9e9ef1d515ad58bfaa5cf282b4a872d8fda00c
     mtn: warning: saving public key for jim@juicebot.co.jp to database
     mtn: finding items to synchronize:
     mtn: bytes in | bytes out | revs in | revs out | revs written
     mtn:     4601 |      1239 |       2 |        0 |            1
     mtn: verifying new revisions (this may take a while)
     mtn: bytes in | bytes out | revs in | revs out | revs written
     mtn:     4601 |      1285 |       2 |        0 |            2
     mtn: successful exchange with jim-laptop.juicebot.co.jp

She checks out a copy of the tree from her database:

     $ mtn --db=beth.mtn --branch=jp.co.juicebot.jb7 checkout .

She edits the file src/banana.c:

     $ vi src/banana.c
     <Beth writes some banana-juice dispensing code>

and logs her changes in _MTN/log right away so she does not forget what she has done like Abe.

     $ vi _MTN/log
     * src/banana.c: Added polling implementation

Later, she commits her work. Monotone again invokes an external editor for her to edit her log message, but this time it fills in the messages she's written so far, and she simply checks them over one last time before finishing her commit:

     $ mtn commit
     mtn: beginning commit on branch 'jp.co.juicebot.jb7'
     mtn: committed revision 80ef9c9d251d39074d37e72abf4897e0bbae1cfb

And she syncs with Jim again:

     $ mtn sync
     mtn: connecting to jim-laptop.juicebot.co.jp
     mtn: finding items to synchronize:
     mtn:   certs |    keys | revisions
     mtn:      12 |       3 |         3
     mtn: bytes in | bytes out | revs in | revs out | revs written
     mtn:      709 |      2879 |       0 |        1 |            0
     mtn: successful exchange with jim-laptop.juicebot.co.jp