Commits

Armin Ronacher  committed 61263e9

Finished defaults support

  • Participants
  • Parent commits b888163

Comments (0)

Files changed (7)

File src/common.c

 
 #include "common.h"
 
-result_t* init_result()
+result_t* init_result(options_t* options)
 {
     result_t *rv = (result_t*) calloc(1, sizeof(result_t));
     ASSERT_NOOM(rv);
+    if (options->default_branch)
+        result_set_branch(rv, options->default_branch);
+    if (options->default_revision)
+        result_set_revision(rv, options->default_revision, -1);
     return rv;
 }
 

File src/common.h

                           result_t* (*get_info)(vccontext_t*));
 void free_context(vccontext_t* context);
     
-result_t* init_result();
+result_t* init_result(options_t* options);
 void free_result(result_t*);
 
 void debug(char*, ...);
 static result_t*
 cvs_get_info(vccontext_t* context)
 {
-    result_t* result = init_result();
+    result_t* result = init_result(context->options);
     char buf[1024];
 
     if (!read_first_line("CVS/Tag", buf, 1024)) {
 static result_t*
 git_get_info(vccontext_t* context)
 {
-    result_t* result = init_result();
+    result_t* result = init_result(context->options);
     char buf[1024];
 
     if (!read_first_line(".git/HEAD", buf, 1024)) {
 static result_t*
 hg_get_info(vccontext_t* context)
 {
-    result_t* result = init_result();
+    result_t* result = init_result(context->options);
     char buf[1024];
 
     // prefers bookmark because it tends to be more informative
 static result_t*
 svn_get_info(vccontext_t* context)
 {
-    result_t* result = init_result();
+    result_t* result = init_result(context->options);
     char buf[1024];
 
     if (!read_first_line(".svn/entries", buf, 1024)) {

File src/vcprompt.c

 
 static size_t read_default_format(const char* format, size_t i, char** out)
 {
-    size_t start = i + 1;
+    size_t start = i;
+    size_t length = 0;
     while (format[i] && format[i] != ']')
-        i++;
+        i++, length++;
     if (format[i])
         i++;
-    *out = malloc(i - start + 1);
-    strncpy(*out, format + start, i - start);
+    *out = malloc(length + 1);
+    strncpy(*out, format + start, length);
     return i;
 }
 
                 case '\0':              /* at end of string: ignore */
                     break;
                 case '[':               /* default section */
-                    i = read_default_format(format, i, &next_default);
+                    i = read_default_format(format, i + 1, &next_default);
                     goto test;          /* consumed default, try again */
                 case 'b':
                     options->show_branch = 1;