]> thyrsus.com Git - src.git/commitdiff
Rely on dates in the log, not entry order, to make revision numbers.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 11 Nov 2014 06:29:44 +0000 (01:29 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 11 Nov 2014 06:31:49 +0000 (01:31 -0500)
The pseudotime logic was assigning dates in reverse order.

Regression test passes, after correction for the pseudotime bug.

src
srctest

diff --git a/src b/src
index f0e9638cf32a34d59e416ed66b25ce7ce270f68f..1ed54ec64294794e7709b7b38b82cab1cf95ac6f 100755 (executable)
--- a/src
+++ b/src
@@ -149,9 +149,9 @@ def capture_or_die(command):
 
 class RCSRevisionItem:
     "Capture the state of an RCS revision item in the log."
-    def __init__(self, master, revno):
+    def __init__(self, master):
         self.master = master
-        self.revno = revno
+        self.revno = None
         self.revision = None
         self.log = ""
         self.date = None
@@ -1020,7 +1020,6 @@ class RCS:
     def parse(self, metadata):
         "Get and parse the RCS log output for this file."
         with popen_or_die("cd %s >/dev/null; rlog %s 2>/dev/null; cd ..>/dev/null" % (repodir, metadata.name)) as fp:
-            maxrevno = 0
             if debug >= DEBUG_PARSE:
                 sys.stderr.write("\t-> init\n")
             state = "init"
@@ -1048,8 +1047,7 @@ class RCS:
                         if debug >= DEBUG_PARSE:
                             sys.stderr.write("\t-> logheader\n")
                         state = "logheader"
-                        metadata.revlist.append(RCSRevisionItem(metadata, maxrevno))
-                        maxrevno += 1
+                        metadata.revlist.append(RCSRevisionItem(metadata))
                 elif state == "locks":
                     if not line[0].isspace():
                         if debug >= DEBUG_PARSE:
@@ -1075,19 +1073,13 @@ class RCS:
                         fields = line.split()
                         metadata.revlist[-1].revision = fields[1]
                     elif line.startswith("----------------------------"):
-                        metadata.revlist.append(RCSRevisionItem(metadata, maxrevno))
-                        maxrevno += 1
+                        metadata.revlist.append(RCSRevisionItem(metadata))
                     elif line.startswith("date: "):
                         fields = line.split()
-                        if pseudotime:
-                            # Artificial date one day after the epoch
-                            # to avoid timezone issues.
-                            date = rfc3339(86400 + len(metadata.revlist) * 60)
-                        else:
-                            date = fields[1] + " " + fields[2]
-                            if date.endswith(";"):
-                                date = date[:-1]
-                            date = date.replace("/","-").replace(" ","T") + "Z"
+                        date = fields[1] + " " + fields[2]
+                        if date.endswith(";"):
+                            date = date[:-1]
+                        date = date.replace("/","-").replace(" ","T") + "Z"
                         metadata.revlist[-1].date = date
                     elif line.startswith("branches:"):
                         continue
@@ -1105,10 +1097,16 @@ class RCS:
                         break
                 else:
                     croak("unrecognized branch ID '%s'" % branch)
-            for item in metadata.revlist:
-                item.revno = maxrevno - item.revno
+            metadata.revlist.sort(key=lambda x: x.date)
+            for (i, item) in enumerate(metadata.revlist):
+                if pseudotime:
+                    # Artificial date one day after the epoch
+                    # to avoid timezone issues.
+                    item.date = rfc3339(86400 + i * 60)
+                item.revno = i + 1
+            metadata.revlist.reverse()
             if debug >= DEBUG_PARSE:
-                print "\t%d revisions" % len(metadata.revlist)
+                #print "\t%d revisions" % len(metadata.revlist)
                 print "\tlockrevs:", metadata.lockrevs
                 print "\tsymbols:", metadata.symbols
     def branch_to_base(self, revid):
diff --git a/srctest b/srctest
index c1f6cf2a18a498882c319350e602f705b0aaae0b..4f153ca361a43572e0df9ae02555a87858a9cea1 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -56,6 +56,7 @@ src $TESTOPTS diff testfile1 | (read discard; read discard; cat) >testfile5
 diff -u testfile4 testfile5
 check "nonempty diff"
 
+sleep 2        # Force commit to have different timestamp
 echo "Second comment" | src $TESTOPTS commit - testfile1 >/dev/null
 check "commit with -"
 
@@ -65,7 +66,7 @@ check "content check after second commit"
 cat >testfile2 <<EOF
 = testfile1 =================================================================
 2     * 1970-01-02T00:01:00Z Second comment
-1     - 1970-01-02T00:02:00Z First comment
+1     - 1970-01-02T00:00:00Z First comment
 EOF
 
 src $TESTOPTS list testfile1 >testfile3
@@ -77,7 +78,7 @@ cat >testfile2 <<EOF
 2    | 1970-01-02T00:01:00Z
 Second comment
 ------------------------------------------------------------------------------
-1    | 1970-01-02T00:02:00Z
+1    | 1970-01-02T00:00:00Z
 First comment
 ------------------------------------------------------------------------------
 EOF
@@ -93,19 +94,20 @@ to come to the aid of foo
 EOF
 cp testfile1 testrev3
 
+sleep 2        # Force commit to have different timestamp
 echo "'Third' comment" >testfile4
 src $TESTOPTS commit -f testfile4 testfile1 >/dev/null
 check "commit with -f"
 
 cat >testfile4 <<EOF
 = testfile1 =================================================================
-3    | 1970-01-02T00:01:00Z
+3    | 1970-01-02T00:02:00Z
 'Third' comment
 ------------------------------------------------------------------------------
-2    | 1970-01-02T00:02:00Z
+2    | 1970-01-02T00:01:00Z
 Second comment
 ------------------------------------------------------------------------------
-1    | 1970-01-02T00:03:00Z
+1    | 1970-01-02T00:00:00Z
 First comment
 ------------------------------------------------------------------------------
 EOF