1. Esben Skovenborg
  2. hg_timestamp_update

Commits

Esben Skovenborg  committed c60e644

Added multi-level control over verbosity, verbose_level = 0 means quiet.
Computing and printing elapsed time in hg_timestamp.main() - if verbose_level >= 2.

  • Participants
  • Parent commits 3532af4
  • Branches default

Comments (0)

Files changed (1)

File src/hg_timestamp.java

View file
 
 class hg_timestamp {
 
-	static boolean verbose = false;
-	static final String version_string = "0.2";
+	static int verbose = 1;  // 0 = quiet, higher = more
+	static final String version_string = "0.3";
 	static final String style_name = "hg_timestamp_files.style";
 
 	public static void main(String args[])
 
 		if (args.length < 2) {
 			System.err.println("hg_timestamp version " + version_string);
-			System.err.println("Syntax: hg_timestamp <pre_update_rev> <update_rev> [<verbose_bool>]");
+			System.err.println("Syntax: hg_timestamp <pre_update_rev> <update_rev> [<verbose_level>]");
 			System.exit(-1);
 		}
 		final String preupdaterev = args[0];
 		final String updaterev = args[1];
 		if (args.length >= 3) {
-			verbose = Boolean.parseBoolean(args[2]);
+			verbose = Integer.parseInt(args[2]);
 		}
 
+		long startTime = System.currentTimeMillis();
+
 		String hg_command[] = {
 			"hg", "log",
 			"--rev=" + preupdaterev + ":" + updaterev,
 			"--style=" + style_name};
-		if (verbose) {
+		if (verbose >= 2) {
 			System.err.printf("Running %s:\n", Arrays.toString(hg_command));
 		}
 
 		// Therefore we use: http://ostermiller.org/utils/doc/com/Ostermiller/util/ExecHelper.html
 		ExecHelper eh = ExecHelper.exec(hg_command);
 
-		if (verbose) {
+		if (verbose >= 2) {
 			System.err.println("... returned code: " + eh.getStatus());
 		}
 		if (eh.getStatus() != 0) {
 		// ISO-format might not be the most efficient way of passing a date from "hg log", but it's nice for debugging :)
 
 		String line1, line2;
-        Date date_time = null;
+		Date date_time = null;
 		int revs = 0;
 		while ((line1 = br.readLine()) != null) {
 			//System.err.printf("Line1: '%s'\n",line1);
         
         if ((updaterev_date != null) && (! updaterev_date.equals(new Date(0)))) {
 			
-			//if (verbose)
-			System.out.printf("[hg_timestamp hook] processing %d revisions, with %d unique file-names...\n",
+			if (verbose >= 1)
+				System.out.printf("[hg_timestamp hook] processing %d revisions, with %d unique file-names...\n",
 					revs, fileMap.size());
 	
 			Charset charset = Charset.defaultCharset();
 			//Charset charset = Charset.forName("UTF-8");  // override default if necessary
-			if (verbose)
+			if (verbose >= 2)
 				System.err.printf("Using charset: %s\n", charset.displayName());
 	
 			// Now iterate through the files, and "touch" each one
 				
 				if (updaterev_date.compareTo(date) < 0) {
 					// file date in map is posterior to update rev: get the real last modified date for this file
-					String hg_commandf[] = {"hg", "log", "--rev=" + updaterev + ":null", "--limit=1", "--template={date|isodatesec}", filename};
+					String hg_commandf[] = {"hg", "log", "--rev=" + updaterev + ":null", "--limit=1",
+						"--template={date|isodatesec}", filename};
 					//System.err.printf("Running %s:\n", Arrays.toString(hg_commandf));
 					
 					ExecHelper ehf = ExecHelper.exec(hg_commandf);
 				
 				if (date != null) {
 					boolean touchRet = touchDontCreate(filename, date);
-					if (verbose) {
+					if (verbose >= 3) {
 						System.err.printf("%-50s = %s", filename, sdf.format(date).toString());
 						if (!touchRet) {
 							System.err.println(" *NO TOUCH*");
 				}
 			}
 		}
+		
+		if (verbose >= 2) {
+			float elapsedTime = (System.currentTimeMillis() - startTime) / 1000F;
+			System.out.println("Elapsed time in hg_timestamp.main(): " + Float.toString(elapsedTime) + " seconds.");
+		}
 
 	}  // main