]> thyrsus.com Git - src.git/commitdiff
Use fixed-with cut lines. Trying to get the terminal width fails under Emacs.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 20 Nov 2014 19:47:20 +0000 (14:47 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 20 Nov 2014 19:47:20 +0000 (14:47 -0500)
Regression test passes.

src
srctest

diff --git a/src b/src
index 68a4b9881d3d378f19cd09cb9af5b598ba54bbfc..522499d81afa2d3066d43fcb0a6e5761eaa9f9b2 100755 (executable)
--- a/src
+++ b/src
@@ -58,14 +58,6 @@ import sys, os, subprocess, time, calendar, stat, glob, shutil, hashlib
 
 version="0.10"
 
-def screenwidth():
-    "Return the current width of the terminal window."
-    if pseudotime:
-        return 79
-    else:
-        with popen_or_die(b'stty size', b"rb") as tp:
-            return int(tp.read().split()[1])
-
 def rfc3339(t):
     "RFC3339 string from Unix time."
     return time.strftime(b"%Y-%m-%dT%H:%M:%SZ", time.gmtime(t))
@@ -89,6 +81,10 @@ pseudotime = False   # option -T: artificial clock for regression testing
 # Repo directory
 repodir = ".src"
 
+# How to size cut lines.  We used to do this dynamically from the screen size,
+# but that fails under Emacs
+WIDTH = 72
+
 def stamp(arg):
     "Name the stamp file used to track revisions."
     if os.sep not in arg:
@@ -1129,13 +1125,11 @@ def list_method(*args):
         custom = args[0][2:]
         args.pop(0)
     ctx = CommandContext("list", args, default_to="branch_reversed")
-    if custom is None:
-        width = screenwidth()
     for arg in ctx.args:
         if ignore(arg) or not registered(arg):
             continue
         if custom is None:
-            sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
+            sys.stdout.write("= %s %s\n" % (arg, ((WIDTH - len(arg) - 3) * "=")))
         for item in ctx.resolve(History(arg), backwards=True):
             # Must allow enough room for revno and date
             if item.selected():
@@ -1144,7 +1138,7 @@ def list_method(*args):
                 mark = "-"
             summary = item.log.split('\n')[0]
             if custom is None:
-                summary = summary[:width - 34]
+                summary = summary[:WIDTH - 34]
                 sys.stdout.write("%-4d  %s %s %s\n" \
                              % (item.revno, mark, item.date, summary))
             else:
@@ -1153,14 +1147,13 @@ def list_method(*args):
 def log_method(*args):
     "Report revision logs"
     ctx = CommandContext("log", args, default_to="branch_reversed")
-    width = screenwidth()
     for arg in ctx.args:
         if ignore(arg) or not registered(arg):
             continue
-        sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
+        sys.stdout.write("= %s %s\n" % (arg, ((WIDTH - len(arg) - 3) * "=")))
         for item in ctx.resolve(History(arg), backwards=True):
             sys.stdout.write("%-4d | %s\n%s" % (item.revno,item.date,item.log))
-            sys.stdout.write(("-" * (width - 1)) + "\n")
+            sys.stdout.write(("-" * WIDTH) + "\n")
 
 def checkout_method(*args):
     "Refresh the working copy from the history file."
@@ -1300,11 +1293,10 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method):
         if args[0] in ("-l", "list"):
             args.pop(0)
             ctx = CommandContext(legend + " listing", args, require_empty=True)
-            width = screenwidth()
             for arg in ctx.args:
                 metadata = History(arg)
                 sys.stdout.write("= %s %s\n" \
-                                 % (arg, ((width - len(arg) - 5) * "=")))
+                                 % (arg, ((WIDTH - len(arg) - 5) * "=")))
                 keys = metadata.symbols.keys()
                 if metadata.branch in keys:
                     keys.remove(metadata.branch)
diff --git a/srctest b/srctest
index 6e13892280593d41615614aecc55482fa4233497..2d00f92638fa633105880be301bbe6670056fa3f 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -66,7 +66,7 @@ src $TESTOPTS cat testfile1 | diff -u testfile1 -
 check "content check after second commit"
 
 cat >testfile2 <<EOF
-= testfile1 =================================================================
+= testfile1 ============================================================
 2     * 1970-01-02T00:01:00Z Second comment
 1     - 1970-01-02T00:00:00Z First comment
 EOF
@@ -76,13 +76,13 @@ diff -u testfile2 testfile3
 check "list test"
 
 cat >testfile2 <<EOF
-= testfile1 =================================================================
+= testfile1 ============================================================
 2    | 1970-01-02T00:01:00Z
 Second comment
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 1    | 1970-01-02T00:00:00Z
 First comment
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 EOF
 
 src $TESTOPTS log testfile1 >testfile3
@@ -102,16 +102,16 @@ src $TESTOPTS commit -f testfile4 testfile1 >/dev/null
 check "commit with -f"
 
 cat >testfile4 <<EOF
-= testfile1 =================================================================
+= testfile1 ============================================================
 3    | 1970-01-02T00:02:00Z
 'Third' comment
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 2    | 1970-01-02T00:01:00Z
 Second comment
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 1    | 1970-01-02T00:00:00Z
 First comment
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 EOF
 
 src $TESTOPTS log testfile1 >testfile5
@@ -119,7 +119,7 @@ diff -u testfile4 testfile5
 check "3-commit log test"
 
 cat >testfile6 <<EOF
-= testfile1 =================================================================
+= testfile1 ============================================================
 src: testfile1 has no 5 revision
 EOF
 
@@ -139,7 +139,7 @@ src $TESTOPTS tag create sampletag
 check "tag set to default tip revision"
 
 cat >testfile8 <<EOF
-= testfile1 =================================================================
+= testfile1 ==========================================================
    3   sampletag
 EOF
 src $TESTOPTS tag list >testfile9
@@ -150,7 +150,7 @@ src $TESTOPTS tag create basetag 1
 check "tag set to revision 1"
 
 cat >testfile10 <<EOF
-= testfile1 =================================================================
+= testfile1 ==========================================================
    1   basetag
    3   sampletag
 EOF
@@ -162,7 +162,7 @@ src $TESTOPTS tag delete sampletag
 check "tag deletion: sampletag"
 
 cat >testfile12 <<EOF
-= testfile1 =================================================================
+= testfile1 ==========================================================
    1   basetag
 EOF
 src $TESTOPTS tag >testfile13
@@ -467,22 +467,22 @@ text
 EOF
 
 cat >sample.seqlog <<EOF
-= sample ====================================================================
+= sample ===============================================================
 6    | 1970-01-02T00:05:00Z
 Still utterly fubar
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 5    | 1970-01-02T00:04:00Z
 Totally unfubared.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 4    | 1970-01-02T00:03:00Z
 On a branch?
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 3    | 1970-01-02T00:02:00Z
 Third comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 2    | 1970-01-02T00:01:00Z
 Second comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 EOF
 
 src $TESTOPTS log 2-6 sample >tryit
@@ -490,19 +490,19 @@ diff -u tryit sample.seqlog
 check "traversal by -"
 
 cat >sample.branchlog <<EOF
-= sample ====================================================================
+= sample ===============================================================
 6    | 1970-01-02T00:05:00Z
 Still utterly fubar
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 5    | 1970-01-02T00:04:00Z
 Totally unfubared.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 3    | 1970-01-02T00:02:00Z
 Third comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 2    | 1970-01-02T00:01:00Z
 Second comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 EOF
 
 src $TESTOPTS log 2..6 sample >tryit
@@ -510,7 +510,7 @@ diff -u tryit sample.branchlog
 check "traversal by .."
 
 cat >sample.taglog <<EOF
-= sample ====================================================================
+= sample ===============================================================
 4     - 1970-01-02T00:03:00Z On a branch?
 EOF
 
@@ -522,7 +522,7 @@ src $TESTOPTS rename tag GLARB GROTTY sample
 check "tag renaming"
 
 cat >changes <<EOF
-= sample ====================================================================
+= sample =============================================================
    8   GORP
    4   GROTTY
 EOF
@@ -532,7 +532,7 @@ diff -u tryit changes
 check "tag list after rename"
 
 cat >branchlist <<EOF
-= sample ====================================================================
+= sample =============================================================
    0   trunk
    3   muggle
    8   sample
@@ -546,7 +546,7 @@ diff -u tryit branchlist
 check "branch list content"
 
 cat >branchlog <<EOF
-= sample ====================================================================
+= sample ===============================================================
 4     - 1970-01-02T00:03:00Z On a branch?
 EOF
 
@@ -581,7 +581,7 @@ src $TESTOPTS branch delete trunk sample
 check "branch delete"
 
 cat >newlist <<EOF
-= sample ====================================================================
+= sample =============================================================
    0   trunk
    3   muggle
    7   sample
@@ -592,43 +592,43 @@ diff -u newlist tryit
 check "branch list check after delete" delete
 
 cat >newlog <<EOF
-= sample ====================================================================
+= sample ===============================================================
 12   | 1970-01-02T00:11:00Z
 I see you
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 11   | 1970-01-02T00:10:00Z
 That's good.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 10   | 1970-01-02T00:09:00Z
 No good.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 9    | 1970-01-02T00:08:00Z
 It' all good.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 8    | 1970-01-02T00:07:00Z
 All fixed up.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 7    | 1970-01-02T00:06:00Z
 Utterly fubar
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 6    | 1970-01-02T00:05:00Z
 Totally chenille.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 5    | 1970-01-02T00:04:00Z
 Still utterly fubar
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 4    | 1970-01-02T00:03:00Z
 Totally unfubared.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 3    | 1970-01-02T00:02:00Z
 Third comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 2    | 1970-01-02T00:01:00Z
 Second comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 1    | 1970-01-02T00:00:00Z
 First comment.
-------------------------------------------------------------------------------
+------------------------------------------------------------------------
 EOF
 
 src $TESTOPTS log sample >tryit