summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-08-21 14:32:09 -0700
committerVicent Martí <vicent@github.com>2012-08-21 14:32:09 -0700
commit697665c0c13e45a5d24af85c133ffaa0a0e0f8cc (patch)
tree9e32cfadd2e1ffaa05f72dd5871551180ee0afb9 /src
parentb2be351aaddc6ba0b3a0f2cf4e09536a3b27e598 (diff)
parent9d7ac675d06dab2e000ad32f9248631af0191f85 (diff)
downloadlibgit2-697665c0c13e45a5d24af85c133ffaa0a0e0f8cc.tar.gz
Merge pull request #889 from nulltoken/filemode-enum
Filemode enum
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c4
-rw-r--r--src/notes.c12
-rw-r--r--src/tree.c46
-rw-r--r--src/tree.h4
4 files changed, 38 insertions, 28 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 252d9c4ae..ac540391e 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -88,7 +88,7 @@ static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
/* Allow overriding of file mode */
if (!file_mode)
- file_mode = git_tree_entry_attributes(entry);
+ file_mode = git_tree_entry_filemode(entry);
if ((retcode = git_futils_mkpath2file(git_buf_cstr(fnbuf), data->opts->dir_mode)) < 0)
goto bctf_cleanup;
@@ -111,7 +111,7 @@ static int checkout_walker(const char *path, const git_tree_entry *entry, void *
{
int retcode = 0;
tree_walk_data *data = (tree_walk_data*)payload;
- int attr = git_tree_entry_attributes(entry);
+ int attr = git_tree_entry_filemode(entry);
git_buf fnbuf = GIT_BUF_INIT;
git_buf_join_n(&fnbuf, '/', 3,
git_repository_workdir(data->repo),
diff --git a/src/notes.c b/src/notes.c
index 6f9e7779d..81e4e5073 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -33,7 +33,7 @@ static int find_subtree_in_current_level(
if (!git__ishex(git_tree_entry_name(entry)))
continue;
- if (S_ISDIR(git_tree_entry_attributes(entry))
+ if (S_ISDIR(git_tree_entry_filemode(entry))
&& strlen(git_tree_entry_name(entry)) == 2
&& !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2))
return git_tree_lookup(out, repo, git_tree_entry_id(entry));
@@ -180,7 +180,7 @@ static int manipulate_note_in_tree_r(
subtree_name[2] = '\0';
error = tree_write(out, repo, parent, git_tree_id(new),
- subtree_name, 0040000);
+ subtree_name, GIT_FILEMODE_TREE);
cleanup:
@@ -252,7 +252,13 @@ static int insert_note_in_tree_enotfound_cb(git_tree **out,
GIT_UNUSED(current_error);
/* No existing fanout at this level, insert in place */
- return tree_write(out, repo, parent, note_oid, annotated_object_sha + fanout, 0100644);
+ return tree_write(
+ out,
+ repo,
+ parent,
+ note_oid,
+ annotated_object_sha + fanout,
+ GIT_FILEMODE_BLOB);
}
static int note_write(git_oid *out,
diff --git a/src/tree.c b/src/tree.c
index 0eee94735..83aa303d4 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -14,14 +14,14 @@
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6
-static bool valid_attributes(const int attributes)
+static bool valid_filemode(const int filemode)
{
- return (attributes == 0040000 /* Directory */
- || attributes == 0100644 /* Non executable file */
- || attributes == 0100664 /* Non executable group writable file */
- || attributes == 0100755 /* Executable file */
- || attributes == 0120000 /* Symbolic link */
- || attributes == 0160000); /* Git link */
+ return (filemode == GIT_FILEMODE_TREE
+ || filemode == GIT_FILEMODE_BLOB
+ || filemode == GIT_FILEMODE_BLOB_GROUP_WRITABLE
+ || filemode == GIT_FILEMODE_BLOB_EXECUTABLE
+ || filemode == GIT_FILEMODE_LINK
+ || filemode == GIT_FILEMODE_COMMIT);
}
static int valid_entry_name(const char *filename)
@@ -185,9 +185,9 @@ const git_oid *git_tree_id(git_tree *c)
return git_object_id((git_object *)c);
}
-unsigned int git_tree_entry_attributes(const git_tree_entry *entry)
+git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
{
- return entry->attr;
+ return (git_filemode_t)entry->attr;
}
const char *git_tree_entry_name(const git_tree_entry *entry)
@@ -308,8 +308,8 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
int attr;
if (git__strtol32(&attr, buffer, &buffer, 8) < 0 ||
- !buffer || !valid_attributes(attr))
- return tree_error("Failed to parse tree. Can't parse attributes");
+ !buffer || !valid_filemode(attr))
+ return tree_error("Failed to parse tree. Can't parse filemode");
if (*buffer++ != ' ')
return tree_error("Failed to parse tree. Object is corrupted");
@@ -368,7 +368,7 @@ static int append_entry(
git_treebuilder *bld,
const char *filename,
const git_oid *id,
- unsigned int attributes)
+ git_filemode_t filemode)
{
git_tree_entry *entry;
@@ -376,7 +376,7 @@ static int append_entry(
GITERR_CHECK_ALLOC(entry);
git_oid_cpy(&entry->oid, id);
- entry->attr = attributes;
+ entry->attr = (uint16_t)filemode;
if (git_vector_insert(&bld->entries, entry) < 0)
return -1;
@@ -517,17 +517,17 @@ static void sort_entries(git_treebuilder *bld)
git_vector_sort(&bld->entries);
}
-GIT_INLINE(int) normalize_attributes(const int attributes)
+GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode)
{
/* 100664 mode is an early design mistake. Tree entries may bear
* this mode in some old git repositories, but it's now deprecated.
* We silently normalize while inserting new entries in a tree
* being built.
*/
- if (attributes == 0100664)
- return 0100644;
+ if (filemode == GIT_FILEMODE_BLOB_GROUP_WRITABLE)
+ return GIT_FILEMODE_BLOB;
- return attributes;
+ return filemode;
}
int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source)
@@ -553,7 +553,7 @@ int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source)
if (append_entry(
bld, entry_src->filename,
&entry_src->oid,
- normalize_attributes(entry_src->attr)) < 0)
+ normalize_filemode((git_filemode_t)entry_src->attr)) < 0)
goto on_error;
}
}
@@ -571,17 +571,17 @@ int git_treebuilder_insert(
git_treebuilder *bld,
const char *filename,
const git_oid *id,
- unsigned int attributes)
+ git_filemode_t filemode)
{
git_tree_entry *entry;
int pos;
assert(bld && id && filename);
- if (!valid_attributes(attributes))
- return tree_error("Failed to insert entry. Invalid attributes");
+ if (!valid_filemode(filemode))
+ return tree_error("Failed to insert entry. Invalid filemode");
- attributes = normalize_attributes(attributes);
+ filemode = normalize_filemode(filemode);
if (!valid_entry_name(filename))
return tree_error("Failed to insert entry. Invalid name for a tree entry");
@@ -598,7 +598,7 @@ int git_treebuilder_insert(
}
git_oid_cpy(&entry->oid, id);
- entry->attr = attributes;
+ entry->attr = filemode;
if (pos < 0) {
if (git_vector_insert(&bld->entries, entry) < 0)
diff --git a/src/tree.h b/src/tree.h
index c49309cbc..24b517ce3 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -47,5 +47,9 @@ int git_tree__parse(git_tree *tree, git_odb_object *obj);
*/
int git_tree__prefix_position(git_tree *tree, const char *prefix);
+/**
+ * Obsolete mode kept for compatibility reasons
+ */
+#define GIT_FILEMODE_BLOB_GROUP_WRITABLE 0100664
#endif