git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[CVSPS PATCH] fix: correct rev order in case commiters clocks were not syncronised

From
Heiko Voigt <git-list@hvoigt.net>
Date
Mar 9, 2009, 11:26 UTC
Message-ID
<49B4FCDA.4030106@hvoigt.net>
In-Reply-To
<49AC1E88.1010709@hvoigt.net>
This fixes the following kind of cvsps issues:
 Structure of the test cvs repository
 Message   File:Content         Commit Time
 Rev 1     a: 1.1               2009-02-21 19:11:43 +0100
 Rev 2     a: 1.2    b: 1.1     2009-02-21 19:11:14 +0100
 Rev 3               b: 1.2     2009-02-21 19:11:43 +0100
 As you can see the commit of Rev 3 has the same time as
 Rev 1 this was leading to a broken estimation of patchset
 order.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
After precisely formulating my problem with cvsps I was curious if this
issue actually could be fixed. Additionally I don't want my test to be
disabled ;). This patch seems to fix it. Is Yann still maintaining the
patches for cvsps or should I forward this patch to someone else ?

Calculating with time_t like I did is probably not valid on all systems if you know of a nicer, more portable solution please let me know.

 cvsps.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/cvsps.c b/cvsps.c
index 81c6e21..d5c30d4 100644
--- a/cvsps.c
+++ b/cvsps.c
@@ -259,6 +259,32 @@ int main(int argc, char *argv[])
     exit(0);
 }
 
+void detect_and_repair_time_skew(const char *last_date, char *date, int n,
+                                 const char *filename)
+{
+
+    time_t smaller;
+    time_t bigger;
+    struct tm *ts;
+
+    /* if last_date does not exist do nothing */
+    if (last_date[0] == '\0')
+        return;
+
+    /* important: because rlog is showing revisions backwards last_date should
+     * always be bigger than date */
+    convert_date(&bigger, last_date);
+    convert_date(&smaller, date);
+
+    if (difftime(bigger, smaller) <= 0) {
+        debug(DEBUG_APPMSG1, "broken revision date: %s -> %s file: %s, repairing.\n",
+              date, last_date, filename);
+        smaller = bigger - 1;
+        ts = gmtime(&smaller);
+        strftime(date, n, "%Y-%m-%d %H:%M:%S", ts);
+    }
+}
+
 static void load_from_cvs()
 {
     FILE * cvsfp;
@@ -267,6 +293,7 @@ static void load_from_cvs()
     CvsFile * file = NULL;
     PatchSetMember * psm = NULL;
     char datebuff[20];
+    char last_datebuff[20];
     char authbuff[AUTH_STR_MAX];
     int logbufflen = LOG_STR_MAX + 1;
     char * logbuff = malloc(logbufflen);
@@ -334,6 +361,8 @@ static void load_from_cvs()
 	exit(1);
     }
 
+    /* initialize the last_datebuff with value indicating invalid date */
+    last_datebuff[0]='\0';
     for (;;)
     {
 	char * tst;
@@ -474,8 +503,14 @@ static void load_from_cvs()
 	    {
 		if (psm)
 		{
+		    detect_and_repair_time_skew(last_datebuff, datebuff, 20, psm->file->filename);
 		    PatchSet * ps = get_patch_set(datebuff, logbuff, authbuff, psm->post_rev->branch, psm);
 		    patch_set_add_member(ps, psm);
+
+		    /* remember last revision */
+		    strncpy(last_datebuff, datebuff, 20);
+		    /* just to be sure */
+		    last_datebuff[19] = '\0';
 		}
 
 		logbuff[0] = 0;
@@ -487,8 +522,13 @@ static void load_from_cvs()
 	    {
 		if (psm)
 		{
+		    detect_and_repair_time_skew(last_datebuff, datebuff, 20, psm->file->filename);
 		    PatchSet * ps = get_patch_set(datebuff, logbuff, authbuff, psm->post_rev->branch, psm);
 		    patch_set_add_member(ps, psm);
+
+		    /* just finished the last revision of this file, set last_datebuff to invalid */
+		    last_datebuff[0]='\0';
+
 		    assign_pre_revision(psm, NULL);
 		}
 
Previous: Heiko VoigtNext: Michael Haggerty
Message 6 of 21 in “cvsimport: add test illustrating a bug in cvsps”
  1. cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Feb 23, 2009
  2. Heiko VoigtFeb 23, 2009
  3. Michael HaggertyFeb 24, 2009
  4. 0/1 cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Mar 2, 2009
  5. 1/1 cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Mar 2, 2009
  6. fix: correct rev order in case commiters clocks were not syncronisedHeiko Voigt, Mar 9, 2009
  7. Michael HaggertyMar 9, 2009
  8. 0/2 cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Mar 18, 2009
  9. Junio C HamanoMar 18, 2009
  10. Michael J GruberMar 19, 2009
  11. Johannes SchindelinMar 19, 2009
  12. Michael J GruberMar 19, 2009
  13. Michael HaggertyMar 21, 2009
  14. started a cvsps testsuite Was: Re: [PATCH v3 0/2] cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Mar 23, 2009
  15. Martin LanghoffMar 23, 2009
  16. Michael HaggertyMar 24, 2009
  17. Heiko VoigtApr 6, 2009
  18. Heiko VoigtMar 23, 2009
  19. 1/2 cvsimport: add test illustrating a bug in cvspsHeiko Voigt, Mar 18, 2009
  20. 2/2 cvsimport: extend testcase about patchset order to contain branchesHeiko Voigt, Mar 18, 2009
  21. fix: correct rev order in case commiters clocks were not syncronisedHeiko Voigt, Mar 18, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.