SF.net SVN: geany:[5893] trunk

colombanw at users.sourceforge.net colombanw at xxxxx
Fri Aug 19 13:12:53 UTC 2011


Revision: 5893
          http://geany.svn.sourceforge.net/geany/?rev=5893&view=rev
Author:   colombanw
Date:     2011-08-19 13:12:53 +0000 (Fri, 19 Aug 2011)

Log Message:
-----------
Don't make tags for /dev/null in diff files but for the new file instead

Based on a patch by Yang Hong, thanks.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tagmanager/diff.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-08-19 10:07:26 UTC (rev 5892)
+++ trunk/ChangeLog	2011-08-19 13:12:53 UTC (rev 5893)
@@ -16,6 +16,9 @@
    tagmanager/tm_workspace.c:
    Create temporary files used for generating global tags files in the
    system directory for temp files.
+ * tagmanager/diff.c:
+   Don't make tags for /dev/null in diff files but for the new file
+   instead (Based on a patch by Yang Hong, thanks).
 
 
 2011-08-15  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>

Modified: trunk/tagmanager/diff.c
===================================================================
--- trunk/tagmanager/diff.c	2011-08-19 10:07:26 UTC (rev 5892)
+++ trunk/tagmanager/diff.c	2011-08-19 13:12:53 UTC (rev 5893)
@@ -31,58 +31,90 @@
 	{ TRUE, 'f', "function", "functions"}
 };
 
+enum {
+	DIFF_DELIM_MINUS = 0,
+	DIFF_DELIM_PLUS
+};
+
+static const char *DiffDelims[2] = {
+	"--- ",
+	"+++ "
+};
+
 /*
 *   FUNCTION DEFINITIONS
 */
 
+static const unsigned char *stripAbsolute (const unsigned char *filename)
+{
+	const unsigned char *tmp;
+
+	/* strip any absolute path */
+	if (*filename == '/' || *filename == '\\')
+	{
+		boolean skipSlash = TRUE;
+
+		tmp = (const unsigned char*) strrchr ((const char*) filename,  '/');
+		if (tmp == NULL)
+		{	/* if no / is contained try \ in case of a Windows filename */
+			tmp = (const unsigned char*) strrchr ((const char*) filename, '\\');
+			if (tmp == NULL)
+			{	/* last fallback, probably the filename doesn't contain a path, so take it */
+				tmp = filename;
+				skipSlash = FALSE;
+			}
+		}
+
+		/* skip the leading slash or backslash */
+		if (skipSlash)
+			tmp++;
+	}
+	else
+		tmp = filename;
+
+	return tmp;
+}
+
 static void findDiffTags (void)
 {
 	vString *filename = vStringNew ();
 	const unsigned char *line, *tmp;
+	int delim = DIFF_DELIM_MINUS;
 
 	while ((line = fileReadLine ()) != NULL)
 	{
 		const unsigned char* cp = line;
-		boolean skipSlash = FALSE;
 
-		if (strncmp((const char*) cp, "--- ", (size_t) 4) == 0)
+		if (strncmp ((const char*) cp, DiffDelims[delim], 4u) == 0)
 		{
 			cp += 4;
 			if (isspace ((int) *cp)) continue;
-
-			/* strip any absolute path */
-			if (*cp == '/' || *cp == '\\')
+			/* when original filename is /dev/null use the new one instead */
+			if (delim == DIFF_DELIM_MINUS &&
+				strncmp ((const char*) cp, "/dev/null", 9u) == 0 &&
+				(cp[9] == 0 || isspace (cp[9])))
 			{
-				skipSlash = TRUE;
-				tmp = (const unsigned char*) strrchr((const char*) cp,  '/');
-				if (tmp == NULL)
-				{	/* if no / is contained try \ in case of a Windows filename */
-					tmp = (const unsigned char*) strrchr((const char*) cp, '\\');
-					if (tmp == NULL)
-					{	/* last fallback, probably the filename doesn't contain a path, so take it */
-						if (cp[0] != 0)
-						{
-							tmp = cp;
-							skipSlash = FALSE;
-						}
-					}
-				}
+				delim = DIFF_DELIM_PLUS;
+				continue;
 			}
-			else
-				tmp = cp;
 
+			tmp = stripAbsolute (cp);
+
 			if (tmp != NULL)
 			{
-				if (skipSlash) tmp++; /* skip the leading slash or backslash */
 				while (! isspace(*tmp) && *tmp != '\0')
 				{
 					vStringPut(filename, *tmp);
 					tmp++;
 				}
+
 				vStringTerminate(filename);
 				makeSimpleTag (filename, DiffKinds, K_FUNCTION);
 				vStringClear (filename);
 			}
+
+			/* restore default delim */
+			delim = DIFF_DELIM_MINUS;
 		}
 	}
 	vStringDelete (filename);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list