#include "refs.h"
#include "commit.h"
-#define CHUNK_SIZE (1048576)
+#define CHUNK_SIZE 1024
static char *get_stdin(void)
{
+ int offset = 0;
char *data = xmalloc(CHUNK_SIZE);
- int offset = 0, read = 0;
- read = xread(0, data, CHUNK_SIZE);
- while (read == CHUNK_SIZE) {
- offset += CHUNK_SIZE;
+
+ while (1) {
+ int cnt = xread(0, data + offset, CHUNK_SIZE);
+ if (cnt < 0)
+ die("error reading standard input: %s",
+ strerror(errno));
+ if (cnt == 0) {
+ data[offset] = 0;
+ break;
+ }
+ offset += cnt;
data = xrealloc(data, offset + CHUNK_SIZE);
- read = xread(0, data + offset, CHUNK_SIZE);
}
return data;
}
-static void show_new(char *type, unsigned char *sha1_new)
+static void show_new(enum object_type type, unsigned char *sha1_new)
{
- fprintf(stderr, " %s: %s\n", type,
+ fprintf(stderr, " %s: %s\n", typename(type),
find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
}
const char *note,
int verbose, int force)
{
- char type[20];
unsigned char sha1_old[20], sha1_new[20];
char oldh[41], newh[41];
struct commit *current, *updated;
+ enum object_type type;
if (get_sha1_hex(new_head, sha1_new))
die("malformed object name %s", new_head);
- if (sha1_object_info(sha1_new, type, NULL))
+
+ type = sha1_object_info(sha1_new, NULL);
+ if (type < 0)
die("object %s not found", new_head);
if (!*name) {
remote_len = i + 1;
if (4 < i && !strncmp(".git", remote + i - 3, 4))
remote_len = i - 3;
- note_len = sprintf(note, "%s\t%s\t",
- sha1_to_hex(commit ? commit->object.sha1 : sha1),
- not_for_merge ? "not-for-merge" : "");
+
+ note_len = 0;
if (*what) {
if (*kind)
note_len += sprintf(note + note_len, "%s ", kind);
note_len += sprintf(note + note_len, "'%s' of ", what);
}
note_len += sprintf(note + note_len, "%.*s", remote_len, remote);
- fprintf(fp, "%s\n", note);
+ fprintf(fp, "%s\t%s\t%s\n",
+ sha1_to_hex(commit ? commit->object.sha1 : sha1),
+ not_for_merge ? "not-for-merge" : "",
+ note);
return update_local_ref(local_name, head, note, verbose, force);
}
eol = !next ? (ls + strlen(ls)) : next;
if (!memcmp("^{}", eol-3, 3))
continue;
+ if (eol - ls < 40)
+ continue;
if (get_sha1_hex(ls, sha1))
continue;
ls += 40;
fclose(fp);
return result;
}
- if (!strcmp("update-local-ref", argv[1])) {
- if (argc != 5)
- return error("update-local-ref takes 3 args");
- return update_local_ref(argv[2], argv[3], argv[4],
- verbose, force);
- }
if (!strcmp("native-store", argv[1])) {
int result;
FILE *fp;