1. dev4dev
  2. vcprompt

Commits

Greg Ward  committed 59b20a1

Allow truncating revision numbers. Necessary for git %r to work sensibly.

  • Participants
  • Parent commits e886396
  • Branches default

Comments (0)

Files changed (5)

File src/common.c

View file
  • Ignore whitespace
     _options = options;
 }
 
-int result_set_revision(result_t* result, const char *revision)
+int result_set_revision(result_t* result, const char *revision, int len)
 {
     if (result->revision)
         free(result->revision);
-    result->revision = strdup(revision);
+    if (len == -1)
+        result->revision = strdup(revision);
+    else
+        result->revision = strndup(revision, len);
     return !!result->revision;
 }
 

File src/common.h

View file
  • Ignore whitespace
     int modified;                       /* any local changes? */
 } result_t;
 
-int result_set_revision(result_t* result, const char *revision);
+int result_set_revision(result_t* result, const char *revision, int len);
 int result_set_branch(result_t* result, const char *branch);
 
 typedef struct vccontext_t vccontext_t;

File src/git.c

View file
  • Ignore whitespace
                 /* if it's not a branch name, assume it is a commit ID */
                 debug(".git/HEAD doesn't look like a head ref: unknown branch");
                 result_set_branch(result, "(unknown)");
-                result_set_revision(result, buf);
+                result_set_revision(result, buf, 12);
             }
             if (context->options->show_revision && found_branch) {
                 char buf[1024];
                 strcat(filename, ".git/refs/heads/");
                 strncat(filename, result->branch, 1000);
                 if (read_first_line(filename, buf, 1024)) {
-                    buf[12] = '0';
-                    result_set_revision(result, buf);
+                    result_set_revision(result, buf, 12);
                 }
             }
         }

File src/hg.c

View file
  • Ignore whitespace
     }
 
 push:
-    result_set_revision(result, rev);
+    result_set_revision(result, rev, -1);
 }
 
 static void
         if (!patch) return;
         patch += 1;
         debug("patch name found: '%s'", patch);
-        result_set_revision(result, patch);
+        result_set_revision(result, patch, -1);
     }
     else {
         debug("failed to read from .hg/patches/status: assuming no mq patch applied");

File src/svn.c

View file
  • Ignore whitespace
                     return NULL;
                 }
                 if (sscanf(p, " %*[^\"]\"%[0-9]\"", rev) == 1) {
-                    result_set_revision(result, rev);
+                    result_set_revision(result, rev, -1);
                     debug("read svn revision from .svn/entries: '%s'", rev);
                 }
             }