diff cmdline/org/tmatesoft/hg/console/Status.java @ 74:6f1b88693d48

Complete refactoring to org.tmatesoft
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 24 Jan 2011 03:14:45 +0100
parents 9a03a80a0f2f
children 61eedab3eb3e
line wrap: on
line diff
--- a/cmdline/org/tmatesoft/hg/console/Status.java	Sun Jan 23 04:06:18 2011 +0100
+++ b/cmdline/org/tmatesoft/hg/console/Status.java	Mon Jan 24 03:14:45 2011 +0100
@@ -16,20 +16,20 @@
  */
 package org.tmatesoft.hg.console;
 
-import static com.tmate.hgkit.ll.HgRepository.TIP;
+import static org.tmatesoft.hg.repo.HgRepository.TIP;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
-import com.tmate.hgkit.fs.RepositoryLookup;
-import com.tmate.hgkit.ll.HgDataFile;
-import com.tmate.hgkit.ll.HgRepository;
-import com.tmate.hgkit.ll.Internals;
-import com.tmate.hgkit.ll.LocalHgRepo;
-import com.tmate.hgkit.ll.Nodeid;
-import com.tmate.hgkit.ll.StatusCollector;
-import com.tmate.hgkit.ll.WorkingCopyStatusCollector;
+import org.tmatesoft.hg.core.Nodeid;
+import org.tmatesoft.hg.core.Path;
+import org.tmatesoft.hg.repo.HgDataFile;
+import org.tmatesoft.hg.repo.HgRepository;
+import org.tmatesoft.hg.repo.Internals;
+import org.tmatesoft.hg.repo.StatusCollector;
+import org.tmatesoft.hg.repo.WorkingCopyStatusCollector;
 
 /**
  *
@@ -39,14 +39,35 @@
 public class Status {
 
 	public static void main(String[] args) throws Exception {
-		RepositoryLookup repoLookup = new RepositoryLookup();
-		RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args);
-		HgRepository hgRepo = repoLookup.detect(cmdLineOpts);
+		Options cmdLineOpts = Options.parse(args);
+		HgRepository hgRepo = cmdLineOpts.findRepository();
 		if (hgRepo.isInvalid()) {
 			System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
 			return;
 		}
 		System.out.println(hgRepo.getLocation());
+		//
+//		bunchOfTests(hgRepo);
+		//
+//		new Internals(hgRepo).dumpDirstate();
+		//
+		mardu(hgRepo);
+	}
+	
+	private static void mardu(HgRepository hgRepo) {
+		WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo);
+		StatusCollector.Record r = new StatusCollector.Record();
+		wcc.walk(TIP, r);
+		sortAndPrint('M', r.getModified());
+		sortAndPrint('A', r.getAdded(), r.getCopied());
+		sortAndPrint('R', r.getRemoved());
+		sortAndPrint('?', r.getUnknown());
+//		sortAndPrint('I', r.getIgnored());
+//		sortAndPrint('C', r.getClean());
+		sortAndPrint('!', r.getMissing());
+	}
+
+	private static void bunchOfTests(HgRepository hgRepo) throws Exception {
 		Internals debug = new Internals(hgRepo);
 		debug.dumpDirstate();
 		final StatusDump dump = new StatusDump();
@@ -66,7 +87,7 @@
 		System.out.println("\n\nTry hg status --change <rev>:");
 		sc.change(0, dump);
 		System.out.println("\nStatus against working dir:");
-		WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo, ((LocalHgRepo) hgRepo).createWorkingDirWalker());
+		WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(hgRepo);
 		wcc.walk(TIP, dump);
 		System.out.println();
 		System.out.printf("Manifest of the revision %d:\n", r2);
@@ -75,7 +96,7 @@
 		System.out.printf("\nStatus of working dir against %d:\n", r2);
 		r = wcc.status(r2);
 		sortAndPrint('M', r.getModified());
-		sortAndPrint('A', r.getAdded());
+		sortAndPrint('A', r.getAdded(), r.getCopied());
 		sortAndPrint('R', r.getRemoved());
 		sortAndPrint('?', r.getUnknown());
 		sortAndPrint('I', r.getIgnored());
@@ -84,17 +105,23 @@
 	}
 	
 	private static void sortAndPrint(char prefix, List<String> ul) {
+		sortAndPrint(prefix, ul, null);
+	}
+	private static void sortAndPrint(char prefix, List<String> ul, Map<String, String> copies) {
 		ArrayList<String> sortList = new ArrayList<String>(ul);
 		Collections.sort(sortList);
 		for (String s : sortList)  {
 			System.out.print(prefix);
 			System.out.print(' ');
 			System.out.println(s);
+			if (copies != null && copies.containsKey(s)) {
+				System.out.println("  " + copies.get(s));
+			}
 		}
 	}
 	
 	protected static void testStatusInternals(HgRepository hgRepo) {
-		HgDataFile n = hgRepo.getFileNode("design.txt");
+		HgDataFile n = hgRepo.getFileNode(Path.create("design.txt"));
 		for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) {
 			// expected: 359, 2123, 3079
 			byte[] b = s.getBytes();