Commits

Robson Peixoto  committed 6ff13c8

Add svn 1.7 support

  • Participants
  • Parent commits 605e46d
  • Branches svn-1.7

Comments (0)

Files changed (2)

 objects = $(subst .c,.o,$(sources))
 
 vcprompt: $(objects)
-	$(CC) -o $@ $(objects)
+	$(CC) -l sqlite3 -o $@ $(objects)
 
 # build a standalone version of capture_child() library for testing
 src/capture: src/capture.c src/capture.h src/common.c src/common.h
+
 /*
  * Copyright (C) 2009-2013, Gregory P. Ward and contributors.
  *
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <sqlite3.h>
+#include <unistd.h>
 #include "common.h"
 #include "svn.h"
 
     FILE *fp = NULL;
     char buf[1024];
 
+    int retval;
+    sqlite3 *conn;
+    sqlite3_stmt    *res;
+    const char      *tail;
+
     if (!read_first_line(".svn/entries", buf, 1024)) {
         debug("failed to read from .svn/entries: not an svn working copy");
         goto err;
     }
     char line[1024];
 
-    // Check the version
-    if (fgets(line, sizeof(line), fp)) {
-        if(isdigit(line[0])) {
-            // Custom file format (working copy created by svn >= 1.4)
+    if( access( ".svn/wc.db", F_OK ) == 0 ) {
+        // Custom file format (working copy created by svn >= 1.7)
 
-            // Read and discard line 2 (name), 3 (entries kind)
-            if (fgets(line, sizeof(line), fp) == NULL ||
-                fgets(line, sizeof(line), fp) == NULL) {
-                debug("early EOF reading .svn/entries");
-                goto err;
-            }
+        retval = sqlite3_open(".svn/wc.db", &conn);
+        if(retval) {
+            debug("Can not open database");
+            goto err;
+        }
+        retval = sqlite3_prepare_v2(conn, "select max(revision) from NODES", 1000, &res, &tail);
+        if(retval) {
+            debug("Can not run the query");
+            goto err_sqlite;
+        }
+        else {
+            sqlite3_step(res);
+            sprintf(buf, "%s", sqlite3_column_text(res, 0));
+            result->revision = strdup(buf);
+            sqlite3_finalize(res);
+            sqlite3_close(conn);
+        }
+    }
+    else {
+        // Custom file format (working copy created by svn <= 1.7)
+        // Check the version
+        if (fgets(line, sizeof(line), fp)) {
+            if(isdigit(line[0])) {
+                // Custom file format (working copy created by svn >= 1.4)
 
-            // Get the revision number
-            if (fgets(line, sizeof(line), fp)) {
-                chop_newline(line);
-                result->revision = strdup(line);
-                debug("read a svn revision from .svn/entries: '%s'", line);
+                // Read and discard line 2 (name), 3 (entries kind)
+                if (fgets(line, sizeof(line), fp) == NULL ||
+                    fgets(line, sizeof(line), fp) == NULL) {
+                    debug("early EOF reading .svn/entries");
+                    goto err;
+                }
+
+                // Get the revision number
+                if (fgets(line, sizeof(line), fp)) {
+                    chop_newline(line);
+                    result->revision = strdup(line);
+                    debug("read a svn revision from .svn/entries: '%s'", line);
+                }
+                else {
+                    debug("early EOF: expected revision number");
+                    goto err;
+                }
             }
             else {
-                debug("early EOF: expected revision number");
-                goto err;
-            }
-        }
-        else {
-            // XML file format (working copy created by svn < 1.4)
-            char rev[100];
-            char *marker = "revision=";
-            char *p = NULL;
-            while (fgets(line, sizeof(line), fp))
-                if ((p = strstr(line, marker)) != NULL)
-                    break;
-            if (p == NULL) {
-                debug("no 'revision=' line found in .svn/entries");
-                goto err;
-            }
-            if (sscanf(p, " %*[^\"]\"%[0-9]\"", rev) == 1) {
-                result_set_revision(result, rev, -1);
-                debug("read svn revision from .svn/entries: '%s'", rev);
+                // XML file format (working copy created by svn < 1.4)
+                char rev[100];
+                char *marker = "revision=";
+                char *p = NULL;
+                while (fgets(line, sizeof(line), fp))
+                    if ((p = strstr(line, marker)) != NULL)
+                        break;
+                if (p == NULL) {
+                    debug("no 'revision=' line found in .svn/entries");
+                    goto err;
+                }
+                if (sscanf(p, " %*[^\"]\"%[0-9]\"", rev) == 1) {
+                    result_set_revision(result, rev, -1);
+                    debug("read svn revision from .svn/entries: '%s'", rev);
+                }
             }
         }
     }
     fclose(fp);
     return result;
 
+ err_sqlite:
+    sqlite3_finalize(res);
+    sqlite3_close(conn);
+
  err:
     free(result);
     if (fp)