зеркало из https://github.com/microsoft/git.git
Make git-write-tree a builtin
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Родитель
64e86c5786
Коммит
8ed05fb5e9
6
Makefile
6
Makefile
|
@ -159,7 +159,7 @@ PROGRAMS = \
|
||||||
git-show-index$X git-ssh-fetch$X \
|
git-show-index$X git-ssh-fetch$X \
|
||||||
git-ssh-upload$X git-unpack-file$X \
|
git-ssh-upload$X git-unpack-file$X \
|
||||||
git-unpack-objects$X git-update-index$X git-update-server-info$X \
|
git-unpack-objects$X git-update-index$X git-update-server-info$X \
|
||||||
git-upload-pack$X git-verify-pack$X git-write-tree$X \
|
git-upload-pack$X git-verify-pack$X \
|
||||||
git-update-ref$X git-symbolic-ref$X \
|
git-update-ref$X git-symbolic-ref$X \
|
||||||
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
|
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
|
||||||
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
|
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
|
||||||
|
@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \
|
||||||
git-check-ref-format$X git-rev-parse$X \
|
git-check-ref-format$X git-rev-parse$X \
|
||||||
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
|
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
|
||||||
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
|
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
|
||||||
git-read-tree$X git-commit-tree$X \
|
git-read-tree$X git-commit-tree$X git-write-tree$X \
|
||||||
git-apply$X git-show-branch$X git-diff-files$X \
|
git-apply$X git-show-branch$X git-diff-files$X \
|
||||||
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
|
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ BUILTIN_OBJS = \
|
||||||
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
|
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
|
||||||
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
|
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
|
||||||
builtin-tar-tree.o builtin-upload-tar.o \
|
builtin-tar-tree.o builtin-upload-tar.o \
|
||||||
builtin-ls-files.o builtin-ls-tree.o \
|
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
|
||||||
builtin-read-tree.o builtin-commit-tree.o \
|
builtin-read-tree.o builtin-commit-tree.o \
|
||||||
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
|
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
|
||||||
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
|
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
|
||||||
|
|
|
@ -3,29 +3,72 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) Linus Torvalds, 2005
|
* Copyright (C) Linus Torvalds, 2005
|
||||||
*/
|
*/
|
||||||
|
#include "builtin.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "cache-tree.h"
|
#include "cache-tree.h"
|
||||||
|
|
||||||
static int missing_ok = 0;
|
|
||||||
static char *prefix = NULL;
|
|
||||||
|
|
||||||
static const char write_tree_usage[] =
|
static const char write_tree_usage[] =
|
||||||
"git-write-tree [--missing-ok] [--prefix=<prefix>/]";
|
"git-write-tree [--missing-ok] [--prefix=<prefix>/]";
|
||||||
|
|
||||||
static struct lock_file lock_file;
|
int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
int entries, was_valid, newfd;
|
int entries, was_valid, newfd;
|
||||||
|
|
||||||
|
/* We can't free this memory, it becomes part of a linked list parsed atexit() */
|
||||||
|
struct lock_file *lock_file = xmalloc(sizeof(struct lock_file));
|
||||||
|
|
||||||
|
newfd = hold_lock_file_for_update(lock_file, get_index_file());
|
||||||
|
|
||||||
|
entries = read_cache();
|
||||||
|
if (entries < 0)
|
||||||
|
die("git-write-tree: error reading cache");
|
||||||
|
|
||||||
|
if (!active_cache_tree)
|
||||||
|
active_cache_tree = cache_tree();
|
||||||
|
|
||||||
|
was_valid = cache_tree_fully_valid(active_cache_tree);
|
||||||
|
|
||||||
|
if (!was_valid) {
|
||||||
|
if (cache_tree_update(active_cache_tree,
|
||||||
|
active_cache, active_nr,
|
||||||
|
missing_ok, 0) < 0)
|
||||||
|
die("git-write-tree: error building trees");
|
||||||
|
if (0 <= newfd) {
|
||||||
|
if (!write_cache(newfd, active_cache, active_nr))
|
||||||
|
commit_lock_file(lock_file);
|
||||||
|
}
|
||||||
|
/* Not being able to write is fine -- we are only interested
|
||||||
|
* in updating the cache-tree part, and if the next caller
|
||||||
|
* ends up using the old index with unupdated cache-tree part
|
||||||
|
* it misses the work we did here, but that is just a
|
||||||
|
* performance penalty and not a big deal.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefix) {
|
||||||
|
struct cache_tree *subtree =
|
||||||
|
cache_tree_find(active_cache_tree, prefix);
|
||||||
|
memcpy(sha1, subtree->sha1, 20);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memcpy(sha1, active_cache_tree->sha1, 20);
|
||||||
|
|
||||||
|
rollback_lock_file(lock_file);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_write_tree(int argc, const char **argv, char **envp)
|
||||||
|
{
|
||||||
|
int missing_ok = 0, ret;
|
||||||
|
const char *prefix = NULL;
|
||||||
|
unsigned char sha1[20];
|
||||||
|
|
||||||
setup_git_directory();
|
setup_git_directory();
|
||||||
|
|
||||||
newfd = hold_lock_file_for_update(&lock_file, get_index_file());
|
|
||||||
entries = read_cache();
|
|
||||||
|
|
||||||
while (1 < argc) {
|
while (1 < argc) {
|
||||||
char *arg = argv[1];
|
const char *arg = argv[1];
|
||||||
if (!strcmp(arg, "--missing-ok"))
|
if (!strcmp(arg, "--missing-ok"))
|
||||||
missing_ok = 1;
|
missing_ok = 1;
|
||||||
else if (!strncmp(arg, "--prefix=", 9))
|
else if (!strncmp(arg, "--prefix=", 9))
|
||||||
|
@ -38,35 +81,8 @@ int main(int argc, char **argv)
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
die("too many options");
|
die("too many options");
|
||||||
|
|
||||||
if (entries < 0)
|
ret = write_tree(sha1, missing_ok, prefix);
|
||||||
die("git-write-tree: error reading cache");
|
printf("%s\n", sha1_to_hex(sha1));
|
||||||
|
|
||||||
if (!active_cache_tree)
|
return ret;
|
||||||
active_cache_tree = cache_tree();
|
|
||||||
|
|
||||||
was_valid = cache_tree_fully_valid(active_cache_tree);
|
|
||||||
if (!was_valid) {
|
|
||||||
if (cache_tree_update(active_cache_tree,
|
|
||||||
active_cache, active_nr,
|
|
||||||
missing_ok, 0) < 0)
|
|
||||||
die("git-write-tree: error building trees");
|
|
||||||
if (0 <= newfd) {
|
|
||||||
if (!write_cache(newfd, active_cache, active_nr))
|
|
||||||
commit_lock_file(&lock_file);
|
|
||||||
}
|
|
||||||
/* Not being able to write is fine -- we are only interested
|
|
||||||
* in updating the cache-tree part, and if the next caller
|
|
||||||
* ends up using the old index with unupdated cache-tree part
|
|
||||||
* it misses the work we did here, but that is just a
|
|
||||||
* performance penalty and not a big deal.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
if (prefix) {
|
|
||||||
struct cache_tree *subtree =
|
|
||||||
cache_tree_find(active_cache_tree, prefix);
|
|
||||||
printf("%s\n", sha1_to_hex(subtree->sha1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
|
@ -46,4 +46,7 @@ extern int cmd_diff_tree(int argc, const char **argv, char **envp);
|
||||||
extern int cmd_cat_file(int argc, const char **argv, char **envp);
|
extern int cmd_cat_file(int argc, const char **argv, char **envp);
|
||||||
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
|
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
|
||||||
|
|
||||||
|
extern int cmd_write_tree(int argc, const char **argv, char **envp);
|
||||||
|
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
3
git.c
3
git.c
|
@ -178,7 +178,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||||
{ "diff-stages", cmd_diff_stages },
|
{ "diff-stages", cmd_diff_stages },
|
||||||
{ "diff-tree", cmd_diff_tree },
|
{ "diff-tree", cmd_diff_tree },
|
||||||
{ "cat-file", cmd_cat_file },
|
{ "cat-file", cmd_cat_file },
|
||||||
{ "rev-parse", cmd_rev_parse }
|
{ "rev-parse", cmd_rev_parse },
|
||||||
|
{ "write-tree", cmd_write_tree }
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче