]> thyrsus.com Git - src.git/commitdiff
There's a src status command now.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 02:35:57 +0000 (21:35 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 02:35:57 +0000 (21:35 -0500)
NEWS
src
src.asc

diff --git a/NEWS b/NEWS
index ce191f49d9d5240257f3864293f969959a2bcb39..267b0f239ae2b2735c8f9e3767877c2d96c5dd34 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 `                      src project news
 
+Repositry head:
+   There is now a "src status" command
+
 0.2: 2014-11-08
    There is a public repository on Gitorious
    All the initially projected commands except branch are impplemented.
diff --git a/src b/src
index 64d946efdf1305d9178fbc421d06b4e59ecb4aab..f77e47a2f34d9dc903b309439d80d9f329fd6e94 100755 (executable)
--- a/src
+++ b/src
@@ -275,6 +275,9 @@ src checkout ['revision-spec'] ['file'...]
    Refresh the working copy of the file(s) from their history files.
    co is a synonym for checkout.
 
+src status ['file'...]
+   A = added, U = unmodified, M = modified, ! = missing, ? = not tracked.
+
 src cat [revision-spec] ['file'...]
    Send the specified revisions of the files to standard output.
 
@@ -501,9 +504,50 @@ def checkout_method(*args):
             revision = master[len(master) - revspec[0]].revision
         with backend.lifter(arg):
             backend.checkout(arg, revision)
+            # Changes the access and modification times
+            # Later, src status will see this.  Alas,
+            # there's a tiny race window here.
+            os.utime(backend.master(arg, None))
         if not quiet and len(args) > 1:
             announce("%s <- %d" % (arg, revspec[0])) 
 
+def status_method(*args):
+    "Get status of some or all fles."
+    try:
+        registered = os.listdir(repodir)
+    except OSError:
+        croak("repo directory %s does not exist" % repodir)
+    if args:
+        candidates = args
+    else:
+        candidates = [f for f in os.listdir(".") if f != repodir]
+    pairs = []
+    for fn in candidates:
+        masterbase = os.path.basename(backend.master(fn))
+        if masterbase not in registered:
+            pairs.append((fn, "?"))
+            continue
+        elif not os.path.exists(fn):
+            pairs.append((fn, "!"))
+            continue
+        # Relies on the fact that we touch the file with utimes(2)
+        # each time it's checked out.
+        elif os.path.getmtime(fn) > os.path.getmtime(backend.master(fn)):
+            pairs.append((fn, "M"))
+            continue
+        metadata = History(fn)
+        if len(metadata) == 0:
+            pairs.append((fn, "A"))
+        else:
+            pairs.append((fn, "U"))
+    if not args:
+        for m in registered:
+            if backend.workfile(m) not in candidates:
+                pairs.append((backend.workfile(m), "!"))
+    pairs.sort()
+    for (fn, status) in pairs:
+        sys.stdout.write(status + "\t" + fn + "\n")
+
 def cat_method(*args):
     "Dump revision content to standard output."
     (revspec, args) = preamble("cat", args)
@@ -723,6 +767,7 @@ dispatch = {
     "log":         log_method,
     "checkout":    checkout_method,
     "co":          checkout_method,
+    "status":      status_method,
     "cat":         cat_method,
     "diff":        diff_method,
     "tag":         tag_method,
diff --git a/src.asc b/src.asc
index 9463fc1c9e6197fe6882ce627b2d6159c45b2810..1070db69513d9c24b9dd817143143ace4544704d 100644 (file)
--- a/src.asc
+++ b/src.asc
@@ -59,6 +59,9 @@ src checkout [revision-spec] ['file'...]::
    Refresh the working copy of the file(s) from their history files.
    co is a synonym for checkout.
 
+src status ['file'...]::
+   A = added, U = unmodified, M = modified, ! = missing, ? = not tracked.
+
 src cat [revision-spec] ['file'...]::
    Send the specified revisions of the files to standard output.