bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS/Template files ... requesting opinion/clue


From: Derek Robert Price
Subject: Re: CVS/Template files ... requesting opinion/clue
Date: Fri, 07 Mar 2003 12:11:56 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02

Mark D. Baushke wrote:

Hi Derek & Larry,

Well, I have been working on a "bug" in cvs whereby the CVS/Template is
never touched after the initial checkout or 'cvs update -d' of a new
directory.

I have 99% of it working... (BTW: I had to discard all of the FreeBSD
ideas as that worked only for the local repository case.)

The problem is that if a given commit occurs which modifies the rcsinfo
file (or possibly the files that are referenced by the rcsinfo file), I
can not figure out how to get the CVSROOT directory to be updated
properly after it rebuilds the database. I am also not sure if it is a
big enough deal to worry about right now or not.


Ah, I didn't understand this in your other email. It does sound like an obscure case, but I think all the same file building fuctions are available to the commit function as to the update function. This does sound obscure enough to skip though cool if it got done.

I also had to introduce a "Clear-template" protocol response which is
only used if the client understands it. This is needed for the situation
where the ParseInfo() for CVSADM_TEMPLATE does not find any appliciable
actions.

I originally tried to use the server_template() function and have it
look at the return code from Parse_Info() something like this:

 if (Parse_Info (CVSROOTADM_RCSINFO, repository, template_proc, 1) == -1)
     server_clear_template (update_dir, repository);


Parse_Info only returns -1 when it can't find an rcsinfo file at all.

but it never seemed to call the server_clear_template() function and so
one could be left with a directory that had an obsolete CVS/Template
file. To fix this, I just always have the server try to send a
Clear-template response before it sends a Template response. It would be
better to only clear the template if it has gone away in the repository.
Suggestions for how to do this correctly would be much appreciated. :-)

If the client cvs does not support Clear-template, then the Template
file will still get updated okay as long as one is defined by the
rcsinfo file. So, this will work for most users anyway.

What follows is my best guess at how the "Template" and "Clear-template"
function should be handled. However, it is possible that there are some
redundant occasions when the CVS/Template may be getting updated more
than once.... although I have tried to find and eliminate those cases
where I could catch them.

Note that I would consider most of this code (other than the
Clear-template support) to be a bug fix for 1.11.x and I would
be interested if you feel this is also true.


I don't think so. I can see where you are coming from, but the idea behind the stable branch is that we attempt to introduce as little new code as possible in order to avoid introducing new bugs so that the branch remains stable. Also, the CVS/Template file was never documented as being updated except on checkout, so this would seem to qualify as a new feature, or at least an enhancement.

Comments greatfully accepted.

        Thanks,
        -- Mark

Index: ChangeLog
===================================================================
RCS file: /cvs/ccvs/src/ChangeLog,v
retrieving revision 1.2373
diff -u -p -r1.2373 ChangeLog
--- ChangeLog   6 Mar 2003 17:55:26 -0000       1.2373
+++ ChangeLog   7 Mar 2003 02:00:15 -0000
@@ -1,3 +1,27 @@
+2003-03-06  Mark D. Baushke  <address@hidden>
+
+       * entries.c (WriteTemplate): New function to control updates to
+       the CVS/Template file or its removal.
+       * create_adm.c (Create_Admin): Use the new WriteTemplate function.
+       * add.c (add_directory): Add a WriteTemplate() call
+       when a new directory is added to the repository.
+       * server.c (server_clear_template): New protocol response to
+       remove existing CVS/Template files.
+       * commit.c (commit_filesdoneproc): Ensure that the CVS/Template is
+       updated at the end of a commit -- mostly to remove it if it is not
+       relevant.
+       (commit_dirleaveproc): Ensure that the CVS/Template gets updated
+       when the directory is left.
+       * update.c (update_dirent_proc): Update CVS/Template file.
+       * client.c (clear_template): New function to remove a
+       CVS/Template file.
+       (handle_clear_template): New function. Handle Clear-template
+       protocol response message.
+       (save_prog): Add new Clear-template response line.
+       * sanity.sh (template): Test the CVS/Template creation with
+       the remote protocol. Nothing gets created locally.
+       (multiroot2): Fix for minor changes to trace output.
+       
2003-03-06  Larry Jones  <address@hidden>

        * sanity.sh (branches3-4): Set and export CVS_LOCAL_BRANCH_NUM
Index: add.c
===================================================================
RCS file: /cvs/ccvs/src/add.c,v
retrieving revision 1.81
diff -u -p -r1.81 add.c
--- add.c       7 Feb 2003 19:53:30 -0000       1.81
+++ add.c       7 Mar 2003 02:00:15 -0000
@@ -809,6 +809,8 @@ add_directory (finfo)
    if (!server_active)
#endif
        Create_Admin (".", finfo->fullname, rcsdir, tag, date, nonbranch, 0, 1);
+    WriteTemplate (finfo->fullname, 1, rcsdir);
+
    if (tag)
        free (tag);
    if (date)
Index: client.c
===================================================================
RCS file: /cvs/ccvs/src/client.c,v
retrieving revision 1.320
diff -u -p -r1.320 client.c
--- client.c    6 Feb 2003 17:33:50 -0000       1.320
+++ client.c    7 Mar 2003 02:00:15 -0000
@@ -123,6 +123,7 @@ static void handle_set_static_directory static void handle_clear_static_directory PROTO((char *, int));
static void handle_set_sticky PROTO((char *, int));
static void handle_clear_sticky PROTO((char *, int));
+static void handle_clear_template PROTO((char *, int));
static void handle_set_checkin_prog PROTO((char *, int));
static void handle_set_update_prog PROTO((char *, int));
static void handle_module_expansion PROTO((char *, int));
@@ -2547,6 +2548,26 @@ handle_template (pathname, len)
    call_in_directory (pathname, template, NULL);
}

+static void
+clear_template (data, ent_list, short_pathname, filename)
+    char *data;
+    List *ent_list;
+    char *short_pathname;
+    char *filename;
+{
+    if (unlink_file (CVSADM_TEMPLATE) < 0 && ! existence_error (errno))
+       error (1, errno, "cannot remove %s", CVSADM_TEMPLATE);
+}
+
+static void
+handle_clear_template (pathname, len)
+    char *pathname;
+    int len;
+{
+    call_in_directory (pathname, clear_template, NULL);
+}
+
+

struct save_prog {
    char *name;
@@ -3408,6 +3429,8 @@ struct response responses[] =
    RSP_LINE("Clear-sticky", handle_clear_sticky, response_type_normal,
       rs_optional),
    RSP_LINE("Template", handle_template, response_type_normal,
+       rs_optional),
+    RSP_LINE("Clear-template", handle_clear_template, response_type_normal,
       rs_optional),
    RSP_LINE("Set-checkin-prog", handle_set_checkin_prog, response_type_normal,
       rs_optional),
Index: commit.c
===================================================================
RCS file: /cvs/ccvs/src/commit.c,v
retrieving revision 1.188
diff -u -p -r1.188 commit.c
--- commit.c    7 Feb 2003 21:34:03 -0000       1.188
+++ commit.c    7 Mar 2003 02:00:15 -0000
@@ -1468,6 +1468,7 @@ commit_filesdoneproc (callerdat, err, re
            cvs_output (": Rebuilding administrative file database\n", 0);
            mkmodules (admin_dir);
            free (admin_dir);
+           WriteTemplate (".", 1, repository);
        }
    }

@@ -1589,6 +1590,12 @@ commit_dirleaveproc (callerdat, dir, err
        char *repos = Name_Repository (NULL, update_dir);
        WriteTag (NULL, write_dirtag, NULL, write_dirnonbranch,
                  update_dir, repos);
+       free (repos);
+    }
+    if (err == 0)
+    {
+       char *repos = Name_Repository (NULL, update_dir);
+       WriteTemplate (update_dir, 1, repos);
        free (repos);
    }

Index: create_adm.c
===================================================================
RCS file: /cvs/ccvs/src/create_adm.c,v
retrieving revision 1.38
diff -u -p -r1.38 create_adm.c
--- create_adm.c        3 Feb 2003 17:53:23 -0000       1.38
+++ create_adm.c        7 Mar 2003 02:00:15 -0000
@@ -159,14 +159,10 @@ Create_Admin (dir, update_dir, repositor
    /* Create a new CVS/Tag file */
    WriteTag (dir, tag, date, nonbranch, update_dir, repository);

-#ifdef SERVER_SUPPORT
-    if (server_active && dotemplate)
-    {
-       server_template (update_dir, repository);
-    }
+    /* Create a new CVS/Template file */
+    WriteTemplate (update_dir, dotemplate, repository);

    TRACE ( 1, "Create_Admin" );
-#endif

    free (reposcopy);
    free (tmp);
Index: entries.c
===================================================================
RCS file: /cvs/ccvs/src/entries.c,v
retrieving revision 1.47
diff -u -p -r1.47 entries.c
--- entries.c   3 Feb 2003 17:53:23 -0000       1.47
+++ entries.c   7 Mar 2003 02:00:15 -0000
@@ -628,6 +628,33 @@ AddEntryNode (list, entdata)
}

/*
+ * Write out the CVS/Template file.
+ */
+void
+WriteTemplate (update_dir, xdotemplate, repository)
+    char *update_dir;
+    int xdotemplate;
+    char *repository;
+{
+    if (noexec)
+       return;
+
+#ifdef SERVER_SUPPORT
+    if (server_active && xdotemplate)
+    {
+        /* clear the CVS/Template if supported to allow for the case
+        * where the rcsinfo file no longer has an entry for this
+        *  directory.
+        */
+       server_clear_template (update_dir, repository);
+       server_template (update_dir, repository);
+    }
+
+    TRACE (1, "Write_Template (%s, %s)", update_dir, repository);
+#endif
+}
+
+/*
 * Write out/Clear the CVS/Tag file.
 */
void
Index: sanity.sh
===================================================================
RCS file: /cvs/ccvs/src/sanity.sh,v
retrieving revision 1.766
diff -u -p -r1.766 sanity.sh
--- sanity.sh   6 Mar 2003 17:55:26 -0000       1.766
+++ sanity.sh   7 Mar 2003 02:00:15 -0000
@@ -716,7 +716,7 @@ if test x"$*" = x; then
        # Multiple root directories and low-level protocol tests.
        tests="${tests} multiroot multiroot2 multiroot3 multiroot4"
        tests="${tests} rmroot reposmv pserver server server2 client"
-       tests="${tests} fork commit-d"
+       tests="${tests} fork commit-d template"
else
        tests="$*"
fi
@@ -23312,16 +23312,20 @@ ${PROG} server: Updating dir1/sdir/ssdir
          if $remote; then :; else
            dotest multiroot2-9a "${testcvs} -t update" \
" *-> main loop with CVSROOT=${TESTDIR}/root1
+ *-> Write_Template (\., ${TESTDIR}/root1)
${PROG} update: Updating \.
 *-> Reader_Lock(${TESTDIR}/root1)
 *-> Lock_Cleanup()
+ *-> Write_Template (dir1, ${TESTDIR}/root1/dir1)
${PROG} update: Updating dir1
 *-> Reader_Lock(${TESTDIR}/root1/dir1)
 *-> Lock_Cleanup()
 *-> main loop with CVSROOT=${TESTDIR}/root2
+ *-> Write_Template (dir1/sdir, ${TESTDIR}/root2/dir1/sdir)
${PROG} update: Updating dir1/sdir
 *-> Reader_Lock(${TESTDIR}/root2/sdir)
 *-> Lock_Cleanup()
+ *-> Write_Template (dir1/sdir/ssdir, ${TESTDIR}/root2/sdir/ssdir)
${PROG} update: Updating dir1/sdir/ssdir
 *-> Reader_Lock(${TESTDIR}/root2/sdir/ssdir)
 *-> Lock_Cleanup()
@@ -24572,6 +24576,171 @@ new revision: 1.2; previous revision: 1.
done"
          cd ../..
          rm -rf 1 cvsroot/c-d-c
+         ;;
+
+       template)
+         # Check that the CVS/Template directory is being
+         # properly created.
+         mkdir -p ${CVSROOT_DIRNAME}/first/subdir
+         mkdir -p ${CVSROOT_DIRNAME}/second
+         mkdir template; cd template
+
+         # check that no CVS/Template is created for an empty rcsinfo
+         dotest template-empty-1 "${testcvs} -Q co first" ''
+         dotest_fail template-empty-2 "test -f first/CVS/Template" ''
+         dotest_fail template-empty-3 "test -f first/subdir/CVS/Template" ''
+         rm -fr first
+
+         # create some template files
+         echo 'CVS: the default template' > ${TESTDIR}/template/temp.def
+         echo 'CVS: the first template' > ${TESTDIR}/template/temp.first
+         echo 'CVS: the subdir template' > ${TESTDIR}/template/temp.subdir
+ + dotest template-rcsinfo-1 "${testcvs} -Q co CVSROOT" ''
+         cd CVSROOT
+         echo "^first/subdir ${TESTDIR}/template/temp.subdir" >>rcsinfo
+         echo "^first ${TESTDIR}/template/temp.first" >>rcsinfo
+         echo DEFAULT ${TESTDIR}/template/temp.def >>rcsinfo
+         dotest template-rcsinfo-2 "${testcvs} -Q ci -m. rcsinfo" \
+"Checking in rcsinfo;
+${CVSROOT_DIRNAME}/CVSROOT/rcsinfo,v  <--  rcsinfo
+new revision: 1\.2; previous revision: 1\.1
+done
+$PROG [a-z]*: Rebuilding administrative file database"
+         # Did the CVSROOT/CVS/Template file get the updated version?
+         # FIXME. This result is wrong!
+         dotest_fail template-rcsinfo-3  \
+"cmp CVS/Template ${TESTDIR}/template/temp.def" \
+'cmp: CVS/Template: No such file or directory'
+         cd ..
+
+         # Now checkout the first and second modules and see
+         # if the proper template has been provided for each
+         dotest template-first "${testcvs} co first second" \
+"$PROG [a-z]*: Updating first
+$PROG [a-z]*: Updating first/subdir
+$PROG [a-z]*: Updating second"
+
+         if $remote; then
+           # When in client/server CVS/Template must exist
+           dotest template-first-r-1 "test -f first/CVS/Template" ''
+           dotest template-first-r-2 "test -f first/subdir/CVS/Template" ''
+           dotest template-first-r-3 "test -f second/CVS/Template" ''
+           # The value of the CVS/Template should be equal to the
+           # file called out in the rcsinfo file.
+           dotest template-first-r-4 \
+"cmp first/CVS/Template ${TESTDIR}/template/temp.first" ''
+           dotest template-first-r-5 \
+"cmp first/subdir/CVS/Template ${TESTDIR}/template/temp.subdir" ''
+           dotest template-first-r-6 \
+"cmp second/CVS/Template ${TESTDIR}/template/temp.def" ''
+          else
+           # When in local mode CVS/Template must NOT exist
+           dotest_fail template-first-1 "test -f first/CVS/Template" ''
+           dotest_fail template-first-2 "test -f first/subdir/CVS/Template" ''
+           dotest_fail template-first-3 "test -f second/CVS/Template" ''
+         fi
+
+         # Next, create a new subdirectory and see if it gets the
+         # correct template or not
+         cd second
+         mkdir otherdir
+         dotest template-add-1 "${testcvs} add otherdir" \
+"Directory ${CVSROOT_DIRNAME}/second/otherdir added to the repository"
+         if $remote; then
+           dotest template-add-2r "test -f otherdir/CVS/Template" ''
+         else
+           dotest_fail template-add-2 "test -f otherdir/CVS/Template" ''
+         fi
+         cd ..
+
+         # Update the remote template. Then see if doing an
+         # update of a checked out tree will properly update
+         # the CVS/Template files.
+         echo 'CVS: Line two' >> ${TESTDIR}/template/temp.def
+         echo 'CVS: Line two' >> ${TESTDIR}/template/temp.first
+         echo 'CVS: Line two' >> ${TESTDIR}/template/temp.subdir
+         dotest template-second "${testcvs} update first second" \
+"$PROG [a-z]*: Updating first
+$PROG [a-z]*: Updating first/subdir
+$PROG [a-z]*: Updating second
+$PROG [a-z]*: Updating second/otherdir"
+
+         if $remote; then
+           dotest template-second-r-1 \
+"cmp first/CVS/Template ${TESTDIR}/template/temp.first" ''
+           dotest template-second-r-2 \
+"cmp first/subdir/CVS/Template ${TESTDIR}/template/temp.subdir" ''
+           dotest template-second-r-3 \
+"cmp second/CVS/Template ${TESTDIR}/template/temp.def" ''
+           dotest template-second-r-4 \
+"cmp second/otherdir/CVS/Template ${TESTDIR}/template/temp.def" ''
+          else
+           # When in local mode CVS/Template must NOT exist
+           dotest_fail template-second-1 "test -f CVS/Template" ''
+           dotest_fail template-second-2 "test -f subdir/CVS/Template" ''
+           dotest_fail template-second-3 "test -f second/CVS/Template" ''
+           dotest_fail template-second-4 \
+"test -f second/otherdir/CVS/Template" ''
+         fi
+         # Update the remote template with a zero-length template
+         : > ${TESTDIR}/template/temp.def
+         dotest template-third-1 "${testcvs} update second" \
+"${PROG} [a-z]*: Updating second
+${PROG} [a-z]*: Updating second/otherdir"
+
+         if $remote; then
+           dotest_fail template-third-r-2 "test -s second/CVS/Template" ''
+           dotest_fail template-third-r-3 "test -s 
second/otherdir/CVS/Template" ''
+          else
+           dotest_fail template-third-2 "test -f second/CVS/Template" ''
+           dotest_fail template-third-3 \
+"test -f second/otherdir/CVS/Template" ''
+          fi
+
+         cd CVSROOT
+         dotest template-norcsinfo-1 "${testcvs} up" \
+"${PROG} [a-z]*: Updating \."
+         # Did the CVSROOT/CVS/Template file get the updated version?
+         if $remote; then
+           dotest template-norcsinfo-r-2 \
+"cmp CVS/Template ${TESTDIR}/template/temp.def" ''
+          else
+           dotest_fail template-norcsinfo-2 "test -f CVS/Template" ''
+         fi
+
+         : > rcsinfo
+         dotest template-norcsinfo-3 "${testcvs} -Q ci -m. rcsinfo" \
+"Checking in rcsinfo;
+${CVSROOT_DIRNAME}/CVSROOT/rcsinfo,v  <--  rcsinfo
+new revision: 1\.3; previous revision: 1\.2
+done
+${PROG} [a-z]*: Rebuilding administrative file database"
+         # Did the CVSROOT/CVS/Template file get the updated version?
+         # FIXME. This result is wrong!
+         #dotest template-norcsinfo-4 "test -f CVS/Template" ''
+         dotest_fail template-norcsinfo-4 "test -f CVS/Template" ''
+         cd ..
+
+         dotest template-norcsinfo-5 "${testcvs} update first" \
+"${PROG} [a-z]*: Updating first
+${PROG} [a-z]*: Updating first/subdir"
+
+         dotest_fail template-norcsinfo-6 "test -f first/CVS/Template" ''
+         dotest_fail template-norcsinfo-7 \
+"test -f first/subdir/CVS/Template" ''
+
+         if $keep; then
+           echo Keeping ${TESTDIR} and exiting due to --keep
+           exit 0
+         fi
+
+         # cleanup
+         rm -f ${CVS_DIRNAME}/CVSROOT/rcsinfo,v \
+                ${CVS_DIRNAME}/CVSROOT/rcsinfo
+         dotest template-cleanup-1 "${testcvs} -Q init" ''
+         cd ..
+         rm -rf template
          ;;

        *)
Index: server.c
===================================================================
RCS file: /cvs/ccvs/src/server.c,v
retrieving revision 1.287
diff -u -p -r1.287 server.c
--- server.c    21 Feb 2003 21:44:14 -0000      1.287
+++ server.c    7 Mar 2003 02:00:15 -0000
@@ -4416,6 +4416,27 @@ template_proc (repository, template)
}

void
+server_clear_template (update_dir, repository)
+    char *update_dir;
+    char *repository;
+{
+    assert (update_dir != NULL);
+
+    if (noexec)
+       return;
+
+    if (supported_response ("Clear-template"))
+    {
+        buf_output0 (protocol, "Clear-template ");
+       output_dir (update_dir, repository);
+       buf_output0 (protocol, "\n");
+       buf_send_counted (protocol);
+    }
+
+    TRACE (1, "Clear-template");
+}
+
+void
server_template (update_dir, repository)
    char *update_dir;
    char *repository;
Index: update.c
===================================================================
RCS file: /cvs/ccvs/src/update.c,v
retrieving revision 1.205
diff -u -p -r1.205 update.c
--- update.c    28 Feb 2003 23:11:21 -0000      1.205
+++ update.c    7 Mar 2003 02:00:15 -0000
@@ -1025,6 +1025,8 @@ update_dirent_proc (callerdat, dir, repo
            nonbranch = 0;
        }

+       WriteTemplate (update_dir, dotemplate, repository);
+
        /* initialize the ignore list for this directory */
        ignlist = getlist ();
    }

Derek

--
               *8^)

Email: address@hidden

Get CVS support at <http://ximbiot.com>!
--
Mud is not one of the 4 food groups.
Mud is not one of the 4 food groups.
Mud is not one of the 4 food groups...

         - Bart Simpson on chalkboard, _The Simpsons_







reply via email to

[Prev in Thread] Current Thread [Next in Thread]