5ed8a7b0f2ad — Sean Farley 12 years ago
fast-status: change prototype to pass pwd only
1 files changed, 7 insertions(+), 4 deletions(-)

M fast-hg-status.c
M fast-hg-status.c +7 -4
@@ 44,10 44,11 @@ void go_up_one_dir(char* dir_path) {
   }
 }
 
-int parse_dirstate(const char* hg_path, const char* dirstate) {
+int parse_dirstate(const char* pwd) {
   FILE          *f        = NULL;
   char           filename[PATH_MAX+1];
   char           filepath[PATH_MAX+1];
+  char           dirstate[PATH_MAX+1];
   size_t         i, bytes_read;
   unsigned char  status;             /* needs to be 8 bits */
   unsigned int   mode, size, length; /* each need to be 32 bits */

          
@@ 55,6 56,8 @@ int parse_dirstate(const char* hg_path, 
   mode_t         u;                  /* original mask of the current file or process */
   struct stat    filestat;
 
+  sprintf(dirstate, "%s/.hg/dirstate", pwd);
+
   f = fopen(dirstate, "rb");
   if (!f) return -1;
 

          
@@ 103,7 106,7 @@ int parse_dirstate(const char* hg_path, 
 
     PRINT("[%zu] filename: %s\n\n", i, filename);
 
-    sprintf(filepath, "%s/%s", hg_path, filename);
+    sprintf(filepath, "%s/%s", pwd, filename);
 
     /* size needs to be >= 0 by definition of the dirstate */
     if (lstat(filepath, &filestat)) return -2;

          
@@ 137,10 140,10 @@ int main() {
   getcwd(pwd, PATH_MAX+1);
 
   while ((l = strlen(pwd)) > 0) {
-    sprintf(hg_path, "%s/.hg/dirstate", pwd);
+    sprintf(hg_path, "%s/.hg", pwd);
     denied = access(hg_path, R_OK);
 
-    if (!denied) return parse_dirstate(pwd, hg_path);
+    if (!denied) return parse_dirstate(pwd);
 
     go_up_one_dir(pwd);
   }