Commits

Alex Efros committed 3464259

vcprompt-hgst will check for unknown files only when user need it

  • Participants
  • Parent commits a4ebb6f

Comments (0)

Files changed (2)

     read_parents(context, result);
 
     if (context->options->show_modified || context->options->show_unknown) {
-        int status = system("vcprompt-hgst");
+        int status = system(context->options->show_unknown ? "vcprompt-hgst -u" : "vcprompt-hgst");
         if (WEXITSTATUS(status) <= 3) {
             if (WEXITSTATUS(status) & 1<<0)
                 result->modified = 1;

File vcprompt-hgst

 # .hg/dirstate cache outdated), this can be fixed by updating cache (for
 # ex. by running real `hg st`).
 # 
+# Options:
+#   -u      detect unknown files
+# 
 # Exit codes:
 #   0 - no modified or unknown files detected
 #   1 - modified files detected
 # use warnings;
 # use strict;
 
-our $VERSION = 2.01;
+our $VERSION = 2.02;
+
+my $need_unknown = @ARGV && $ARGV[0] eq '-u';
 
 my $found_modified = 0;
 my $found_unknown  = 0;
     $filename =~ s/\0.*//s;
 
     $filename =~ m{(.*/)?(.+)}s    or exit 255;
-    $seen{$1}{$2} = 1;
+    $seen{$1 || q{}}{$2} = 1;
 
     if (!$found_modified) {
         my @stat = lstat $filename;
         if (@stat && !($stat[2]==$mode && $stat[7]==$size && $stat[9]==$mtime)) {
             $found_modified = 1;
+            last if !$need_unknown;
         }
     }
 }
 
-my @dirs = (q{});   # dirs here must end with /, except root dir (empty string)
+if ($need_unknown) {
+    my @dirs = (q{});   # dirs here must end with /, except root dir (empty string)
 DIR: while (@dirs) {
-    my $dir = shift @dirs;
-    next if $dir eq '.hg/';
+        my $dir = shift @dirs;
+        next if $dir eq '.hg/';
 
-    my $known = $seen{$dir} || {};
-    $known->{'.'} = $known->{'..'} = 1;
+        my $known = $seen{$dir} || {};
+        $known->{'.'} = $known->{'..'} = 1;
 
-    opendir my $d, $dir || './'     or exit 255;
-    for my $name (readdir $d) {
-        if (!$known->{$name} && "$dir$name" !~ /$hgignore/o) {
-            if (-d "$dir$name") {
-                push @dirs, "$dir$name/";
-            }
-            else {
-                $found_unknown = 1;
-                last DIR;
+        opendir my $d, $dir || './'     or exit 255;
+        for my $name (readdir $d) {
+            if (!$known->{$name} && "$dir$name" !~ /$hgignore/o) {
+                if (-d "$dir$name") {
+                    push @dirs, "$dir$name/";
+                }
+                else {
+                    $found_unknown = 1;
+                    last DIR;
+                }
             }
         }
     }