bug-cvs
[Top][All Lists]
Advanced

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

Patch: make alias modules work.


From: Or Tal
Subject: Patch: make alias modules work.
Date: Mon, 05 Aug 2002 21:27:28 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20011126 Netscape6/6.2.1

Hi all,

Attached is a patch against cvs-1.11.2 to make alias modules work in a consistent way and fix some bugs in alias handling.

It basically adds a sticky notation to alias module definition. After checking out a module, you can cvs update -d without creating directories that were excluded by !dirname in the module definition.
Changes to CVSROOT/modules will be reflected in the next update -d.

Currently this functionality is only added for client/server, and is added in a messy way.

I would appreciate any feedback on this patch.

Or Tal
Jungo.
diff -u /home/ortal/src/cvs-1.11.2/src/add.c ./add.c
--- /home/ortal/src/cvs-1.11.2/src/add.c        Tue Feb  6 17:29:43 2001
+++ ./add.c     Sun Aug  4 17:01:39 2002
@@ -174,6 +174,21 @@
           special-case this.  */
        if (found_slash)
        {
+           /* Get the module name */
+           char *update_dir, *filedir, *p;
+           filedir = xstrdup (argv[0]);
+           p = last_component (filedir);
+           if (p == filedir)
+           {
+               update_dir = "";
+           }
+           else
+           {
+               p[-1] = '\0';
+               update_dir = filedir;
+           }
+           module_name = read_module_name(update_dir, update_dir);
+
            repository = Name_Repository (NULL, NULL);
            send_a_repository ("", repository, "");
            free (repository);
@@ -245,6 +260,7 @@
                rcsdir = xmalloc (strlen (repository) + strlen (p) + 5);
                sprintf (rcsdir, "%s/%s", repository, p);
 
+               module_name = read_module_name(".", ".");
                Create_Admin (p, argv[i], rcsdir, tag, date,
                              nonbranch, 0, 1);
 
@@ -807,7 +823,10 @@
 #ifdef SERVER_SUPPORT
     if (!server_active)
 #endif
+    {
+       module_name = read_module_name(repository, repository);
         Create_Admin (".", finfo->fullname, rcsdir, tag, date, nonbranch, 0, 
1);
+    }
     if (tag)
        free (tag);
     if (date)
diff -u /home/ortal/src/cvs-1.11.2/src/client.c ./client.c
--- /home/ortal/src/cvs-1.11.2/src/client.c     Thu Aug  9 23:27:26 2001
+++ ./client.c  Sun Aug  4 17:01:39 2002
@@ -137,6 +137,7 @@
 static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *,
                                int, int, struct hostent *));
 
+char *module_name = NULL;
 /* We need to keep track of the list of directories we've sent to the
    server.  This list, along with the current CVSROOT, will help us
    decide which command-line arguments to send.  */
@@ -3068,6 +3069,14 @@
        module_argv[i] = xstrdup (argv[i]);
     module_argv[argc] = NULL;
 
+    /* First arg should be the module name. */
+    if (argc < 1)
+    {
+       error(0, 0, "No module name given");
+       return;
+    }
+
+    module_name = xstrdup(argv[0]);
     for (i = 0; i < argc; ++i)
        send_arg (argv[i]);
     send_a_repository ("", current_parsed_root->directory, "");
diff -u /home/ortal/src/cvs-1.11.2/src/create_adm.c ./create_adm.c
--- /home/ortal/src/cvs-1.11.2/src/create_adm.c Tue Jan  9 15:59:59 2001
+++ ./create_adm.c      Sun Aug  4 17:01:39 2002
@@ -169,6 +169,35 @@
     WriteTag (dir, tag, date, nonbranch, update_dir, repository);
 
 #ifdef SERVER_SUPPORT
+    if (!server_active && module_name)
+    {
+       /* Create the ModuleName file */
+       if (dir != NULL)
+           (void) sprintf (tmp, "%s/%s", dir, CVSADM_MODULE_NAME);
+       else
+           (void) strcpy (tmp, CVSADM_MODULE_NAME);
+       fout = CVS_FOPEN (tmp, "w+");
+       if (fout == NULL)
+       {
+           if (update_dir[0] == '\0')
+               error (1, errno, "cannot open %s", tmp);
+           else
+           {
+               error (1, errno, "cannot open %s/%s", update_dir,
+                   CVSADM_MODULE_NAME);
+           }
+       }
+       fprintf(fout, "%s\n", module_name);
+       if (fclose (fout) == EOF)
+       {
+           if (update_dir[0] == '\0')
+               error (1, errno, "cannot close %s", tmp);
+           else
+               error (1, errno, "cannot close %s/%s", update_dir,
+                   CVSADM_ENT);
+       }
+    }
+
     if (server_active && dotemplate)
     {
        server_template (update_dir, repository);
diff -u /home/ortal/src/cvs-1.11.2/src/cvs.h ./cvs.h
--- /home/ortal/src/cvs-1.11.2/src/cvs.h        Fri Aug 24 20:47:02 2001
+++ ./cvs.h     Sun Aug  4 17:01:39 2002
@@ -123,6 +123,7 @@
 #define CVSADM_ENTLOG   "CVS/Entries.Log"
 #define CVSADM_ENTSTAT  "CVS/Entries.Static"
 #define CVSADM_REP      "CVS/Repository."
+#define CVSADM_MODULE_NAME "CVS/Module."
 #define CVSADM_ROOT     "CVS/Root."
 #define CVSADM_CIPROG   "CVS/Checkin.prog"
 #define CVSADM_UPROG    "CVS/Update.prog"
@@ -140,6 +141,7 @@
 #define CVSADM_ENTLOG  "CVS/Entries.Log"
 #define        CVSADM_ENTSTAT  "CVS/Entries.Static"
 #define        CVSADM_REP      "CVS/Repository"
+#define CVSADM_MODULE_NAME "CVS/Module"
 #define        CVSADM_ROOT     "CVS/Root"
 #define        CVSADM_CIPROG   "CVS/Checkin.prog"
 #define        CVSADM_UPROG    "CVS/Update.prog"
@@ -366,6 +368,7 @@
 extern int use_editor;
 extern int cvswrite;
 extern mode_t cvsumask;
+extern char *module_name;
 
 
 
@@ -445,6 +448,8 @@
 void tm_to_internet PROTO ((char *, const struct tm *));
 
 char *Name_Repository PROTO((char *dir, char *update_dir));
+char * read_module_name PROTO((char *dir, char *update_dir));
+
 char *Short_Repository PROTO((char *repository));
 void Sanitize_Repository_Name PROTO((char *repository));
 
diff -u /home/ortal/src/cvs-1.11.2/src/ignore.c ./ignore.c
--- /home/ortal/src/cvs-1.11.2/src/ignore.c     Wed Apr  4 18:52:55 2001
+++ ./ignore.c  Sun Aug  4 17:01:39 2002
@@ -325,7 +325,7 @@
     char *name;
 {
     /* Make sure we've got the space for the entry.  */
-    if (dir_ign_current <= dir_ign_max)
+    if (dir_ign_current >= dir_ign_max)
     {
        dir_ign_max += IGN_GROW;
        dir_ign_list =
diff -u /home/ortal/src/cvs-1.11.2/src/logmsg.c ./logmsg.c
--- /home/ortal/src/cvs-1.11.2/src/logmsg.c     Fri Sep 14 20:12:10 2001
+++ ./logmsg.c  Sun Aug  4 17:01:39 2002
@@ -261,7 +261,7 @@
        }
     }
 
-    (void) fprintf (fp,
+    (void) fprintf (fp, "\n"
   "%s----------------------------------------------------------------------\n",
                    CVSEDITPREFIX);
     (void) fprintf (fp,
diff -u /home/ortal/src/cvs-1.11.2/src/modules.c ./modules.c
--- /home/ortal/src/cvs-1.11.2/src/modules.c    Fri Jun 22 00:23:09 2001
+++ ./modules.c Sun Aug  4 17:01:39 2002
@@ -162,7 +162,13 @@
     /* if this is a directory to ignore, add it to that list */
     if (mname[0] == '!' && mname[1] != '\0')
     {
-       ign_dir_add (mname+1);
+       char *file = xmalloc (strlen (current_parsed_root->directory)
+           + strlen (mname) + 1);
+       (void) sprintf (file, "%s/%s", current_parsed_root->directory,
+           mname + 1);
+
+       ign_dir_add (file);
+       free(file);
        goto do_module_return;
     }
 
diff -u /home/ortal/src/cvs-1.11.2/src/repos.c ./repos.c
--- /home/ortal/src/cvs-1.11.2/src/repos.c      Tue Jan  9 15:59:59 2001
+++ ./repos.c   Sun Aug  4 17:01:39 2002
@@ -10,6 +10,45 @@
 #include "cvs.h"
 #include "getline.h"
 
+char *
+read_module_name (dir, update_dir)
+    char *dir;
+    char *update_dir;
+{
+    FILE *fpin;
+    char *mname = NULL;
+    size_t mname_allocated = 0;
+    char *tmp;
+    char *cp;
+
+    if (dir != NULL)
+    {
+       tmp = xmalloc (strlen (dir) + sizeof (CVSADM_MODULE_NAME) + 10);
+       (void) sprintf (tmp, "%s/%s", dir, CVSADM_MODULE_NAME);
+    }
+    else
+       tmp = xstrdup (CVSADM_MODULE_NAME);
+
+    fpin = CVS_FOPEN (tmp, "r");
+
+    if (fpin == NULL)
+        return NULL;
+
+    if (getline (&mname, &mname_allocated, fpin) < 0)
+    {
+       /* FIXME: should be checking for end of file separately.  */
+       error (1, errno, "cannot read %s", tmp);
+    }
+    if (fclose (fpin) < 0)
+       error (0, errno, "cannot close %s", tmp);
+    free (tmp);
+
+    if ((cp = strrchr (mname, '\n')) != NULL)
+       *cp = '\0';                     /* strip the newline */
+
+    return mname;
+}
+
 /* Determine the name of the RCS repository for directory DIR in the
    current working directory, or for the current working directory
    itself if DIR is NULL.  Returns the name in a newly-malloc'd
diff -u /home/ortal/src/cvs-1.11.2/src/server.c ./server.c
--- /home/ortal/src/cvs-1.11.2/src/server.c     Tue Mar 19 21:15:45 2002
+++ ./server.c  Sun Aug  4 17:01:39 2002
@@ -3692,6 +3692,27 @@
     do_cvs_command ("admin", admin);
 }
 
+/* Null callback for do_module() of serve_module_name(). */
+static int
+serve_module_name_cb (int argc, char *argv[], char *where,
+    char *mwhere, char *mfile, int shorten, int local_specified,
+    char *omodule, char *msg)
+{
+}
+
+static void
+serve_module_name (arg)
+    char *arg;
+{
+    DBM *db;
+    module_name = xstrdup(arg);
+    /* Parse the module in order to build ignore list based on the module. */
+    db = open_module ();
+    do_module(db, arg, CHECKOUT, "Updating", serve_module_name_cb,
+       NULL, 0, 0, 0, 1, NULL);
+
+    close_module (db);
+}
 static void
 serve_history (arg)
     char *arg;
@@ -4816,6 +4837,7 @@
   REQ_LINE("rannotate", serve_rannotate, 0),
   REQ_LINE("noop", serve_noop, RQ_ROOTLESS),
   REQ_LINE("version", serve_version, RQ_ROOTLESS),
+  REQ_LINE("module-name", serve_module_name, 0),
   REQ_LINE(NULL, NULL, 0)
 
 #undef REQ_LINE
diff -u /home/ortal/src/cvs-1.11.2/src/status.c ./status.c
--- /home/ortal/src/cvs-1.11.2/src/status.c     Tue Jan  9 15:59:59 2001
+++ ./status.c  Sun Aug  4 17:01:39 2002
@@ -78,6 +78,18 @@
        if (local)
            send_arg("-l");
 
+       /* Read the module name. We assume that we are located inside
+        * the repository.
+        */
+       module_name = read_module_name(".", ".");
+       if (supported_request ("module-name") && module_name)
+       {
+           /* Send module name to server. */
+           send_to_server ("module-name ", 0);
+           send_to_server (module_name, 0);
+           send_to_server ("\012", 1);
+       }
+
        /* For a while, we tried setting SEND_NO_CONTENTS here so this
           could be a fast operation.  That prevents the
           server from updating our timestamp if the timestamp is
@@ -287,6 +299,14 @@
        }
        else if (!really_quiet)
            cvs_output ("   Sticky Options:\t(none)\n", 0);
+       if (module_name)
+       {
+           cvs_output ("   Module:\t\t", 0);
+           cvs_output (module_name, 0);
+           cvs_output ("\n", 0);
+       }
+       else if (!really_quiet)
+           cvs_output ("   Module:\t\t(none)\n", 0);
     }
 
     if (long_format && vers->srcfile)
diff -u /home/ortal/src/cvs-1.11.2/src/update.c ./update.c
--- /home/ortal/src/cvs-1.11.2/src/update.c     Sun Jul  8 23:51:46 2001
+++ ./update.c  Sun Aug  4 17:01:39 2002
@@ -278,6 +278,18 @@
            {
                 unsigned int flags = 0;
 
+               /* Read the module name. We assume that we are located inside
+                * the repository.
+                */
+               module_name = read_module_name(".", ".");
+               if (supported_request ("module-name") && module_name)
+               {
+                   /* Send module name to server. */
+                   send_to_server ("module-name ", 0);
+                   send_to_server (module_name, 0);
+                   send_to_server ("\012", 1);
+               }
+
                /* If the server supports the command "update-patches", that 
                   means that it knows how to handle the -u argument to update,
                   which means to send patches instead of complete files.
@@ -895,7 +907,7 @@
     char *update_dir;
     List *entries;
 {
-    if (ignore_directory (update_dir))
+    if (ignore_directory (repository))
     {
        /* print the warm fuzzy message */
        if (!quiet)

reply via email to

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