Blame SOURCES/cvs-1.11.23-Back-port-KeywordExpand-configuration-keyword.patch

83a95a
From fe7182d15c93f46212781106b4b63503fcec713f Mon Sep 17 00:00:00 2001
83a95a
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
83a95a
Date: Tue, 15 Mar 2011 14:44:17 +0100
83a95a
Subject: [PATCH] Back-port KeywordExpand configuration keyword
83a95a
83a95a
This is based on code from developemnt 1.12 branch.
83a95a
---
83a95a
 doc/cvs.texinfo |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
83a95a
 src/mkmodules.c |    5 +++
83a95a
 src/parseinfo.c |    4 ++
83a95a
 src/rcs.c       |   51 ++++++++++++++++++++++++++++--
83a95a
 src/rcs.h       |    1 +
83a95a
 5 files changed, 146 insertions(+), 8 deletions(-)
83a95a
83a95a
diff --git a/doc/cvs.texinfo b/doc/cvs.texinfo
83a95a
index ad3a414..943af37 100644
83a95a
--- a/doc/cvs.texinfo
83a95a
+++ b/doc/cvs.texinfo
83a95a
@@ -6847,11 +6847,12 @@ with strings of the form
83a95a
 a new revision of the file.
83a95a
 
83a95a
 @menu
83a95a
-* Keyword list::                Keywords
83a95a
-* Using keywords::              Using keywords
83a95a
-* Avoiding substitution::       Avoiding substitution
83a95a
-* Substitution modes::          Substitution modes
83a95a
-* Log keyword::                 Problems with the $@splitrcskeyword{Log}$ keyword.
83a95a
+* Keyword list::                   Keywords
83a95a
+* Using keywords::                 Using keywords
83a95a
+* Avoiding substitution::          Avoiding substitution
83a95a
+* Substitution modes::             Substitution modes
83a95a
+* Configuring keyword expansion::  Configuring keyword expansion
83a95a
+* Log keyword::                    Problems with the $@splitrcskeyword{Log}$ keyword.
83a95a
 @end menu
83a95a
 
83a95a
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83a95a
@@ -7032,6 +7033,12 @@ contains @samp{$@@asis@{@}Author$} whenever the text
83a95a
 and @code{troff} you can embed the null-character
83a95a
 @code{\&} inside the keyword for a similar effect.
83a95a
 
83a95a
+It is also possible to specify an explicit list of
83a95a
+keywords to include or exclude using the
83a95a
+@code{KeywordExpand} option in the
83a95a
+@file{CVSROOT/config} file--see @ref{Configuring keyword expansion}
83a95a
+for more details.
83a95a
+
83a95a
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83a95a
 @node Substitution modes
83a95a
 @section Substitution modes
83a95a
@@ -7124,6 +7131,74 @@ handle an export containing binary files correctly.
83a95a
 @end table
83a95a
 
83a95a
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83a95a
+@node Configuring keyword expansion
83a95a
+@section Configuring Keyword Expansion
83a95a
+@cindex Configuring keyword expansion
83a95a
+
83a95a
+The @code{KeywordExpand} option in the
83a95a
+@file{CVSROOT/config} file is intended to allow for the
83a95a
+either the explicit exclusion of a keyword or list of
83a95a
+keywords, or for the explicit inclusion of a keyword or
83a95a
+a list of keywords.
83a95a
+
83a95a
+The @code{KeywordExpand} option is followed by
83a95a
+@code{=} and the next character may either be @code{i}
83a95a
+to start an inclusion list or @code{e} to start an
83a95a
+exclusion list. If the following lines were added to
83a95a
+the @file{CVSROOT/config} file:
83a95a
+
83a95a
+@example
83a95a
+        # Restrict keyword expansion to "Log" only
83a95a
+        KeywordExpand=iLog
83a95a
+@end example
83a95a
+
83a95a
+then only the $@splitrcskeyword{Log}$ keyword would be expanded.
83a95a
+A list may be used. The this example:
83a95a
+
83a95a
+@example
83a95a
+        # Restrict keyword expansion to the Name and Date keywords.
83a95a
+        KeywordExpand=iName,Date
83a95a
+@end example
83a95a
+
83a95a
+would allow $@splitrcskeyword{Name}$, and $@splitrcskeyword{Date}$
83a95a
+to be expanded.
83a95a
+
83a95a
+It is also possible to configure an exclusion list
83a95a
+using the following:
83a95a
+
83a95a
+@example
83a95a
+        # Do not expand the keyword Date
83a95a
+        KeywordExpand=eDate
83a95a
+@end example
83a95a
+
83a95a
+This allows @sc{cvs} to ignore the 
83a95a
+$@splitrcskeyword{CVSHeader}$ keyword and retain all of the
83a95a
+others. This could be confusing
83a95a
+to users that expect RCS keywords to be expanded, so
83a95a
+care should be taken to properly set user expectations
83a95a
+for a repository that is configured in that manner.
83a95a
+
83a95a
+If there is a desire to not have any RCS keywords
83a95a
+expanded and not use the @code{-ko} flags everywhere,
83a95a
+an administrator may disable all keyword expansion
83a95a
+using the @file{CVSROOT/config} line:
83a95a
+
83a95a
+@example
83a95a
+    # Do not expand any RCS keywords
83a95a
+    KeywordExpand=i
83a95a
+@end example
83a95a
+
83a95a
+this could be confusing to users that expect RCS
83a95a
+keywords like $@splitrcskeyword{Id}$ to be expanded properly,
83a95a
+so care should be taken to properly set user
83a95a
+expectations for a repository so configured.
83a95a
+
83a95a
+It should be noted that a patch to provide the
83a95a
+@code{KeywordExpand} feature has been around a long time.
83a95a
+However, that patch implemented this feature using
83a95a
+@code{tagexpand=} keyword and this keyword is NOT recognized.
83a95a
+
83a95a
+@c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83a95a
 @node Log keyword
83a95a
 @section Problems with the $@splitrcskeyword{Log}$ keyword.
83a95a
 
83a95a
@@ -13789,6 +13864,14 @@ each command.  It also provides a place for the
83a95a
 @file{CVS/Template} file (@pxref{Working directory
83a95a
 storage}).
83a95a
 
83a95a
+@cindex KeywordExpand, in @file{CVSROOT/config}
83a95a
+@item KeywordExpand=@var{value}
83a95a
+Specify @samp{i} followed by a list of keywords to be expanded
83a95a
+(for example, @samp{KeywordExpand=iName,Date}),
83a95a
+or @samp{e} followed by a list of keywords not to be expanded
83a95a
+(for example, @samp{KeywordExpand=eName}).
83a95a
+For more on keyword expansion, see @ref{Configuring keyword expansion}.
83a95a
+
83a95a
 @cindex LockDir, in CVSROOT/config
83a95a
 @item LockDir=@var{directory}
83a95a
 Put @sc{cvs} lock files in @var{directory} rather than
83a95a
diff --git a/src/mkmodules.c b/src/mkmodules.c
83a95a
index 4bb9d74..3be9509 100644
83a95a
--- a/src/mkmodules.c
83a95a
+++ b/src/mkmodules.c
83a95a
@@ -300,6 +300,11 @@ static const char *const config_contents[] = {
83a95a
     "# primary CVS repository.\n",
83a95a
     "#IgnoreUnknownConfigKeys=no\n",
83a95a
     "\n",
83a95a
+    "# Set `KeywordExpand' to `i' followed by a list of keywords to expand or\n",
83a95a
+    "# `e' followed by a list of keywords to not expand.\n"
83a95a
+    "#KeywordExpand=iName,Date\n",
83a95a
+    "#KeywordExpand=eName\n",
83a95a
+    "\n",
83a95a
     "# Put CVS lock files in this directory rather than directly in the repository.\n",
83a95a
     "#LockDir=/var/lock/cvs\n",
83a95a
     "\n",
83a95a
diff --git a/src/parseinfo.c b/src/parseinfo.c
83a95a
index 86fc6d6..477740a 100644
83a95a
--- a/src/parseinfo.c
83a95a
+++ b/src/parseinfo.c
83a95a
@@ -360,6 +360,10 @@ parse_config (cvsroot)
83a95a
 		goto error_return;
83a95a
 	    }
83a95a
 	}
83a95a
+	else if (strcmp (line, "KeywordExpand") == 0)
83a95a
+	{
83a95a
+	    RCS_setincexc (p);
83a95a
+	}
83a95a
 	else if (strcmp (line, "PreservePermissions") == 0)
83a95a
 	{
83a95a
 	    if (strcmp (p, "no") == 0)
83a95a
diff --git a/src/rcs.c b/src/rcs.c
83a95a
index 20c3162..ba255ce 100644
83a95a
--- a/src/rcs.c
83a95a
+++ b/src/rcs.c
83a95a
@@ -15,6 +15,7 @@
83a95a
  */
83a95a
 
83a95a
 #include <assert.h>
83a95a
+#include <stdbool.h>
83a95a
 #include "cvs.h"
83a95a
 #include "edit.h"
83a95a
 #include "hardlink.h"
83a95a
@@ -3509,9 +3510,10 @@ struct rcs_keyword
83a95a
 {
83a95a
     const char *string;
83a95a
     size_t len;
83a95a
+    bool expandit;
83a95a
 };
83a95a
-#define KEYWORD_INIT(s) (s), sizeof (s) - 1
83a95a
-static const struct rcs_keyword keywords[] =
83a95a
+#define KEYWORD_INIT(s) (s), sizeof (s) - 1, true
83a95a
+static struct rcs_keyword keywords[] =
83a95a
 {
83a95a
     { KEYWORD_INIT ("Author") },
83a95a
     { KEYWORD_INIT ("Date") },
83a95a
@@ -3717,7 +3719,8 @@ expand_keywords (rcs, ver, name, log, loglen, expand, buf, len, retbuf, retlen)
83a95a
 	slen = s - srch;
83a95a
 	for (keyword = keywords; keyword->string != NULL; keyword++)
83a95a
 	{
83a95a
-	    if (keyword->len == slen
83a95a
+	    if (keyword->expandit
83a95a
+		&& keyword->len == slen
83a95a
 		&& strncmp (keyword->string, srch, slen) == 0)
83a95a
 	    {
83a95a
 		break;
83a95a
@@ -8958,3 +8961,45 @@ make_file_label (path, rev, rcs)
83a95a
     }
83a95a
     return label;
83a95a
 }
83a95a
+
83a95a
+
83a95a
+
83a95a
+void
83a95a
+RCS_setincexc (const char *arg)
83a95a
+{
83a95a
+    char *key;
83a95a
+    char *copy, *next;
83a95a
+    bool include = false;
83a95a
+    struct rcs_keyword *keyword;
83a95a
+
83a95a
+    copy = xstrdup(arg);
83a95a
+    next = copy;
83a95a
+    switch (*next++) {
83a95a
+	case 'e':
83a95a
+	    include = false;
83a95a
+	    break;
83a95a
+	case 'i':
83a95a
+	    include = true;
83a95a
+	    break;
83a95a
+	default:
83a95a
+	    free(copy);
83a95a
+	    return;
83a95a
+    }
83a95a
+
83a95a
+    if (include)
83a95a
+	for (keyword = keywords; keyword->string != NULL; keyword++)
83a95a
+	{
83a95a
+	    keyword->expandit = false;
83a95a
+	}
83a95a
+
83a95a
+    key = strtok(next, ",");
83a95a
+    while (key) {
83a95a
+	for (keyword = keywords; keyword->string != NULL; keyword++) {
83a95a
+	    if (strcmp (keyword->string, key) == 0)
83a95a
+		keyword->expandit = include;
83a95a
+	}
83a95a
+	key = strtok(NULL, ",");
83a95a
+    }
83a95a
+    free(copy);
83a95a
+    return;
83a95a
+}
83a95a
diff --git a/src/rcs.h b/src/rcs.h
83a95a
index 3a66640..2126029 100644
83a95a
--- a/src/rcs.h
83a95a
+++ b/src/rcs.h
83a95a
@@ -250,6 +250,7 @@ int rcs_change_text PROTO ((const char *, char *, size_t, const char *,
83a95a
 void RCS_deltas PROTO ((RCSNode *, FILE *, struct rcsbuffer *, const char *,
83a95a
 			enum rcs_delta_op, char **, size_t *,
83a95a
 			char **, size_t *));
83a95a
+void RCS_setincexc (const char *arg);
83a95a
 char *make_file_label PROTO ((const char *, const char *, RCSNode *));
83a95a
 
83a95a
 extern int preserve_perms;
83a95a
-- 
83a95a
1.7.4
83a95a