* [PATCH 1/4] add mode parameter to get_sha1
@ 2007-04-21 12:26 Martin Koegler
2007-04-21 12:26 ` [PATCH 2/4] add support for storing the mode in object_array Martin Koegler
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Martin Koegler @ 2007-04-21 12:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jakub Narebski, git, Martin Koegler
If the mode parameter is not NULL, get_sha1 will store
the mode of the object in it.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
builtin-apply.c | 2 +-
builtin-archive.c | 2 +-
builtin-blame.c | 2 +-
builtin-branch.c | 2 +-
builtin-cat-file.c | 2 +-
builtin-commit-tree.c | 4 ++--
builtin-describe.c | 2 +-
builtin-diff.c | 2 +-
builtin-fetch--tool.c | 4 ++--
builtin-fmt-merge-msg.c | 2 +-
builtin-fsck.c | 2 +-
builtin-grep.c | 2 +-
builtin-log.c | 2 +-
builtin-ls-tree.c | 2 +-
builtin-merge-base.c | 4 ++--
builtin-name-rev.c | 4 ++--
builtin-read-tree.c | 2 +-
builtin-rev-parse.c | 8 ++++----
builtin-revert.c | 4 ++--
builtin-rm.c | 2 +-
builtin-show-branch.c | 8 ++++----
builtin-update-ref.c | 4 ++--
cache.h | 5 ++++-
connect.c | 2 +-
convert-objects.c | 2 +-
fast-import.c | 8 ++++----
merge-recursive.c | 2 +-
merge-tree.c | 2 +-
revision.c | 14 +++++++-------
sha1_name.c | 8 ++++++--
ssh-upload.c | 2 +-
unpack-file.c | 2 +-
upload-pack.c | 2 +-
wt-status.c | 2 +-
34 files changed, 63 insertions(+), 56 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 94311e7..a053403 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2159,7 +2159,7 @@ static void show_index_list(struct patch *list)
name = patch->old_name ? patch->old_name : patch->new_name;
if (0 < patch->is_new)
sha1_ptr = null_sha1;
- else if (get_sha1(patch->old_sha1_prefix, sha1))
+ else if (get_sha1(patch->old_sha1_prefix, sha1, NULL))
die("sha1 information is lacking or useless (%s).",
name);
else
diff --git a/builtin-archive.c b/builtin-archive.c
index 7f4e409..97b4dcb 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -112,7 +112,7 @@ void parse_treeish_arg(const char **argv, struct archiver_args *ar_args,
struct commit *commit;
unsigned char sha1[20];
- if (get_sha1(name, sha1))
+ if (get_sha1(name, sha1, NULL))
die("Not a valid object name");
commit = lookup_commit_reference_gently(sha1, 1);
diff --git a/builtin-blame.c b/builtin-blame.c
index 8919b02..7777748 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -1935,7 +1935,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
struct cache_entry *ce;
unsigned mode;
- if (get_sha1("HEAD", head_sha1))
+ if (get_sha1("HEAD", head_sha1, NULL))
die("No such ref: HEAD");
time(&now);
diff --git a/builtin-branch.c b/builtin-branch.c
index 7408285..66ef90c 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -442,7 +442,7 @@ static void create_branch(const char *name, const char *start_name,
}
real_ref = NULL;
- if (get_sha1(start_name, sha1))
+ if (get_sha1(start_name, sha1, NULL))
die("Not a valid object name: '%s'.", start_name);
switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index d61d3d5..11512da 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -87,7 +87,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
git_config(git_default_config);
if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
- if (get_sha1(argv[2], sha1))
+ if (get_sha1(argv[2], sha1, NULL))
die("Not a valid object name %s", argv[2]);
opt = 0;
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index 4a8d8d8..1b5a572 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -97,7 +97,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
if (argc < 2)
usage(commit_tree_usage);
- if (get_sha1(argv[1], tree_sha1))
+ if (get_sha1(argv[1], tree_sha1, NULL))
die("Not a valid object name %s", argv[1]);
check_valid(tree_sha1, OBJ_TREE);
@@ -109,7 +109,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
if (parents >= MAXPARENT)
die("Too many parents (%d max)", MAXPARENT);
- if (get_sha1(b, parent_sha1[parents]))
+ if (get_sha1(b, parent_sha1[parents], NULL))
die("Not a valid object name %s", b);
check_valid(parent_sha1[parents], OBJ_COMMIT);
if (new_parent(parents))
diff --git a/builtin-describe.c b/builtin-describe.c
index 165917e..1d5467f 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -135,7 +135,7 @@ static void describe(const char *arg, int last_one)
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
unsigned long seen_commits = 0;
- if (get_sha1(arg, sha1))
+ if (get_sha1(arg, sha1, NULL))
die("Not a valid object name %s", arg);
cmit = lookup_commit_reference(sha1);
if (!cmit)
diff --git a/builtin-diff.c b/builtin-diff.c
index 21d13f0..5f1b50e 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -173,7 +173,7 @@ void add_head(struct rev_info *revs)
{
unsigned char sha1[20];
struct object *obj;
- if (get_sha1("HEAD", sha1))
+ if (get_sha1("HEAD", sha1, NULL))
return;
obj = parse_object(sha1);
if (!obj)
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index e9d6764..fe38d34 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -79,7 +79,7 @@ static int update_local_ref(const char *name,
return 0;
}
- if (get_sha1(name, sha1_old)) {
+ if (get_sha1(name, sha1_old, NULL)) {
char *msg;
just_store:
/* new ref */
@@ -148,7 +148,7 @@ static int append_fetch_head(FILE *fp,
char note[1024];
const char *what, *kind;
- if (get_sha1(head, sha1))
+ if (get_sha1(head, sha1, NULL))
return error("Not a valid object name: %s", head);
commit = lookup_commit_reference(sha1);
if (!commit)
diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index 5c145d2..89224c2 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -89,7 +89,7 @@ static int handle_line(char *line)
line[40] = 0;
sha1 = xmalloc(20);
- i = get_sha1(line, sha1);
+ i = get_sha1(line, sha1, NULL);
line[40] = '\t';
if (i)
return 3;
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 05d98d2..3ed2c50 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -674,7 +674,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
if (*arg == '-')
continue;
- if (!get_sha1(arg, head_sha1)) {
+ if (!get_sha1(arg, head_sha1, NULL)) {
struct object *obj = lookup_object(head_sha1);
/* Error is printed by lookup_object(). */
diff --git a/builtin-grep.c b/builtin-grep.c
index e13cb31..f2ee20f 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -673,7 +673,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
const char *arg = argv[i];
unsigned char sha1[20];
/* Is it a rev? */
- if (!get_sha1(arg, sha1)) {
+ if (!get_sha1(arg, sha1, NULL)) {
struct object *object = parse_object(sha1);
if (!object)
die("bad object %s", arg);
diff --git a/builtin-log.c b/builtin-log.c
index 38bf52f..1ca3aa9 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -648,7 +648,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
{
unsigned char sha1[20];
- if (get_sha1(arg, sha1) == 0) {
+ if (get_sha1(arg, sha1, NULL) == 0) {
struct commit *commit = lookup_commit_reference(sha1);
if (commit) {
commit->object.flags |= flags;
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index 6472610..40213ee 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -143,7 +143,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
if (argc < 2)
usage(ls_tree_usage);
- if (get_sha1(argv[1], sha1))
+ if (get_sha1(argv[1], sha1, NULL))
die("Not a valid object name %s", argv[1]);
pathspec = get_pathspec(prefix, argv + 2);
diff --git a/builtin-merge-base.c b/builtin-merge-base.c
index e35d362..7b415a1 100644
--- a/builtin-merge-base.c
+++ b/builtin-merge-base.c
@@ -39,9 +39,9 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
}
if (argc != 3)
usage(merge_base_usage);
- if (get_sha1(argv[1], rev1key))
+ if (get_sha1(argv[1], rev1key, NULL))
die("Not a valid object name %s", argv[1]);
- if (get_sha1(argv[2], rev2key))
+ if (get_sha1(argv[2], rev2key, NULL))
die("Not a valid object name %s", argv[2]);
rev1 = lookup_commit_reference(rev1key);
rev2 = lookup_commit_reference(rev2key);
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index c022224..0351185 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -184,7 +184,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
usage(name_rev_usage);
}
- if (get_sha1(*argv, sha1)) {
+ if (get_sha1(*argv, sha1, NULL)) {
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
*argv);
continue;
@@ -230,7 +230,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
forty = 0;
*(p+1) = 0;
- if (!get_sha1(p - 39, sha1)) {
+ if (!get_sha1(p - 39, sha1, NULL)) {
struct object *o =
lookup_object(sha1);
if (o)
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 316fb0f..06224aa 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -204,7 +204,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
if (1 < opts.index_only + opts.update)
usage(read_tree_usage);
- if (get_sha1(arg, sha1))
+ if (get_sha1(arg, sha1, NULL))
die("Not a valid object name %s", arg);
if (list_tree(sha1) < 0)
die("failed to unpack tree object %s", arg);
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 37addb2..370856b 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -130,7 +130,7 @@ static void show_default(void)
unsigned char sha1[20];
def = NULL;
- if (!get_sha1(s, sha1)) {
+ if (!get_sha1(s, sha1, NULL)) {
show_rev(NORMAL, sha1, s);
return;
}
@@ -186,7 +186,7 @@ static int try_difference(const char *arg)
next = "HEAD";
if (dotdot == arg)
this = "HEAD";
- if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
+ if (!get_sha1(this, sha1, NULL) && !get_sha1(next, end, NULL)) {
show_rev(NORMAL, end, next);
show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
if (symmetric) {
@@ -376,11 +376,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
/* Not a flag argument */
if (try_difference(arg))
continue;
- if (!get_sha1(arg, sha1)) {
+ if (!get_sha1(arg, sha1, NULL)) {
show_rev(NORMAL, sha1, arg);
continue;
}
- if (*arg == '^' && !get_sha1(arg+1, sha1)) {
+ if (*arg == '^' && !get_sha1(arg+1, sha1, NULL)) {
show_rev(REVERSED, sha1, arg+1);
continue;
}
diff --git a/builtin-revert.c b/builtin-revert.c
index 4ba0ee6..2db624a 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -61,7 +61,7 @@ static void parse_options(int argc, const char **argv)
}
arg = argv[argc - 1];
- if (get_sha1(arg, sha1))
+ if (get_sha1(arg, sha1, NULL))
die ("Cannot find '%s'", arg);
commit = (struct commit *)parse_object(sha1);
if (!commit)
@@ -257,7 +257,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
} else {
struct wt_status s;
- if (get_sha1("HEAD", head))
+ if (get_sha1("HEAD", head, NULL))
die ("You do not have a valid HEAD");
wt_status_prepare(&s);
if (s.commitable || s.workdir_dirty)
diff --git a/builtin-rm.c b/builtin-rm.c
index 4a0bd93..6fc44af 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -190,7 +190,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
*/
if (!force) {
unsigned char sha1[20];
- if (get_sha1("HEAD", sha1))
+ if (get_sha1("HEAD", sha1, NULL))
hashclr(sha1);
if (check_local_mod(sha1))
exit(1);
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index c892f1f..9c515db 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -383,7 +383,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
+ if (get_sha1(refname + ofs, tmp, NULL) || hashcmp(tmp, sha1))
ofs = 5;
return append_ref(refname + ofs, sha1, 0);
}
@@ -397,7 +397,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
+ if (get_sha1(refname + ofs, tmp, NULL) || hashcmp(tmp, sha1))
ofs = 5;
return append_ref(refname + ofs, sha1, 0);
}
@@ -511,7 +511,7 @@ static int show_independent(struct commit **rev,
static void append_one_rev(const char *av)
{
unsigned char revkey[20];
- if (!get_sha1(av, revkey)) {
+ if (!get_sha1(av, revkey, NULL)) {
append_ref(av, revkey, 0);
return;
}
@@ -794,7 +794,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
if (MAX_REVS <= num_rev)
die("cannot handle more than %d revs.", MAX_REVS);
- if (get_sha1(ref_name[num_rev], revkey))
+ if (get_sha1(ref_name[num_rev], revkey, NULL))
die("'%s' is not a valid ref.", ref_name[num_rev]);
commit = lookup_commit_reference(revkey);
if (!commit)
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 5ee960b..3c56e1b 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -46,7 +46,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
if (!refname || !value)
usage(git_update_ref_usage);
- if (get_sha1(value, sha1))
+ if (get_sha1(value, sha1, NULL))
die("%s: not a valid SHA1", value);
if (delete) {
@@ -56,7 +56,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
}
hashclr(oldsha1);
- if (oldval && *oldval && get_sha1(oldval, oldsha1))
+ if (oldval && *oldval && get_sha1(oldval, oldsha1, NULL))
die("%s: not a valid old SHA1", oldval);
lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
diff --git a/cache.h b/cache.h
index 53c2341..dc8d7b1 100644
--- a/cache.h
+++ b/cache.h
@@ -24,6 +24,9 @@
#define DTYPE(de) DT_UNKNOWN
#endif
+/* unknown mode */
+#define S_IFINVALID 0320000
+
/*
* Intensive research over the course of many years has shown that
* port 9418 is totally unused by anything else. Or
@@ -316,7 +319,7 @@ static inline unsigned int hexval(unsigned int c)
#define MINIMUM_ABBREV 4
#define DEFAULT_ABBREV 7
-extern int get_sha1(const char *str, unsigned char *sha1);
+extern int get_sha1(const char *str, unsigned char *sha1, unsigned *mode);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern int read_ref(const char *filename, unsigned char *sha1);
diff --git a/connect.c b/connect.c
index da89c9c..71ebe3c 100644
--- a/connect.c
+++ b/connect.c
@@ -243,7 +243,7 @@ static struct ref *try_explicit_object_name(const char *name)
hashclr(ref->new_sha1);
return ref;
}
- if (get_sha1(name, sha1))
+ if (get_sha1(name, sha1, NULL))
return NULL;
len = strlen(name) + 1;
ref = xcalloc(1, sizeof(*ref) + len);
diff --git a/convert-objects.c b/convert-objects.c
index cefbceb..d3fa9bf 100644
--- a/convert-objects.c
+++ b/convert-objects.c
@@ -320,7 +320,7 @@ int main(int argc, char **argv)
if (argc != 2)
usage("git-convert-objects <sha1>");
- if (get_sha1(argv[1], sha1))
+ if (get_sha1(argv[1], sha1, NULL))
die("Not a valid object name %s", argv[1]);
entry = convert_entry(sha1);
diff --git a/fast-import.c b/fast-import.c
index cdd629d..a671f77 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1721,7 +1721,7 @@ static void cmd_from(struct branch *b)
free(buf);
hashcpy(b->branch_tree.versions[0].sha1,
b->branch_tree.versions[1].sha1);
- } else if (!get_sha1(from, b->sha1)) {
+ } else if (!get_sha1(from, b->sha1, NULL)) {
if (is_null_sha1(b->sha1)) {
hashclr(b->branch_tree.versions[0].sha1);
hashclr(b->branch_tree.versions[1].sha1);
@@ -1765,7 +1765,7 @@ static struct hash_list *cmd_merge(unsigned int *count)
if (oe->type != OBJ_COMMIT)
die("Mark :%" PRIuMAX " not a commit", idnum);
hashcpy(n->sha1, oe->sha1);
- } else if (!get_sha1(from, n->sha1)) {
+ } else if (!get_sha1(from, n->sha1, NULL)) {
unsigned long size;
char *buf = read_object_with_reference(n->sha1,
commit_type, &size, n->sha1);
@@ -1916,7 +1916,7 @@ static void cmd_new_tag(void)
if (oe->type != OBJ_COMMIT)
die("Mark :%" PRIuMAX " not a commit", from_mark);
hashcpy(sha1, oe->sha1);
- } else if (!get_sha1(from, sha1)) {
+ } else if (!get_sha1(from, sha1, NULL)) {
unsigned long size;
char *buf;
@@ -2011,7 +2011,7 @@ static void import_marks(const char *input_file)
*end = 0;
mark = strtoumax(line + 1, &end, 10);
if (!mark || end == line + 1
- || *end != ' ' || get_sha1(end + 1, sha1))
+ || *end != ' ' || get_sha1(end + 1, sha1, NULL))
die("corrupt mark line: %s", line);
e = find_object(sha1);
if (!e) {
diff --git a/merge-recursive.c b/merge-recursive.c
index cea6c87..8e6daca 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1364,7 +1364,7 @@ static struct commit *get_ref(const char *ref)
unsigned char sha1[20];
struct object *object;
- if (get_sha1(ref, sha1))
+ if (get_sha1(ref, sha1, NULL))
die("Could not resolve ref '%s'", ref);
object = deref_tag(parse_object(sha1), ref, strlen(ref));
if (object->type == OBJ_TREE)
diff --git a/merge-tree.c b/merge-tree.c
index 3b8d9e6..1831082 100644
--- a/merge-tree.c
+++ b/merge-tree.c
@@ -325,7 +325,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
unsigned char sha1[20];
void *buf;
- if (get_sha1(rev, sha1))
+ if (get_sha1(rev, sha1, NULL))
die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1);
if (!buf)
diff --git a/revision.c b/revision.c
index ce70f48..8f0ed77 100644
--- a/revision.c
+++ b/revision.c
@@ -614,7 +614,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
flags ^= UNINTERESTING;
arg++;
}
- if (get_sha1(arg, sha1))
+ if (get_sha1(arg, sha1, NULL))
return 0;
while (1) {
it = get_reference(revs, arg, sha1, 0);
@@ -684,9 +684,9 @@ static void prepare_show_merge(struct rev_info *revs)
const char **prune = NULL;
int i, prune_num = 1; /* counting terminating NULL */
- if (get_sha1("HEAD", sha1) || !(head = lookup_commit(sha1)))
+ if (get_sha1("HEAD", sha1, NULL) || !(head = lookup_commit(sha1)))
die("--merge without HEAD?");
- if (get_sha1("MERGE_HEAD", sha1) || !(other = lookup_commit(sha1)))
+ if (get_sha1("MERGE_HEAD", sha1, NULL) || !(other = lookup_commit(sha1)))
die("--merge without MERGE_HEAD?");
add_pending_object(revs, &head->object, "HEAD");
add_pending_object(revs, &other->object, "MERGE_HEAD");
@@ -743,8 +743,8 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
next = "HEAD";
if (dotdot == arg)
this = "HEAD";
- if (!get_sha1(this, from_sha1) &&
- !get_sha1(next, sha1)) {
+ if (!get_sha1(this, from_sha1, NULL) &&
+ !get_sha1(next, sha1, NULL)) {
struct commit *a, *b;
struct commit_list *exclude;
@@ -796,7 +796,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
local_flags = UNINTERESTING;
arg++;
}
- if (get_sha1(arg, sha1))
+ if (get_sha1(arg, sha1, NULL))
return -1;
if (!cant_be_filename)
verify_non_filename(revs->prefix, arg);
@@ -1177,7 +1177,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
if (def && !revs->pending.nr) {
unsigned char sha1[20];
struct object *object;
- if (get_sha1(def, sha1))
+ if (get_sha1(def, sha1, NULL))
die("bad default revision '%s'", def);
object = get_reference(revs, def, sha1, 0);
add_pending_object(revs, object, def);
diff --git a/sha1_name.c b/sha1_name.c
index 267ea3f..57de683 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -641,13 +641,15 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
* This is like "get_sha1_basic()", except it allows "sha1 expressions",
* notably "xyz^" for "parent of xyz"
*/
-int get_sha1(const char *name, unsigned char *sha1)
+int get_sha1(const char *name, unsigned char *sha1, unsigned *mode)
{
int ret, bracket_depth;
unsigned unused;
int namelen = strlen(name);
const char *cp;
+ if (mode)
+ *mode = S_IFINVALID;
prepare_alt_odb();
ret = get_sha1_1(name, namelen, sha1);
if (!ret)
@@ -685,6 +687,8 @@ int get_sha1(const char *name, unsigned char *sha1)
break;
if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->sha1);
+ if (mode)
+ *mode = ce->ce_mode;
return 0;
}
pos++;
@@ -703,7 +707,7 @@ int get_sha1(const char *name, unsigned char *sha1)
unsigned char tree_sha1[20];
if (!get_sha1_1(name, cp-name, tree_sha1))
return get_tree_entry(tree_sha1, cp+1, sha1,
- &unused);
+ mode ? mode : &unused);
}
return ret;
}
diff --git a/ssh-upload.c b/ssh-upload.c
index 2f04572..065cf5d 100644
--- a/ssh-upload.c
+++ b/ssh-upload.c
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
usage(ssh_push_usage);
commit_id = argv[arg];
url = argv[arg + 1];
- if (get_sha1(commit_id, sha1))
+ if (get_sha1(commit_id, sha1, NULL))
die("Not a valid object name %s", commit_id);
memcpy(hex, sha1_to_hex(sha1), sizeof(hex));
argv[arg] = hex;
diff --git a/unpack-file.c b/unpack-file.c
index 25c56b3..f6aaca0 100644
--- a/unpack-file.c
+++ b/unpack-file.c
@@ -29,7 +29,7 @@ int main(int argc, char **argv)
if (argc != 2)
usage("git-unpack-file <sha1>");
- if (get_sha1(argv[1], sha1))
+ if (get_sha1(argv[1], sha1, NULL))
die("Not a valid object name %s", argv[1]);
setup_git_directory();
diff --git a/upload-pack.c b/upload-pack.c
index d3a09e7..9c39231 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -517,7 +517,7 @@ static void receive_needs(void)
unsigned char sha1[20];
struct object *object;
use_thin_pack = 0;
- if (get_sha1(line + 8, sha1))
+ if (get_sha1(line + 8, sha1, NULL))
die("invalid shallow line: %s", line);
object = parse_object(sha1);
if (!object)
diff --git a/wt-status.c b/wt-status.c
index a055990..a40c5d1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -302,7 +302,7 @@ static void wt_status_print_verbose(struct wt_status *s)
void wt_status_print(struct wt_status *s)
{
unsigned char sha1[20];
- s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
+ s->is_initial = get_sha1(s->reference, sha1, NULL) ? 1 : 0;
if (s->branch) {
const char *on_what = "On branch ";
--
1.4.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] add support for storing the mode in object_array
2007-04-21 12:26 [PATCH 1/4] add mode parameter to get_sha1 Martin Koegler
@ 2007-04-21 12:26 ` Martin Koegler
2007-04-21 12:26 ` [PATCH 3/4] add mode to add_pending_object Martin Koegler
2007-04-21 18:42 ` [PATCH 1/4] add mode parameter to get_sha1 Junio C Hamano
2007-04-21 20:02 ` Alex Riesen
2 siblings, 1 reply; 6+ messages in thread
From: Martin Koegler @ 2007-04-21 12:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jakub Narebski, git, Martin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
builtin-bundle.c | 2 +-
builtin-grep.c | 2 +-
builtin-log.c | 2 +-
builtin-name-rev.c | 2 +-
builtin-reflog.c | 8 ++++----
list-objects.c | 2 +-
object.c | 3 ++-
object.h | 3 ++-
revision.c | 6 +++---
shallow.c | 2 +-
upload-pack.c | 8 ++++----
11 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/builtin-bundle.c b/builtin-bundle.c
index d1635a0..97cce9e 100644
--- a/builtin-bundle.c
+++ b/builtin-bundle.c
@@ -155,7 +155,7 @@ static int verify_bundle(struct bundle_header *header, int verbose)
memset(&refs, 0, sizeof(struct object_array));
for (i = 0; i < revs.pending.nr; i++) {
struct object_array_entry *e = revs.pending.objects + i;
- add_object_array(e->item, e->name, &refs);
+ add_object_array(e->item, e->name, S_IFINVALID, &refs);
}
prepare_revision_walk(&revs);
diff --git a/builtin-grep.c b/builtin-grep.c
index f2ee20f..3690f7e 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -677,7 +677,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct object *object = parse_object(sha1);
if (!object)
die("bad object %s", arg);
- add_object_array(object, arg, &list);
+ add_object_array(object, arg, S_IFINVALID, &list);
continue;
}
if (!strcmp(arg, "--")) {
diff --git a/builtin-log.c b/builtin-log.c
index 1ca3aa9..ca12791 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -202,7 +202,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
case OBJ_COMMIT:
rev.pending.nr = rev.pending.alloc = 0;
rev.pending.objects = NULL;
- add_object_array(o, name, &rev.pending);
+ add_object_array(o, name, S_IFINVALID, &rev.pending);
ret = cmd_log_walk(&rev);
break;
default:
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 0351185..748cc0c 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -202,7 +202,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
if (cutoff > commit->date)
cutoff = commit->date;
- add_object_array((struct object *)commit, *argv, &revs);
+ add_object_array((struct object *)commit, *argv, S_IFINVALID, &revs);
}
for_each_ref(name_ref, &data);
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 4c39f1d..a346e8e 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -101,8 +101,8 @@ static int commit_is_complete(struct commit *commit)
*/
memset(&study, 0, sizeof(study));
memset(&found, 0, sizeof(found));
- add_object_array(&commit->object, NULL, &study);
- add_object_array(&commit->object, NULL, &found);
+ add_object_array(&commit->object, NULL, S_IFINVALID, &study);
+ add_object_array(&commit->object, NULL, S_IFINVALID, &found);
commit->object.flags |= STUDYING;
while (study.nr) {
struct commit *c;
@@ -123,8 +123,8 @@ static int commit_is_complete(struct commit *commit)
if (p->object.flags & STUDYING)
continue;
p->object.flags |= STUDYING;
- add_object_array(&p->object, NULL, &study);
- add_object_array(&p->object, NULL, &found);
+ add_object_array(&p->object, NULL, S_IFINVALID, &study);
+ add_object_array(&p->object, NULL, S_IFINVALID, &found);
}
}
if (!is_incomplete) {
diff --git a/list-objects.c b/list-objects.c
index 2ba2c95..1f862bc 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -118,7 +118,7 @@ void traverse_commit_list(struct rev_info *revs,
continue;
if (obj->type == OBJ_TAG) {
obj->flags |= SEEN;
- add_object_array(obj, name, &objects);
+ add_object_array(obj, name, S_IFINVALID, &objects);
continue;
}
if (obj->type == OBJ_TREE) {
diff --git a/object.c b/object.c
index 78a44a6..11c614e 100644
--- a/object.c
+++ b/object.c
@@ -238,7 +238,7 @@ int object_list_contains(struct object_list *list, struct object *obj)
return 0;
}
-void add_object_array(struct object *obj, const char *name, struct object_array *array)
+void add_object_array(struct object *obj, const char *name, unsigned mode, struct object_array *array)
{
unsigned nr = array->nr;
unsigned alloc = array->alloc;
@@ -252,5 +252,6 @@ void add_object_array(struct object *obj, const char *name, struct object_array
}
objects[nr].item = obj;
objects[nr].name = name;
+ objects[nr].mode = mode;
array->nr = ++nr;
}
diff --git a/object.h b/object.h
index bdbbc18..b29268a 100644
--- a/object.h
+++ b/object.h
@@ -17,6 +17,7 @@ struct object_array {
struct object_array_entry {
struct object *item;
const char *name;
+ unsigned mode;
} *objects;
};
@@ -76,6 +77,6 @@ unsigned object_list_length(struct object_list *list);
int object_list_contains(struct object_list *list, struct object *obj);
/* Object array handling .. */
-void add_object_array(struct object *obj, const char *name, struct object_array *array);
+void add_object_array(struct object *obj, const char *name, unsigned mode, struct object_array *array);
#endif /* OBJECT_H */
diff --git a/revision.c b/revision.c
index 8f0ed77..b2df974 100644
--- a/revision.c
+++ b/revision.c
@@ -39,7 +39,7 @@ void add_object(struct object *obj,
struct name_path *path,
const char *name)
{
- add_object_array(obj, path_name(path, name), p);
+ add_object_array(obj, path_name(path, name), S_IFINVALID, p);
}
static void mark_blob_uninteresting(struct blob *blob)
@@ -118,7 +118,7 @@ void add_pending_object(struct rev_info *revs, struct object *obj, const char *n
{
if (revs->no_walk && (obj->flags & UNINTERESTING))
die("object ranges do not make sense when not walking revisions");
- add_object_array(obj, name, &revs->pending);
+ add_object_array(obj, name, S_IFINVALID, &revs->pending);
if (revs->reflog_info && obj->type == OBJ_COMMIT)
add_reflog_for_walk(revs->reflog_info,
(struct commit *)obj, name);
@@ -1461,7 +1461,7 @@ struct commit *get_revision(struct rev_info *revs)
continue;
p->flags |= CHILD_SHOWN;
gc_boundary(&revs->boundary_commits);
- add_object_array(p, NULL, &revs->boundary_commits);
+ add_object_array(p, NULL, S_IFINVALID, &revs->boundary_commits);
}
return c;
diff --git a/shallow.c b/shallow.c
index d178689..d320a13 100644
--- a/shallow.c
+++ b/shallow.c
@@ -87,7 +87,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
if (cur_depth < depth) {
if (p->next)
add_object_array(&p->item->object,
- NULL, &stack);
+ NULL, S_IFINVALID, &stack);
else {
commit = p->item;
cur_depth = *(int *)commit->util;
diff --git a/upload-pack.c b/upload-pack.c
index 9c39231..1f12d29 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -378,7 +378,7 @@ static int got_sha1(char *hex, unsigned char *sha1)
parents->item->object.flags |= THEY_HAVE;
}
if (!we_knew_they_have) {
- add_object_array(o, NULL, &have_obj);
+ add_object_array(o, NULL, S_IFINVALID, &have_obj);
return 1;
}
return 0;
@@ -523,7 +523,7 @@ static void receive_needs(void)
if (!object)
die("did not find object for %s", line);
object->flags |= CLIENT_SHALLOW;
- add_object_array(object, NULL, &shallows);
+ add_object_array(object, NULL, S_IFINVALID, &shallows);
continue;
}
if (!prefixcmp(line, "deepen ")) {
@@ -564,7 +564,7 @@ static void receive_needs(void)
die("git-upload-pack: not our ref %s", line+5);
if (!(o->flags & WANTED)) {
o->flags |= WANTED;
- add_object_array(o, NULL, &want_obj);
+ add_object_array(o, NULL, S_IFINVALID, &want_obj);
}
}
if (depth == 0 && shallows.nr == 0)
@@ -598,7 +598,7 @@ static void receive_needs(void)
parents = ((struct commit *)object)->parents;
while (parents) {
add_object_array(&parents->item->object,
- NULL, &want_obj);
+ NULL, S_IFINVALID, &want_obj);
parents = parents->next;
}
}
--
1.4.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] add mode to add_pending_object
2007-04-21 12:26 ` [PATCH 2/4] add support for storing the mode in object_array Martin Koegler
@ 2007-04-21 12:26 ` Martin Koegler
2007-04-21 12:26 ` [PATCH 4/4] use the mode information of the tree, if <SHA1>:file name syntax is used Martin Koegler
0 siblings, 1 reply; 6+ messages in thread
From: Martin Koegler @ 2007-04-21 12:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jakub Narebski, git, Martin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
builtin-blame.c | 2 +-
builtin-bundle.c | 4 ++--
builtin-diff.c | 2 +-
builtin-fmt-merge-msg.c | 4 ++--
builtin-log.c | 6 +++---
reachable.c | 8 ++++----
revision.c | 38 ++++++++++++++++++++------------------
revision.h | 2 +-
upload-pack.c | 4 ++--
9 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index 7777748..5491dd2 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -2274,7 +2274,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
* or "--contents".
*/
sb.final = fake_working_tree_commit(path, contents_from);
- add_pending_object(&revs, &(sb.final->object), ":");
+ add_pending_object(&revs, &(sb.final->object), ":", S_IFINVALID);
}
else if (contents_from)
die("Cannot use --contents with final commit object name");
diff --git a/builtin-bundle.c b/builtin-bundle.c
index 97cce9e..80a1a3f 100644
--- a/builtin-bundle.c
+++ b/builtin-bundle.c
@@ -140,7 +140,7 @@ static int verify_bundle(struct bundle_header *header, int verbose)
struct object *o = parse_object(e->sha1);
if (o) {
o->flags |= PREREQ_MARK;
- add_pending_object(&revs, o, e->name);
+ add_pending_object(&revs, o, e->name, S_IFINVALID);
continue;
}
if (++ret == 1)
@@ -238,7 +238,7 @@ static int create_bundle(struct bundle_header *header, const char *path,
if (!get_sha1_hex(buffer + 1, sha1)) {
struct object *object = parse_object(sha1);
object->flags |= UNINTERESTING;
- add_pending_object(&revs, object, buffer);
+ add_pending_object(&revs, object, buffer, S_IFINVALID);
}
} else if (!get_sha1_hex(buffer, sha1)) {
struct object *object = parse_object(sha1);
diff --git a/builtin-diff.c b/builtin-diff.c
index 5f1b50e..a427358 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -178,7 +178,7 @@ void add_head(struct rev_info *revs)
obj = parse_object(sha1);
if (!obj)
return;
- add_pending_object(revs, obj, "HEAD");
+ add_pending_object(revs, obj, "HEAD", S_IFINVALID);
}
int cmd_diff(int argc, const char **argv, const char *prefix)
diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index 89224c2..127263a 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -186,8 +186,8 @@ static void shortlog(const char *name, unsigned char *sha1,
setup_revisions(0, NULL, rev, NULL);
rev->ignore_merges = 1;
- add_pending_object(rev, branch, name);
- add_pending_object(rev, &head->object, "^HEAD");
+ add_pending_object(rev, branch, name, S_IFINVALID);
+ add_pending_object(rev, &head->object, "^HEAD", S_IFINVALID);
head->object.flags |= UNINTERESTING;
prepare_revision_walk(rev);
while ((commit = get_revision(rev)) != NULL) {
diff --git a/builtin-log.c b/builtin-log.c
index ca12791..678ef6b 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -388,8 +388,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
init_revisions(&check_rev, prefix);
o1->flags ^= UNINTERESTING;
o2->flags ^= UNINTERESTING;
- add_pending_object(&check_rev, o1, "o1");
- add_pending_object(&check_rev, o2, "o2");
+ add_pending_object(&check_rev, o1, "o1", S_IFINVALID);
+ add_pending_object(&check_rev, o2, "o2", S_IFINVALID);
prepare_revision_walk(&check_rev);
while ((commit = get_revision(&check_rev)) != NULL) {
@@ -652,7 +652,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
struct commit *commit = lookup_commit_reference(sha1);
if (commit) {
commit->object.flags |= flags;
- add_pending_object(revs, &commit->object, arg);
+ add_pending_object(revs, &commit->object, arg, S_IFINVALID);
return 0;
}
}
diff --git a/reachable.c b/reachable.c
index ff3dd34..4edca75 100644
--- a/reachable.c
+++ b/reachable.c
@@ -112,10 +112,10 @@ static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
object = parse_object(osha1);
if (object)
- add_pending_object(revs, object, "");
+ add_pending_object(revs, object, "", S_IFINVALID);
object = parse_object(nsha1);
if (object)
- add_pending_object(revs, object, "");
+ add_pending_object(revs, object, "", S_IFINVALID);
return 0;
}
@@ -126,7 +126,7 @@ static int add_one_ref(const char *path, const unsigned char *sha1, int flag, vo
if (!object)
die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
- add_pending_object(revs, object, "");
+ add_pending_object(revs, object, "", S_IFINVALID);
return 0;
}
@@ -140,7 +140,7 @@ static int add_one_reflog(const char *path, const unsigned char *sha1, int flag,
static void add_one_tree(const unsigned char *sha1, struct rev_info *revs)
{
struct tree *tree = lookup_tree(sha1);
- add_pending_object(revs, &tree->object, "");
+ add_pending_object(revs, &tree->object, "", S_IFINVALID);
}
static void add_cache_tree(struct cache_tree *it, struct rev_info *revs)
diff --git a/revision.c b/revision.c
index b2df974..4ff2e4e 100644
--- a/revision.c
+++ b/revision.c
@@ -114,11 +114,11 @@ void mark_parents_uninteresting(struct commit *commit)
}
}
-void add_pending_object(struct rev_info *revs, struct object *obj, const char *name)
+void add_pending_object(struct rev_info *revs, struct object *obj, const char *name, unsigned mode)
{
if (revs->no_walk && (obj->flags & UNINTERESTING))
die("object ranges do not make sense when not walking revisions");
- add_object_array(obj, name, S_IFINVALID, &revs->pending);
+ add_object_array(obj, name, mode, &revs->pending);
if (revs->reflog_info && obj->type == OBJ_COMMIT)
add_reflog_for_walk(revs->reflog_info,
(struct commit *)obj, name);
@@ -145,7 +145,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object;
if (revs->tag_objects && !(flags & UNINTERESTING))
- add_pending_object(revs, object, tag->tag);
+ add_pending_object(revs, object, tag->tag, S_IFINVALID);
object = parse_object(tag->tagged->sha1);
if (!object)
die("bad object %s", sha1_to_hex(tag->tagged->sha1));
@@ -179,7 +179,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
mark_tree_uninteresting(tree);
return NULL;
}
- add_pending_object(revs, object, "");
+ add_pending_object(revs, object, "", S_IFINVALID);
return NULL;
}
@@ -194,7 +194,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
mark_blob_uninteresting(blob);
return NULL;
}
- add_pending_object(revs, object, "");
+ add_pending_object(revs, object, "", S_IFINVALID);
return NULL;
}
die("%s is unknown object", name);
@@ -548,7 +548,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flag,
struct all_refs_cb *cb = cb_data;
struct object *object = get_reference(cb->all_revs, path, sha1,
cb->all_flags);
- add_pending_object(cb->all_revs, object, path);
+ add_pending_object(cb->all_revs, object, path, S_IFINVALID);
return 0;
}
@@ -567,7 +567,7 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
struct object *o = parse_object(sha1);
if (o) {
o->flags |= cb->all_flags;
- add_pending_object(cb->all_revs, o, "");
+ add_pending_object(cb->all_revs, o, "", S_IFINVALID);
}
else if (!cb->warned_bad_reflog) {
warning("reflog of '%s' references pruned commits",
@@ -628,7 +628,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
for (parents = commit->parents; parents; parents = parents->next) {
it = &parents->item->object;
it->flags |= flags;
- add_pending_object(revs, it, arg);
+ add_pending_object(revs, it, arg, S_IFINVALID);
}
return 1;
}
@@ -671,7 +671,7 @@ static void add_pending_commit_list(struct rev_info *revs,
while (commit_list) {
struct object *object = &commit_list->item->object;
object->flags |= flags;
- add_pending_object(revs, object, sha1_to_hex(object->sha1));
+ add_pending_object(revs, object, sha1_to_hex(object->sha1), S_IFINVALID);
commit_list = commit_list->next;
}
}
@@ -688,8 +688,8 @@ static void prepare_show_merge(struct rev_info *revs)
die("--merge without HEAD?");
if (get_sha1("MERGE_HEAD", sha1, NULL) || !(other = lookup_commit(sha1)))
die("--merge without MERGE_HEAD?");
- add_pending_object(revs, &head->object, "HEAD");
- add_pending_object(revs, &other->object, "MERGE_HEAD");
+ add_pending_object(revs, &head->object, "HEAD", S_IFINVALID);
+ add_pending_object(revs, &other->object, "MERGE_HEAD", S_IFINVALID);
bases = get_merge_bases(head, other, 1);
while (bases) {
struct commit *it = bases->item;
@@ -697,7 +697,7 @@ static void prepare_show_merge(struct rev_info *revs)
free(bases);
bases = n;
it->object.flags |= UNINTERESTING;
- add_pending_object(revs, &it->object, "(merge-base)");
+ add_pending_object(revs, &it->object, "(merge-base)", S_IFINVALID);
}
if (!active_nr)
@@ -727,6 +727,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
struct object *object;
unsigned char sha1[20];
int local_flags;
+ unsigned mode;
dotdot = strstr(arg, "..");
if (dotdot) {
@@ -771,8 +772,8 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
} else
a->object.flags |= flags_exclude;
b->object.flags |= flags;
- add_pending_object(revs, &a->object, this);
- add_pending_object(revs, &b->object, next);
+ add_pending_object(revs, &a->object, this, S_IFINVALID);
+ add_pending_object(revs, &b->object, next, S_IFINVALID);
return 0;
}
*dotdot = '.';
@@ -796,12 +797,12 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
local_flags = UNINTERESTING;
arg++;
}
- if (get_sha1(arg, sha1, NULL))
+ if (get_sha1(arg, sha1, &mode))
return -1;
if (!cant_be_filename)
verify_non_filename(revs->prefix, arg);
object = get_reference(revs, arg, sha1, flags ^ local_flags);
- add_pending_object(revs, object, arg);
+ add_pending_object(revs, object, arg, mode);
return 0;
}
@@ -1177,10 +1178,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
if (def && !revs->pending.nr) {
unsigned char sha1[20];
struct object *object;
- if (get_sha1(def, sha1, NULL))
+ unsigned mode;
+ if (get_sha1(def, sha1, &mode))
die("bad default revision '%s'", def);
object = get_reference(revs, def, sha1, 0);
- add_pending_object(revs, object, def);
+ add_pending_object(revs, object, def, mode);
}
if (revs->topo_order)
diff --git a/revision.h b/revision.h
index 8a02618..c58ec75 100644
--- a/revision.h
+++ b/revision.h
@@ -130,6 +130,6 @@ extern void add_object(struct object *obj,
struct name_path *path,
const char *name);
-extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
+extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name, unsigned mode);
#endif
diff --git a/upload-pack.c b/upload-pack.c
index 1f12d29..aefca5f 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -139,12 +139,12 @@ static void create_pack_file(void)
struct object *o = want_obj.objects[i].item;
/* why??? */
o->flags &= ~UNINTERESTING;
- add_pending_object(&revs, o, NULL);
+ add_pending_object(&revs, o, NULL, S_IFINVALID);
}
for (i = 0; i < have_obj.nr; i++) {
struct object *o = have_obj.objects[i].item;
o->flags |= UNINTERESTING;
- add_pending_object(&revs, o, NULL);
+ add_pending_object(&revs, o, NULL, S_IFINVALID);
}
setup_revisions(0, NULL, &revs, NULL);
}
--
1.4.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] use the mode information of the tree, if <SHA1>:file name syntax is used
2007-04-21 12:26 ` [PATCH 3/4] add mode to add_pending_object Martin Koegler
@ 2007-04-21 12:26 ` Martin Koegler
0 siblings, 0 replies; 6+ messages in thread
From: Martin Koegler @ 2007-04-21 12:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jakub Narebski, git, Martin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
builtin-diff.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/builtin-diff.c b/builtin-diff.c
index a427358..f1886ec 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -20,6 +20,7 @@
struct blobinfo {
unsigned char sha1[20];
const char *name;
+ unsigned mode;
};
static const char builtin_diff_usage[] =
@@ -88,8 +89,14 @@ static int builtin_diff_blobs(struct rev_info *revs,
if (argc > 1)
usage(builtin_diff_usage);
+ if (blob[0].mode == S_IFINVALID)
+ blob[0].mode = mode;
+
+ if (blob[1].mode == S_IFINVALID)
+ blob[1].mode = mode;
+
stuff_change(&revs->diffopt,
- mode, mode,
+ blob[0].mode, blob[1].mode,
blob[0].sha1, blob[1].sha1,
blob[0].name, blob[1].name);
diffcore_std(&revs->diffopt);
@@ -271,6 +278,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
die("more than two blobs given: '%s'", name);
hashcpy(blob[blobs].sha1, obj->sha1);
blob[blobs].name = name;
+ blob[blobs].mode = list->mode;
blobs++;
continue;
--
1.4.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] add mode parameter to get_sha1
2007-04-21 12:26 [PATCH 1/4] add mode parameter to get_sha1 Martin Koegler
2007-04-21 12:26 ` [PATCH 2/4] add support for storing the mode in object_array Martin Koegler
@ 2007-04-21 18:42 ` Junio C Hamano
2007-04-21 20:02 ` Alex Riesen
2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2007-04-21 18:42 UTC (permalink / raw)
To: Martin Koegler; +Cc: Jakub Narebski, git
Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
> If the mode parameter is not NULL, get_sha1 will store
> the mode of the object in it.
Most existing callers pass NULL to this. Wouldn't it be cleaner
to have a new get_sha1_with_mode() function, and convert the
callers that care about mode to use it, like this?
int get_sha1(const char *str, unsigned char sha1[20]) {
unsigned discard;
return get_sha1_with_mode(str, sha1, &discard);
}
That way, your patch would be much easier to review and would
have less chance of getting it wrong. I wonder if [2/4] can be
made less impact using a similar trick. Most of the existing
callers that place objects in object_array do not know the mode.
Only some do.
+/* unknown mode */
+#define S_IFINVALID 0320000
+
This hunk does not belong to [1/4]; it is part of [2/4].
Typically S_IF$TYPE macros are masked with S_IFMT (0170000)
before being used, so the above value is *obviously* invalid,
but it also risks our code would treat it as a symlink, we do
the masking before comparison. I wonder if defining it to
S_IFMT mask itself might be a safer option.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] add mode parameter to get_sha1
2007-04-21 12:26 [PATCH 1/4] add mode parameter to get_sha1 Martin Koegler
2007-04-21 12:26 ` [PATCH 2/4] add support for storing the mode in object_array Martin Koegler
2007-04-21 18:42 ` [PATCH 1/4] add mode parameter to get_sha1 Junio C Hamano
@ 2007-04-21 20:02 ` Alex Riesen
2 siblings, 0 replies; 6+ messages in thread
From: Alex Riesen @ 2007-04-21 20:02 UTC (permalink / raw)
To: Martin Koegler; +Cc: Junio C Hamano, Jakub Narebski, git
Martin Koegler, Sat, Apr 21, 2007 14:26:17 +0200:
> If the mode parameter is not NULL, get_sha1 will store
> the mode of the object in it.
It looks like the number of call sites which actually use the
argument is vanishingly small compared to the number of sites
where it is set to NULL. Why don't you introduce a new function
instead, say get_sha1_and_mode, and use it for this two or three
places?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-04-21 20:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-21 12:26 [PATCH 1/4] add mode parameter to get_sha1 Martin Koegler
2007-04-21 12:26 ` [PATCH 2/4] add support for storing the mode in object_array Martin Koegler
2007-04-21 12:26 ` [PATCH 3/4] add mode to add_pending_object Martin Koegler
2007-04-21 12:26 ` [PATCH 4/4] use the mode information of the tree, if <SHA1>:file name syntax is used Martin Koegler
2007-04-21 18:42 ` [PATCH 1/4] add mode parameter to get_sha1 Junio C Hamano
2007-04-21 20:02 ` Alex Riesen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).