?? x6950.htm
字號(hào):
<HTML
><HEAD
><TITLE
>CVS notification</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Messages, Presence, and Presence Subscription"
HREF="c6941.htm"><LINK
REL="PREVIOUS"
TITLE="Messages, Presence, and Presence Subscription"
HREF="c6941.htm"><LINK
REL="NEXT"
TITLE="Dialup system watch"
HREF="x7229.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c6941.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 7. Messages, Presence, and Presence Subscription</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x7229.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-7-SECT-1"
>CVS notification</A
></H1
><P
>CVS—the Concurrent Versions System
<A
NAME="AEN6953"
HREF="#FTN.AEN6953"
>[1]</A
>
—allows you to comfortably
create and manage versions of the sources of your project. The most common
use for CVS is to create and manage versions of program source code, but
it can be readily used for any text files. For example, this book was
written using the DocBook markup language
<A
NAME="AEN6956"
HREF="#FTN.AEN6956"
>[2]</A
>
and CVS was used to take versions of the manuscript at certain points
in the writing's progress. The versions so taken could be compared, and old
versions could be retrieved. </P
><P
>That's the <I
CLASS="EMPHASIS"
>Versions System</I
> part of the name. The
<I
CLASS="EMPHASIS"
>Concurrent</I
> part means that this facility is given
an extra dimension in the form of group collaboration. With CVS,
more than one person can share work on a project, and the various chunks
of work carried out by each participant are coordinated—automatically,
to a large extent—by CVS. Multiple changes by different people to
the same file can be merged by CVS; any unresolvable conflicts (which may
for example arise when more than one person changes exactly the same line
of source code) are flagged and must be resolved by the participants
involved.</P
><P
>The general idea is that you can create a project containing files and
directories and have it stored centrally in a CVS
<I
CLASS="EMPHASIS"
>repository</I
>. Depending on what sort of access is
granted to this repository, other project participants can pull down a
copy of the
project—those files and directories—and work on it
independently. In this way, each participant's work is isolated (in time
and space) from the others. When the work is done, the work can be
sent back to the repository and the changes will be merged into the
central copy.
After that, those merged changes are available to the rest of the
participants.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-7-SECT-1.1"
>CVS watches and notification</A
></H2
><P
>While CVS automatically handles most of the tedious merging process
that comes about when more than one person works on a project, it also
offers a facility which allows you to set a "watch" on one or more
files in the project, and be alerted when someone else starts to work
on those watched files. This is useful if you wish to preempt any automatic
merging process by contacting the other participant and coordinating
your editing efforts with them.</P
><P
>There are two CVS commands involved in setting up watches and notifications.
There are also a couple of CVS administrative files that determine how the
notifications are carried out. Let's look at these commands and files in
turn.</P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="JABTDG-CH-7-SECT-1.1.1"
>CVS commands</A
></H3
><P
>The CVS commands <B
CLASS="COMMAND"
>cvs watch</B
> and <B
CLASS="COMMAND"
>cvs notify</B
>
are used, usually in combination, by project participants to set up the
notification mechanism.</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><B
CLASS="COMMAND"
>cvs watch on|off</B
></DT
><DD
><P
>Assuming we have a CVS-controlled project called
'<I
CLASS="EMPHASIS"
>proj1</I
>', and we're currently inside our local
checked-out copy of the project's files, we first use
<B
CLASS="COMMAND"
>cvs watch</B
> to tell CVS to watch a file ("turn a watch
<I
CLASS="EMPHASIS"
>on</I
>") that we're
interested in, which is <TT
CLASS="FILENAME"
>file4</TT
> in this example:</P
><P
><PRE
CLASS="SCREEN"
>yak:~/projects/proj1$ <TT
CLASS="USERINPUT"
><B
>cvs watch on file4</B
></TT
></PRE
></P
><P
>This causes CVS to mark <TT
CLASS="FILENAME"
>file4</TT
> as "watched", which
means that any time a project participant checks out the file from the
central repository, the checked-out working copy is created with read-only
attributes. This means that the participant is (initially) prevented from
saving any changes to that working copy. It is, in effect, a reminder
to that participant to use the CVS command <B
CLASS="COMMAND"
>cvs edit</B
>,
specifying <TT
CLASS="FILENAME"
>file4</TT
>, before commencing the edit session.
Using <B
CLASS="COMMAND"
>cvs edit</B
> will cause CVS to:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>remove the read-only attribute for the file</P
></LI
><LI
><P
>send out a notification that the participant has
commenced editing it.</P
></LI
></OL
></DD
><DT
><B
CLASS="COMMAND"
>cvs watch add|remove</B
></DT
><DD
><P
>While running <B
CLASS="COMMAND"
>cvs watch on</B
>
against a file will set a
marker causing the file to be replicated with the read-only attribute
when checked out (which has the effect of "suggesting" to the participant
editing the file that he
use the <B
CLASS="COMMAND"
>cvs edit</B
> command to signal that he's to start
editing), the actual determination of the notification recipients is
set up using the <B
CLASS="COMMAND"
>cvs watch add</B
>
command. </P
><P
>Running the command:</P
><P
><PRE
CLASS="SCREEN"
>yak:~/projects/proj1$ <TT
CLASS="USERINPUT"
><B
>cvs watch add file4</B
></TT
></PRE
></P
><P
>will arrange for the CVS notification to be sent to <I
CLASS="EMPHASIS"
>us</I
>
when someone else signals their intention (via <B
CLASS="COMMAND"
>cvs edit</B
>)
to edit <TT
CLASS="FILENAME"
>file4</TT
>.</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="JABTDG-CH-7-SECT-1.1.2"
>CVS administrative files</A
></H3
><P
>Kept in the central CVS repository are a number of administrative files
that are used to control how CVS works. Two of these files,
<TT
CLASS="FILENAME"
>notify</TT
> and <TT
CLASS="FILENAME"
>users</TT
>, are used to
manage the watch-based notification process.</P
><P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="FILENAME"
>notify</TT
></DT
><DD
><P
>The standard <TT
CLASS="FILENAME"
>notify</TT
> file contains a line like this:</P
><P
><PRE
CLASS="SCREEN"
>ALL mail %s -s "CVS notification" </PRE
></P
><P
>The '<TT
CLASS="LITERAL"
>ALL</TT
>' causes the formula described here to be
used for any notification requirements (an alternative to
<TT
CLASS="LITERAL"
>ALL</TT
> is a regular expression to match the directory
name in which the edit causing the notification is being carried out).</P
><P
>The rest of the line is the formula to use to send the notification.
It is a simple invocation of the <B
CLASS="COMMAND"
>mail</B
> command,
specifying a subject line (<TT
CLASS="LITERAL"
>-s "CVS notification"</TT
>).
The <TT
CLASS="LITERAL"
>%s</TT
> is a placeholder that CVS replaces with the
address of the notification's intended recipient. The actual notification
text, generated by CVS, is piped into the <B
CLASS="COMMAND"
>mail</B
> command
via STDIN.</P
></DD
><DT
><TT
CLASS="FILENAME"
>users</TT
></DT
><DD
><P
>The <TT
CLASS="FILENAME"
>users</TT
> file contains a list of notification
recipient addresses:</P
><P
><PRE
CLASS="SCREEN"
>dj:dj.adams@pobox.com
piers:pxharding@ompa.net
robert:robert@shiels.com
...</PRE
></P
><P
>This is a mapping from the user IDs (<TT
CLASS="LITERAL"
>dj</TT
>,
<TT
CLASS="LITERAL"
>piers</TT
>, and <TT
CLASS="LITERAL"
>robert</TT
>) of the
CVS participants, local to the host where the CVS repository is
stored, to the actual addresses (<TT
CLASS="LITERAL"
>dj.adams@pobox.com</TT
>,
<TT
CLASS="LITERAL"
>pxharding@ompa.net</TT
>, and
<TT
CLASS="LITERAL"
>robert@shiels.com</TT
>) that are
used to replace the <TT
CLASS="LITERAL"
>%s</TT
>
in the formula described in the <TT
CLASS="FILENAME"
>notify</TT
> file.</P
></DD
></DL
></DIV
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="JABTDG-CH-7-SECT-1.1.3"
>The Notification</A
></H3
><P
>If the contents of the <TT
CLASS="FILENAME"
>notify</TT
> and
<TT
CLASS="FILENAME"
>users</TT
> files have been set up correctly,
a typical notification, set up by <I
CLASS="EMPHASIS"
>dj</I
> using
the <B
CLASS="COMMAND"
>cvs watch on file4</B
>
and <B
CLASS="COMMAND"
>cvs watch add file4</B
> commands, and triggered
by <I
CLASS="EMPHASIS"
>piers</I
> using the <B
CLASS="COMMAND"
>cvs edit file4</B
>
command, will be received in <I
CLASS="EMPHASIS"
>dj</I
>'s inbox looking
like the one shown in <A
HREF="x6950.htm#JABTDG-CH-7-FIG-1"
>Figure 7-1</A
>.</P
><DIV
CLASS="FIGURE"
><A
NAME="JABTDG-CH-7-FIG-1"
></A
><P
><B
>Figure 7-1. A typical email CVS notification</B
></P
><PRE
CLASS="SCREEN"
>Date: Fri, 8 Jun 2001 13:10:55 +0100
From: piers@ompa.net
To: dj.adams@pobox.com
Subject: CVS notification
testproject file4
---
Triggered edit watch on /usr/local/cvsroot/testproject
By piers</PRE
></DIV
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-7-SECT-1.2"
>CVS notifications via Jabber</A
></H2
><P
>While email-based notifications are useful, we can add value to this
process by using a more immediate (and penetrating) form of communication:
Jabber. While mail clients can be configured to check for mail automatically
on a regular basis, using an IM-style client has a number of immediately
obvious advantages: </P
><P
></P
><UL
><LI
><P
>it's likely to take up less screen real-estate</P
></LI
><LI
><P
>no amount of tweaking of the mail client's auto-check frequency, if
available (which will log in, check for, and <I
CLASS="EMPHASIS"
>pull</I
>
emails from the mail server) will match the immediacy of IM-style
message <I
CLASS="EMPHASIS"
>push</I
></P
></LI
><LI
><P
>in extreme cases, the higher the auto-check frequency, the higher effect
on overall system performance</P
></LI
><LI
><P
>depending on the configuration, an incoming Jabber message can be made
to pop up, with greater effect</P
></LI
><LI
><P
>a Jabber user is more likely to have a Jabber client running permanently
than an email client</P
></LI
><LI
><P
>it's more fun!</P
></LI
></UL
><P
>The design of CVS's notification mechanism is simple and abstract enough
for us to put an alternative notification system in place.
If we substitute the formula in the <TT
CLASS="FILENAME"
>notify</TT
>
configuration file with something that will call a Jabber script,
we might end up with something like <A
HREF="x6950.htm#JABTDG-CH-7-EX-1"
>Example 7-1</A
>.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-7-EX-1"
></A
><P
><B
>Example 7-1. A Jabber notification formula in the <TT
CLASS="FILENAME"
>notify</TT
> file</B
></P
><P
><PRE
CLASS="SCREEN"
>ALL python cvsmsg %s </PRE
></P
></DIV
><P
>Like the previous formula, it will be invoked by CVS to send the notification,
and the <TT
CLASS="LITERAL"
>%s</TT
> will be substituted by the recipient's address
determined from the <TT
CLASS="FILENAME"
>users</TT
> file. In this case, the
Python script <I
CLASS="EMPHASIS"
>cvsmsg</I
> is called. </P
><P
>But now that we're sending a notification via Jabber, we need a Jabber
address - a JID - instead of an email address. No problem; just edit the
<TT
CLASS="FILENAME"
>users</TT
> file to reflect the new addresses.
<A
HREF="x6950.htm#JABTDG-CH-7-EX-2"
>Example 7-2</A
> shows what the <TT
CLASS="FILENAME"
>users</TT
>
file might contain if we were to use JIDs instead of email addresses.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-7-EX-2"
></A
><P
><B
>Example 7-2. Matching users to JIDs in the <TT
CLASS="FILENAME"
>notify</TT
> file</B
></P
><P
><PRE
CLASS="SCREEN"
>dj:dj@gnu.pipetree.com
piers:piers@jabber.org
robert:shiels@jabber.org</PRE
></P
></DIV
><P
>As Jabber user JIDs in their most basic form (i.e., without a
<I
CLASS="EMPHASIS"
>resource</I
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -