From 294f8c54d5ae902e02b91470269737be242e053f Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 8 Nov 2014 21:35:57 -0500 Subject: [PATCH] There's a src status command now. --- NEWS | 3 +++ src | 45 +++++++++++++++++++++++++++++++++++++++++++++ src.asc | 3 +++ 3 files changed, 51 insertions(+) diff --git a/NEWS b/NEWS index ce191f4..267b0f2 100644 --- 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 64d946e..f77e47a 100755 --- 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 9463fc1..1070db6 100644 --- 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. -- 2.43.0