* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Jakub Narebski @ 2006-06-08 18:32 UTC (permalink / raw)
To: git
In-Reply-To: <1149775348.23938.236.camel@cashmere.sps.mot.com>
Jon Loeliger wrote:
> On Thu, 2006-06-08 at 06:30, Johannes Schindelin wrote:
>> - The --no-local flag [...]
>
> Could we have multiple levels, and have names that call out
> where it applies? Perhaps something like:
>
> --repo into $GIT_DIR/.gitconfig <- current default, right?
> --home into ~/.gitconfig
> --site into /etc/gitconfig
> --share into /usr/share/git/config
I like that too, wlthough --home might be named --user, and --share be named
--predefined or --library.
--
Jakub Narebski
Warsaw, Poland
^ permalink raw reply
* [PATCH] check for error return from fork()
From: Paul T Darga @ 2006-06-08 18:14 UTC (permalink / raw)
To: git
Trivial fixup for fork() callsites which do not check for errors.
Signed-off-by: Paul T Darga <pdarga@umich.edu>
---
connect.c | 2 ++
imap-send.c | 6 +++++-
rsh.c | 6 +++++-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/connect.c b/connect.c
index eca94f7..52d709e 100644
--- a/connect.c
+++ b/connect.c
@@ -657,6 +657,8 @@ int git_connect(int fd[2], char *url, co
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
die("unable to create pipe pair for communication");
pid = fork();
+ if (pid < 0)
+ die("unable to fork");
if (!pid) {
snprintf(command, sizeof(command), "%s %s", prog,
sq_quote(path));
diff --git a/imap-send.c b/imap-send.c
index 52e2400..285ad29 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srv
struct hostent *he;
struct sockaddr_in addr;
int s, a[2], preauth;
+ pid_t pid;
ctx = xcalloc( sizeof(*ctx), 1 );
@@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srv
exit( 1 );
}
- if (fork() == 0) {
+ pid = fork();
+ if (pid < 0)
+ _exit( 127 );
+ if (!pid) {
if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)
_exit( 127 );
close( a[0] );
diff --git a/rsh.c b/rsh.c
index d665269..07166ad 100644
--- a/rsh.c
+++ b/rsh.c
@@ -48,6 +48,7 @@ int setup_connection(int *fd_in, int *fd
int sizen;
int of;
int i;
+ pid_t pid;
if (!strcmp(url, "-")) {
*fd_in = 0;
@@ -91,7 +92,10 @@ int setup_connection(int *fd_in, int *fd
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
return error("Couldn't create socket");
- if (!fork()) {
+ pid = fork();
+ if (pid < 0)
+ return error("Couldn't fork");
+ if (!pid) {
const char *ssh, *ssh_basename;
ssh = getenv("GIT_SSH");
if (!ssh) ssh = "ssh";
--
1.4.0.rc2
--
Paul T. Darga - pdarga@umich.edu - http://www.eecs.umich.edu/~pdarga/
"When I gave food to the poor, they called me a saint. When I asked
why the poor were hungry, they called me a communist."
-- Dom Helder Camara, Brazilian Bishop, Nobel Peace Prize nominee
^ permalink raw reply related
* [PATCH] Implement git-branch and git-merge-base as built-ins.
From: Kristian Høgsberg @ 2006-06-08 17:49 UTC (permalink / raw)
To: git
This patch is more or less a straight port of git-branch from shell
script to C. Branch deletion uses git-merge-base to check if it is safe
to delete a branch, so I changed merge-base.c to export this functionality
as a for_each_merge_base() iterator. As a side effect, git-merge-base is
now also a built-in command.
---
6b90d7b7af4bf577ccfeebef1f736e75631b052d
Makefile | 13 +++--
builtin-branch.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
builtin.h | 2 +
commit.h | 5 ++
git-branch.sh | 120 ------------------------------------------
git.c | 4 +
merge-base.c | 34 ++++++++----
7 files changed, 194 insertions(+), 138 deletions(-)
diff --git a/Makefile b/Makefile
index 5373986..a709e40 100644
--- a/Makefile
+++ b/Makefile
@@ -113,7 +113,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powe
### --- END CONFIGURATION SECTION ---
SCRIPT_SH = \
- git-bisect.sh git-branch.sh git-checkout.sh \
+ git-bisect.sh git-checkout.sh \
git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
git-fetch.sh \
git-format-patch.sh git-ls-remote.sh \
@@ -155,7 +155,7 @@ PROGRAMS = \
git-diff-index$X git-diff-stages$X \
git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \
git-hash-object$X git-index-pack$X git-init-db$X git-local-fetch$X \
- git-ls-files$X git-ls-tree$X git-mailinfo$X git-merge-base$X \
+ git-ls-files$X git-ls-tree$X git-mailinfo$X \
git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
git-peek-remote$X git-prune-packed$X git-read-tree$X \
git-receive-pack$X git-rev-parse$X \
@@ -170,7 +170,8 @@ PROGRAMS = \
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
git-count-objects$X git-diff$X git-push$X \
- git-grep$X git-add$X git-rev-list$X git-check-ref-format$X
+ git-grep$X git-add$X git-rev-list$X git-check-ref-format$X \
+ git-branch$X git-merge-base$X
# what 'all' will build and 'install' will install, in gitexecdir
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@ -214,11 +215,13 @@ LIB_OBJS = \
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
+ merge-base.o \
$(DIFF_OBJS)
BUILTIN_OBJS = \
- builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
- builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o
+ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o \
+ builtin-push.o builtin-grep.o builtin-add.o builtin-rev-list.o \
+ builtin-check-ref-format.o builtin-branch.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
diff --git a/builtin-branch.c b/builtin-branch.c
new file mode 100644
index 0000000..c7776a3
--- /dev/null
+++ b/builtin-branch.c
@@ -0,0 +1,154 @@
+/*
+ * Builtin "git branch"
+ *
+ * Copyright (c) 2006 Kristian Høgsberg <krh@redhat.com>
+ * Based on git-branch.sh by Junio C Hamano.
+ */
+
+#include "cache.h"
+#include "refs.h"
+#include "commit.h"
+#include "builtin.h"
+
+static const char builtin_branch_usage[] =
+ "git-branch [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r";
+
+
+static int remote_only = 0;
+static const char *head;
+static unsigned char head_sha1[20];
+
+static int find_sha1(struct commit *commit, void *data)
+{
+ return !memcmp(data, commit->object.sha1, sizeof commit->object.sha1);
+}
+
+static void delete_branches(int argc, const char **argv, int force)
+{
+ struct commit *rev1, *rev2;
+ unsigned char sha1[20];
+ const char *p, *name;
+ int i;
+
+ for (i = 0; i < argc; i++) {
+ if (!strcmp(head, argv[i]))
+ die("Cannot delete the branch you are currently on.");
+
+ name = git_path("refs/heads/%s", argv[i]);
+ p = resolve_ref(name, sha1, 1);
+ if (p == NULL)
+ die("Branch '%s' not found.", argv[i]);
+
+ rev1 = lookup_commit_reference(sha1);
+ rev2 = lookup_commit_reference(head_sha1);
+ if (!rev1 || !rev2)
+ die("Couldn't look up commit objects.");
+
+ /* This checks wether the merge bases of branch and
+ * HEAD contains branch -- which means that the HEAD
+ * contains everything in both.
+ */
+
+ if (!force &&
+ !for_each_merge_base(rev1, rev2, find_sha1, sha1)) {
+ fprintf(stderr,
+ "The branch '%s' is not a strict subset of your current HEAD.\n"
+ "If you are sure you want to delete it, run 'git branch -D %s'.\n",
+ argv[i], argv[i]);
+ exit(1);
+ }
+
+ unlink(name);
+ printf("Deleted branch %s.\n", argv[i]);
+ }
+}
+
+static int show_reference(const char *refname, const unsigned char *sha1)
+{
+ int is_head = !strcmp(refname, head);
+
+ printf("%c %s\n", (is_head ? '*' : ' '), refname);
+
+ return 0;
+}
+
+static void create_branch (const char *name, const char *start, int force)
+{
+ unsigned char sha1[20];
+ char ref[500];
+
+ snprintf (ref, sizeof ref, "heads/%s", name);
+ if (check_ref_format(ref))
+ die("'%s' is not a valid branch name.", name);
+
+ if (resolve_ref(git_path("refs/%s", ref), sha1, 1)) {
+ if (!force)
+ die("A branch named '%s' already exists.", name);
+ else if (!strcmp(head, name))
+ die("Cannot force update the current branch.");
+ }
+
+ if (get_sha1(start, sha1))
+ die("Not a valid branch point: '%s'", start);
+
+ if (write_ref_sha1_unlocked(ref, sha1))
+ die("Failed to create branch: %s.", strerror(errno));
+}
+
+int cmd_branch(int argc, const char **argv, char **envp)
+{
+ int delete = 0, force_delete = 0, force_create = 0;
+ int i, prefix_length;
+ const char *p;
+
+ setup_git_directory();
+ git_config(git_default_config);
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-d")) {
+ delete = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-D")) {
+ delete = 1;
+ force_delete = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-f")) {
+ force_create = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-r")) {
+ remote_only = 1;
+ continue;
+ }
+ die(builtin_branch_usage);
+ }
+
+ prefix_length = strlen(git_path("refs/heads/"));
+ p = resolve_ref(git_path("HEAD"), head_sha1, 0);
+ if (!p)
+ die("Failed to resolve HEAD as a valid ref");
+ head = strdup(p + prefix_length);
+
+ if (delete)
+ delete_branches(argc - i, argv + i, force_delete);
+ else if (i == argc && remote_only)
+ for_each_remote_ref(show_reference);
+ else if (i == argc)
+ for_each_branch_ref(show_reference);
+ else if (argc - i == 1)
+ create_branch (argv[i], head, force_create);
+ else
+ create_branch (argv[i], argv[i + 1], force_create);
+
+ return 0;
+}
diff --git a/builtin.h b/builtin.h
index 78275ea..0105358 100644
--- a/builtin.h
+++ b/builtin.h
@@ -28,5 +28,7 @@ extern int cmd_grep(int argc, const char
extern int cmd_add(int argc, const char **argv, char **envp);
extern int cmd_rev_list(int argc, const char **argv, char **envp);
extern int cmd_check_ref_format(int argc, const char **argv, char **envp);
+extern int cmd_branch(int argc, const char **argv, char **envp);
+extern int cmd_merge_base(int argc, const char **argv, char **envp);
#endif
diff --git a/commit.h b/commit.h
index 8d7514c..b1a518a 100644
--- a/commit.h
+++ b/commit.h
@@ -104,4 +104,9 @@ struct commit_graft *read_graft_line(cha
int register_commit_graft(struct commit_graft *, int);
int read_graft_file(const char *graft_file);
+/* merge-base.c */
+int for_each_merge_base(struct commit *rev1, struct commit *rev2,
+ int (*fn)(struct commit *commit, void *data),
+ void *data);
+
#endif /* COMMIT_H */
diff --git a/git-branch.sh b/git-branch.sh
deleted file mode 100755
index 134e68c..0000000
--- a/git-branch.sh
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/bin/sh
-
-USAGE='[(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'
-LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
-If one argument, create a new branch <branchname> based off of current HEAD.
-If two arguments, create a new branch <branchname> based off of <start-point>.'
-
-SUBDIRECTORY_OK='Yes'
-. git-sh-setup
-
-headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
-
-delete_branch () {
- option="$1"
- shift
- for branch_name
- do
- case ",$headref," in
- ",$branch_name,")
- die "Cannot delete the branch you are on." ;;
- ,,)
- die "What branch are you on anyway?" ;;
- esac
- branch=$(cat "$GIT_DIR/refs/heads/$branch_name") &&
- branch=$(git-rev-parse --verify "$branch^0") ||
- die "Seriously, what branch are you talking about?"
- case "$option" in
- -D)
- ;;
- *)
- mbs=$(git-merge-base -a "$branch" HEAD | tr '\012' ' ')
- case " $mbs " in
- *' '$branch' '*)
- # the merge base of branch and HEAD contains branch --
- # which means that the HEAD contains everything in both.
- ;;
- *)
- echo >&2 "The branch '$branch_name' is not a strict subset of your current HEAD.
-If you are sure you want to delete it, run 'git branch -D $branch_name'."
- exit 1
- ;;
- esac
- ;;
- esac
- rm -f "$GIT_DIR/refs/heads/$branch_name"
- echo "Deleted branch $branch_name."
- done
- exit 0
-}
-
-ls_remote_branches () {
- git-rev-parse --symbolic --all |
- sed -ne 's|^refs/\(remotes/\)|\1|p' |
- sort
-}
-
-force=
-while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
-do
- case "$1" in
- -d | -D)
- delete_branch "$@"
- exit
- ;;
- -r)
- ls_remote_branches
- exit
- ;;
- -f)
- force="$1"
- ;;
- --)
- shift
- break
- ;;
- -*)
- usage
- ;;
- esac
- shift
-done
-
-case "$#" in
-0)
- git-rev-parse --symbolic --branches |
- sort |
- while read ref
- do
- if test "$headref" = "$ref"
- then
- pfx='*'
- else
- pfx=' '
- fi
- echo "$pfx $ref"
- done
- exit 0 ;;
-1)
- head=HEAD ;;
-2)
- head="$2^0" ;;
-esac
-branchname="$1"
-
-rev=$(git-rev-parse --verify "$head") || exit
-
-git-check-ref-format "heads/$branchname" ||
- die "we do not like '$branchname' as a branch name."
-
-if [ -e "$GIT_DIR/refs/heads/$branchname" ]
-then
- if test '' = "$force"
- then
- die "$branchname already exists."
- elif test "$branchname" = "$headref"
- then
- die "cannot force-update the current branch."
- fi
-fi
-git update-ref "refs/heads/$branchname" $rev
diff --git a/git.c b/git.c
index 7db5cc1..fb66c0e 100644
--- a/git.c
+++ b/git.c
@@ -53,7 +53,9 @@ static void handle_internal_command(int
{ "grep", cmd_grep },
{ "add", cmd_add },
{ "rev-list", cmd_rev_list },
- { "check-ref-format", cmd_check_ref_format }
+ { "check-ref-format", cmd_check_ref_format },
+ { "branch", cmd_branch },
+ { "merge-base", cmd_merge_base }
};
int i;
diff --git a/merge-base.c b/merge-base.c
index 4856ca0..0aa6ed4 100644
--- a/merge-base.c
+++ b/merge-base.c
@@ -1,6 +1,6 @@
-#include <stdlib.h>
#include "cache.h"
#include "commit.h"
+#include "builtin.h"
#define PARENT1 1
#define PARENT2 2
@@ -167,16 +167,16 @@ static void mark_reachable_commits(struc
}
}
-static int merge_base(struct commit *rev1, struct commit *rev2)
+int for_each_merge_base(struct commit *rev1, struct commit *rev2,
+ int (*fn)(struct commit *commit, void *data),
+ void *data)
{
struct commit_list *list = NULL;
struct commit_list *result = NULL;
struct commit_list *tmp = NULL;
- if (rev1 == rev2) {
- printf("%s\n", sha1_to_hex(rev1->object.sha1));
- return 0;
- }
+ if (rev1 == rev2)
+ return fn(rev1, data);
parse_commit(rev1);
parse_commit(rev2);
@@ -220,12 +220,13 @@ static int merge_base(struct commit *rev
while (result) {
struct commit *commit = result->item;
+ int retval;
result = result->next;
if (commit->object.flags & UNINTERESTING)
continue;
- printf("%s\n", sha1_to_hex(commit->object.sha1));
- if (!show_all)
- return 0;
+ retval = fn(commit, data);
+ if (retval)
+ return retval;
commit->object.flags |= UNINTERESTING;
}
return 0;
@@ -234,7 +235,13 @@ static int merge_base(struct commit *rev
static const char merge_base_usage[] =
"git-merge-base [--all] <commit-id> <commit-id>";
-int main(int argc, char **argv)
+static int print_merge_base(struct commit *commit, void *data)
+{
+ printf("%s\n", sha1_to_hex(commit->object.sha1));
+ return show_all ? 0 : 1;
+}
+
+int cmd_merge_base(int argc, const char **argv, char **envp)
{
struct commit *rev1, *rev2;
unsigned char rev1key[20], rev2key[20];
@@ -243,7 +250,7 @@ int main(int argc, char **argv)
git_config(git_default_config);
while (1 < argc && argv[1][0] == '-') {
- char *arg = argv[1];
+ const char *arg = argv[1];
if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
show_all = 1;
else
@@ -260,5 +267,8 @@ int main(int argc, char **argv)
rev2 = lookup_commit_reference(rev2key);
if (!rev1 || !rev2)
return 1;
- return merge_base(rev1, rev2);
+
+ for_each_merge_base(rev1, rev2, print_merge_base, NULL);
+
+ return 0;
}
6b90d7b7af4bf577ccfeebef1f736e75631b052d
diff --git a/Makefile b/Makefile
index 5373986..a709e40 100644
--- a/Makefile
+++ b/Makefile
@@ -113,7 +113,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powe
### --- END CONFIGURATION SECTION ---
SCRIPT_SH = \
- git-bisect.sh git-branch.sh git-checkout.sh \
+ git-bisect.sh git-checkout.sh \
git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
git-fetch.sh \
git-format-patch.sh git-ls-remote.sh \
@@ -155,7 +155,7 @@ PROGRAMS = \
git-diff-index$X git-diff-stages$X \
git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \
git-hash-object$X git-index-pack$X git-init-db$X git-local-fetch$X \
- git-ls-files$X git-ls-tree$X git-mailinfo$X git-merge-base$X \
+ git-ls-files$X git-ls-tree$X git-mailinfo$X \
git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
git-peek-remote$X git-prune-packed$X git-read-tree$X \
git-receive-pack$X git-rev-parse$X \
@@ -170,7 +170,8 @@ PROGRAMS = \
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
git-count-objects$X git-diff$X git-push$X \
- git-grep$X git-add$X git-rev-list$X git-check-ref-format$X
+ git-grep$X git-add$X git-rev-list$X git-check-ref-format$X \
+ git-branch$X git-merge-base$X
# what 'all' will build and 'install' will install, in gitexecdir
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@ -214,11 +215,13 @@ LIB_OBJS = \
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
+ merge-base.o \
$(DIFF_OBJS)
BUILTIN_OBJS = \
- builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
- builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o
+ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o \
+ builtin-push.o builtin-grep.o builtin-add.o builtin-rev-list.o \
+ builtin-check-ref-format.o builtin-branch.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
diff --git a/builtin-branch.c b/builtin-branch.c
new file mode 100644
index 0000000..c7776a3
--- /dev/null
+++ b/builtin-branch.c
@@ -0,0 +1,154 @@
+/*
+ * Builtin "git branch"
+ *
+ * Copyright (c) 2006 Kristian Høgsberg <krh@redhat.com>
+ * Based on git-branch.sh by Junio C Hamano.
+ */
+
+#include "cache.h"
+#include "refs.h"
+#include "commit.h"
+#include "builtin.h"
+
+static const char builtin_branch_usage[] =
+ "git-branch [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r";
+
+
+static int remote_only = 0;
+static const char *head;
+static unsigned char head_sha1[20];
+
+static int find_sha1(struct commit *commit, void *data)
+{
+ return !memcmp(data, commit->object.sha1, sizeof commit->object.sha1);
+}
+
+static void delete_branches(int argc, const char **argv, int force)
+{
+ struct commit *rev1, *rev2;
+ unsigned char sha1[20];
+ const char *p, *name;
+ int i;
+
+ for (i = 0; i < argc; i++) {
+ if (!strcmp(head, argv[i]))
+ die("Cannot delete the branch you are currently on.");
+
+ name = git_path("refs/heads/%s", argv[i]);
+ p = resolve_ref(name, sha1, 1);
+ if (p == NULL)
+ die("Branch '%s' not found.", argv[i]);
+
+ rev1 = lookup_commit_reference(sha1);
+ rev2 = lookup_commit_reference(head_sha1);
+ if (!rev1 || !rev2)
+ die("Couldn't look up commit objects.");
+
+ /* This checks wether the merge bases of branch and
+ * HEAD contains branch -- which means that the HEAD
+ * contains everything in both.
+ */
+
+ if (!force &&
+ !for_each_merge_base(rev1, rev2, find_sha1, sha1)) {
+ fprintf(stderr,
+ "The branch '%s' is not a strict subset of your current HEAD.\n"
+ "If you are sure you want to delete it, run 'git branch -D %s'.\n",
+ argv[i], argv[i]);
+ exit(1);
+ }
+
+ unlink(name);
+ printf("Deleted branch %s.\n", argv[i]);
+ }
+}
+
+static int show_reference(const char *refname, const unsigned char *sha1)
+{
+ int is_head = !strcmp(refname, head);
+
+ printf("%c %s\n", (is_head ? '*' : ' '), refname);
+
+ return 0;
+}
+
+static void create_branch (const char *name, const char *start, int force)
+{
+ unsigned char sha1[20];
+ char ref[500];
+
+ snprintf (ref, sizeof ref, "heads/%s", name);
+ if (check_ref_format(ref))
+ die("'%s' is not a valid branch name.", name);
+
+ if (resolve_ref(git_path("refs/%s", ref), sha1, 1)) {
+ if (!force)
+ die("A branch named '%s' already exists.", name);
+ else if (!strcmp(head, name))
+ die("Cannot force update the current branch.");
+ }
+
+ if (get_sha1(start, sha1))
+ die("Not a valid branch point: '%s'", start);
+
+ if (write_ref_sha1_unlocked(ref, sha1))
+ die("Failed to create branch: %s.", strerror(errno));
+}
+
+int cmd_branch(int argc, const char **argv, char **envp)
+{
+ int delete = 0, force_delete = 0, force_create = 0;
+ int i, prefix_length;
+ const char *p;
+
+ setup_git_directory();
+ git_config(git_default_config);
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-d")) {
+ delete = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-D")) {
+ delete = 1;
+ force_delete = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-f")) {
+ force_create = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-r")) {
+ remote_only = 1;
+ continue;
+ }
+ die(builtin_branch_usage);
+ }
+
+ prefix_length = strlen(git_path("refs/heads/"));
+ p = resolve_ref(git_path("HEAD"), head_sha1, 0);
+ if (!p)
+ die("Failed to resolve HEAD as a valid ref");
+ head = strdup(p + prefix_length);
+
+ if (delete)
+ delete_branches(argc - i, argv + i, force_delete);
+ else if (i == argc && remote_only)
+ for_each_remote_ref(show_reference);
+ else if (i == argc)
+ for_each_branch_ref(show_reference);
+ else if (argc - i == 1)
+ create_branch (argv[i], head, force_create);
+ else
+ create_branch (argv[i], argv[i + 1], force_create);
+
+ return 0;
+}
diff --git a/builtin.h b/builtin.h
index 78275ea..0105358 100644
--- a/builtin.h
+++ b/builtin.h
@@ -28,5 +28,7 @@ extern int cmd_grep(int argc, const char
extern int cmd_add(int argc, const char **argv, char **envp);
extern int cmd_rev_list(int argc, const char **argv, char **envp);
extern int cmd_check_ref_format(int argc, const char **argv, char **envp);
+extern int cmd_branch(int argc, const char **argv, char **envp);
+extern int cmd_merge_base(int argc, const char **argv, char **envp);
#endif
diff --git a/commit.h b/commit.h
index 8d7514c..b1a518a 100644
--- a/commit.h
+++ b/commit.h
@@ -104,4 +104,9 @@ struct commit_graft *read_graft_line(cha
int register_commit_graft(struct commit_graft *, int);
int read_graft_file(const char *graft_file);
+/* merge-base.c */
+int for_each_merge_base(struct commit *rev1, struct commit *rev2,
+ int (*fn)(struct commit *commit, void *data),
+ void *data);
+
#endif /* COMMIT_H */
diff --git a/git-branch.sh b/git-branch.sh
deleted file mode 100755
index 134e68c..0000000
--- a/git-branch.sh
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/bin/sh
-
-USAGE='[(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'
-LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
-If one argument, create a new branch <branchname> based off of current HEAD.
-If two arguments, create a new branch <branchname> based off of <start-point>.'
-
-SUBDIRECTORY_OK='Yes'
-. git-sh-setup
-
-headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
-
-delete_branch () {
- option="$1"
- shift
- for branch_name
- do
- case ",$headref," in
- ",$branch_name,")
- die "Cannot delete the branch you are on." ;;
- ,,)
- die "What branch are you on anyway?" ;;
- esac
- branch=$(cat "$GIT_DIR/refs/heads/$branch_name") &&
- branch=$(git-rev-parse --verify "$branch^0") ||
- die "Seriously, what branch are you talking about?"
- case "$option" in
- -D)
- ;;
- *)
- mbs=$(git-merge-base -a "$branch" HEAD | tr '\012' ' ')
- case " $mbs " in
- *' '$branch' '*)
- # the merge base of branch and HEAD contains branch --
- # which means that the HEAD contains everything in both.
- ;;
- *)
- echo >&2 "The branch '$branch_name' is not a strict subset of your current HEAD.
-If you are sure you want to delete it, run 'git branch -D $branch_name'."
- exit 1
- ;;
- esac
- ;;
- esac
- rm -f "$GIT_DIR/refs/heads/$branch_name"
- echo "Deleted branch $branch_name."
- done
- exit 0
-}
-
-ls_remote_branches () {
- git-rev-parse --symbolic --all |
- sed -ne 's|^refs/\(remotes/\)|\1|p' |
- sort
-}
-
-force=
-while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
-do
- case "$1" in
- -d | -D)
- delete_branch "$@"
- exit
- ;;
- -r)
- ls_remote_branches
- exit
- ;;
- -f)
- force="$1"
- ;;
- --)
- shift
- break
- ;;
- -*)
- usage
- ;;
- esac
- shift
-done
-
-case "$#" in
-0)
- git-rev-parse --symbolic --branches |
- sort |
- while read ref
- do
- if test "$headref" = "$ref"
- then
- pfx='*'
- else
- pfx=' '
- fi
- echo "$pfx $ref"
- done
- exit 0 ;;
-1)
- head=HEAD ;;
-2)
- head="$2^0" ;;
-esac
-branchname="$1"
-
-rev=$(git-rev-parse --verify "$head") || exit
-
-git-check-ref-format "heads/$branchname" ||
- die "we do not like '$branchname' as a branch name."
-
-if [ -e "$GIT_DIR/refs/heads/$branchname" ]
-then
- if test '' = "$force"
- then
- die "$branchname already exists."
- elif test "$branchname" = "$headref"
- then
- die "cannot force-update the current branch."
- fi
-fi
-git update-ref "refs/heads/$branchname" $rev
diff --git a/git.c b/git.c
index 7db5cc1..fb66c0e 100644
--- a/git.c
+++ b/git.c
@@ -53,7 +53,9 @@ static void handle_internal_command(int
{ "grep", cmd_grep },
{ "add", cmd_add },
{ "rev-list", cmd_rev_list },
- { "check-ref-format", cmd_check_ref_format }
+ { "check-ref-format", cmd_check_ref_format },
+ { "branch", cmd_branch },
+ { "merge-base", cmd_merge_base }
};
int i;
diff --git a/merge-base.c b/merge-base.c
index 4856ca0..0aa6ed4 100644
--- a/merge-base.c
+++ b/merge-base.c
@@ -1,6 +1,6 @@
-#include <stdlib.h>
#include "cache.h"
#include "commit.h"
+#include "builtin.h"
#define PARENT1 1
#define PARENT2 2
@@ -167,16 +167,16 @@ static void mark_reachable_commits(struc
}
}
-static int merge_base(struct commit *rev1, struct commit *rev2)
+int for_each_merge_base(struct commit *rev1, struct commit *rev2,
+ int (*fn)(struct commit *commit, void *data),
+ void *data)
{
struct commit_list *list = NULL;
struct commit_list *result = NULL;
struct commit_list *tmp = NULL;
- if (rev1 == rev2) {
- printf("%s\n", sha1_to_hex(rev1->object.sha1));
- return 0;
- }
+ if (rev1 == rev2)
+ return fn(rev1, data);
parse_commit(rev1);
parse_commit(rev2);
@@ -220,12 +220,13 @@ static int merge_base(struct commit *rev
while (result) {
struct commit *commit = result->item;
+ int retval;
result = result->next;
if (commit->object.flags & UNINTERESTING)
continue;
- printf("%s\n", sha1_to_hex(commit->object.sha1));
- if (!show_all)
- return 0;
+ retval = fn(commit, data);
+ if (retval)
+ return retval;
commit->object.flags |= UNINTERESTING;
}
return 0;
@@ -234,7 +235,13 @@ static int merge_base(struct commit *rev
static const char merge_base_usage[] =
"git-merge-base [--all] <commit-id> <commit-id>";
-int main(int argc, char **argv)
+static int print_merge_base(struct commit *commit, void *data)
+{
+ printf("%s\n", sha1_to_hex(commit->object.sha1));
+ return show_all ? 0 : 1;
+}
+
+int cmd_merge_base(int argc, const char **argv, char **envp)
{
struct commit *rev1, *rev2;
unsigned char rev1key[20], rev2key[20];
@@ -243,7 +250,7 @@ int main(int argc, char **argv)
git_config(git_default_config);
while (1 < argc && argv[1][0] == '-') {
- char *arg = argv[1];
+ const char *arg = argv[1];
if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
show_all = 1;
else
@@ -260,5 +267,8 @@ int main(int argc, char **argv)
rev2 = lookup_commit_reference(rev2key);
if (!rev1 || !rev2)
return 1;
- return merge_base(rev1, rev2);
+
+ for_each_merge_base(rev1, rev2, print_merge_base, NULL);
+
+ return 0;
}
^ permalink raw reply related
* Re: [PATCH 1/2]: amendment
From: Junio C Hamano @ 2006-06-08 16:52 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
In-Reply-To: <Pine.LNX.4.63.0606081719400.27335@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> I completely forgot that with a global config, it makes sense to have
> aliases even if we are not in a git repository.
>
> So, in git.c, handle_alias() the "if (nongit)" makes no sense any longer.
> If I have to revise the patch anyway, I will include the change, but if
> you decide to take it, please change that.
>
> Ciao,
> Dscho
>
> P.S.: There might be other users (such as git-peek-remote) who want that
> change, too.
Well, this is pretty late in the 1.4.0 game and honestly I am
pretty reluctant to merge this in, push 1.4.0 out in 48 hours
and leave for nearly a week.
So either we would reschedule 1.4.0 and shoot for June 24th, or
do 1.4.0 this weekend as planned, and leave this as the first
item (perhaps the second, after applying many small clean-ups
I've privately received, which I haven't acted on other than
quickly reviewing and asking the submitter to rebase and resend
cc'ing the list) in the post-1.4.0 development cycle. This
potentially is a candidate to backport to 1.4.X series.
My preference is to cook this in "next" for a while and merge it
post 1.4.0.
^ permalink raw reply
* Re: [PATCH 1/2]: amendment
From: Junio C Hamano @ 2006-06-08 16:51 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
In-Reply-To: <Pine.LNX.4.63.0606081719400.27335@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> I completely forgot that with a global config, it makes sense to have
> aliases even if we are not in a git repository.
>
> So, in git.c, handle_alias() the "if (nongit)" makes no sense any longer.
> If I have to revise the patch anyway, I will include the change, but if
> you decide to take it, please change that.
>
> Ciao,
> Dscho
>
> P.S.: There might be other users (such as git-peek-remote) who want that
> change, too.
Well, this is pretty late in the 1.4.0 game and honestly I am
pretty reluctant to merge this in, push 1.4.0 out in 48 hours
and leave for nearly a week.
So either we would reschedule 1.4.0 and shoot for June 24th, or
do 1.4.0 this weekend as planned, and leave this as the first
item (perhaps the second, after applying many small clean-ups
I've privately received, which I haven't acted on other than
quickly reviewing and asking the submitter to rebase and resend
cc'ing the list) in the post-1.4.0 development cycle. This
potentially is a candidate to backport to 1.4.X series.
My preference is to cook this in "next" for a while and merge it
post 1.4.0.
^ permalink raw reply
* Re: HEAD branch duplicated in remotes/origin
From: Junio C Hamano @ 2006-06-08 16:39 UTC (permalink / raw)
To: Uwe Zeisberger; +Cc: git
In-Reply-To: <20060608123337.GA12456@informatik.uni-freiburg.de>
Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:
> I wonder if this is easier not to add the other duplicate.
Unfortunately the above is probably easier. The other duplicate
is coming from the lowlevel code that makes sure each of the
fetch-pack parameters is not used to match more than once. We
should fix it eventually, though.
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Sean @ 2006-06-08 16:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes.Schindelin, lukass, git, junkio
In-Reply-To: <7v1wtzaa26.fsf@assigned-by-dhcp.cox.net>
On Thu, 08 Jun 2006 09:25:53 -0700
Junio C Hamano <junkio@cox.net> wrote:
> The wording "--no-local" means you are looking at things
> relative to a particular repository. I.e. some configuration
> variables come from repository-local file, and others from
> somewhere else. But I do not think that somewhere else is
> "global". We are reading from $HOME, which is different
> depending on who is interacting with that same repository. So I
> would probably call the other one "--user" or something if I
> were force to pick name.
--user or --home makes a lot of sense. Alternatively you could
just be explicit: --config=~ or --config=/etc/gitconfig where
/.gitconfig is automatically appended to the path if it ends in
a directory name.
Sean
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Junio C Hamano @ 2006-06-08 16:25 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Lukas Sandström, Git Mailing List, junkio
In-Reply-To: <Pine.LNX.4.63.0606081340230.25911@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>> Johannes Schindelin wrote:
> On Thu, 8 Jun 2006, Lukas Sandström wrote:
>> > Since there is a global config now, we need a way to access it
>> > conveniently. Now you can say
>> >
>> > git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
>> >
>> > to set the alias globally (it will be stored in ~/.gitconfig).
>>
>> Wouldn't it make more sense to call the flag --global ?
>
> Sure, why not? Other opinions? (I will not add a test case until this is
> resolved! ;-)
The wording "--no-local" means you are looking at things
relative to a particular repository. I.e. some configuration
variables come from repository-local file, and others from
somewhere else. But I do not think that somewhere else is
"global". We are reading from $HOME, which is different
depending on who is interacting with that same repository. So I
would probably call the other one "--user" or something if I
were force to pick name.
But as you know, I am horrible at picking names, so please don't
stop this from coming up with a good name the list can agree
upon.
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Aneesh Kumar K.V @ 2006-06-08 15:35 UTC (permalink / raw)
To: Karl Hasselstr?m; +Cc: Lukas Sandstr?m, Git Mailing List, junkio
In-Reply-To: <20060608133747.GA15374@diana.vm.bytemark.co.uk>
On Thu, Jun 08, 2006 at 03:37:47PM +0200, Karl Hasselstr?m wrote:
> On 2006-06-08 13:41:04 +0200, Johannes Schindelin wrote:
>
> My vote goes to --no-local, but only if we also get a --no-no-local
> flag with the opposite meaning. Otherwise, I'd prefer --global. :-)
>
I guess it makes much sense to rename the command to git-config and say
git config alias.l -> for golbal config
git config --repo alias.l -> for repo specific config
-aneesh
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Aneesh Kumar K.V @ 2006-06-08 15:32 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: junkio, git
In-Reply-To: <Pine.LNX.4.63.0606081331140.11910@wbgn013.biozentrum.uni-wuerzburg.de>
On Thu, Jun 08, 2006 at 01:31:46PM +0200, Johannes Schindelin wrote:
>
> Since there is a global config now, we need a way to access it
> conveniently. Now you can say
>
> git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
>
> to set the alias globally (it will be stored in ~/.gitconfig).
>
how about making the above
git config --repo alias.l "log --stat -M ORIG_HEAD.."
-aneesh
^ permalink raw reply
* [PATCH 1/2]: amendment
From: Johannes Schindelin @ 2006-06-08 15:22 UTC (permalink / raw)
To: junkio, git
Hi,
I completely forgot that with a global config, it makes sense to have
aliases even if we are not in a git repository.
So, in git.c, handle_alias() the "if (nongit)" makes no sense any longer.
If I have to revise the patch anyway, I will include the change, but if
you decide to take it, please change that.
Ciao,
Dscho
P.S.: There might be other users (such as git-peek-remote) who want that
change, too.
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Johannes Schindelin @ 2006-06-08 15:19 UTC (permalink / raw)
To: Jon Loeliger; +Cc: Git List, Junio C Hamano
In-Reply-To: <1149775348.23938.236.camel@cashmere.sps.mot.com>
Hi,
On Thu, 8 Jun 2006, Jon Loeliger wrote:
> On Thu, 2006-06-08 at 06:30, Johannes Schindelin wrote:
>
> > - The --no-local flag could be implemented more cleanly, but also less
>
> Could we have multiple levels, and have names that call out
> where it applies? Perhaps something like:
>
> --repo into $GIT_DIR/.gitconfig <- current default, right?
> --home into ~/.gitconfig
> --site into /etc/gitconfig
> --share into /usr/share/git/config
>
> My issue is that --no-local is vague and doesn't call out
> where it actually does go. There could be more than one
> different non-local place.
The whole idea is that there are only two levels of configuration. Global
(applies to all calls to git) and local (applies only to the repository).
Now, it makes sense to make settings overrideable in a certain order: If
the global default does not match your needs in a particular case,
override it. With "git-repo-config <key> <value>".
*However*, if you want to change the default, it makes sense to say
"--no-local" or "--global", but I doubt that it makes any sense at all to
access a certain finer level. For example, when would you possibly need to
wrap in porcelain a method to query exactly which aliases are defined in
/usr/local/share/git/config?
IOW if you want to edit /etc/gitconfig or something else you need admin
permissions for with git-repo-config, you should look for another
profession. Quickly.
> But, hey, that's all pre-coffee.
post-coffee is pre-coffee.
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Alex Riesen @ 2006-06-08 14:49 UTC (permalink / raw)
To: Jon Loeliger; +Cc: Johannes Schindelin, Git List, Junio C Hamano
In-Reply-To: <1149775348.23938.236.camel@cashmere.sps.mot.com>
On 6/8/06, Jon Loeliger <jdl@freescale.com> wrote:
> --repo into $GIT_DIR/.gitconfig <- current default, right?
> --home into ~/.gitconfig
> --site into /etc/gitconfig
> --share into /usr/share/git/config
BTW, if we go that far, maybe it makes more sense to
implement a way to include files other config files?
So repo-level config can (maybe implicitely) have an
"include ~/.gitconfig" which in turn can "include /etc/gitconfig".
We could even do like C-preprocessor does: relative
pathnames can be searched in a defined set of directores.
That's all overengineered, probably. I never needed .git/config,
except for switching exec-bit (which I'd like to have on per-site
basis, to be fair).
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Jon Loeliger @ 2006-06-08 14:02 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <Pine.LNX.4.63.0606081329200.11910@wbgn013.biozentrum.uni-wuerzburg.de>
On Thu, 2006-06-08 at 06:30, Johannes Schindelin wrote:
>
> - The name. I personally prefer .gitconfig, since we talk about the repo
> config all the time. But I have no strong feelings there.
I like .gitconfig over .gitrc.
> - The --no-local flag could be implemented more cleanly, but also less
Could we have multiple levels, and have names that call out
where it applies? Perhaps something like:
--repo into $GIT_DIR/.gitconfig <- current default, right?
--home into ~/.gitconfig
--site into /etc/gitconfig
--share into /usr/share/git/config
My issue is that --no-local is vague and doesn't call out
where it actually does go. There could be more than one
different non-local place.
> - With this, repo-config does no longer merit its name. What do people think
> about making it a builtin named "git config"? (Of course, nothing hinders
> us to keep the synonymous "repo-config" indefinitely...)
I have often forgotten the "repo-" part, and go looking
for the "git config ..." man page and command. I think
it should be "git config".
Perhaps, "git repo-config" would be "git config --repo ...."
And "git config ..." would need an explict --home, --repo,
--site type location flag from above?
But, hey, that's all pre-coffee.
jdl
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Alex Riesen @ 2006-06-08 14:06 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Lukas Sandström, Git Mailing List, junkio
In-Reply-To: <Pine.LNX.4.63.0606081340230.25911@wbgn013.biozentrum.uni-wuerzburg.de>
> >
> > Wouldn't it make more sense to call the flag --global ?
>
> Sure, why not? Other opinions? (I will not add a test case until this is
> resolved! ;-)
>
"--no-gitconfig" (as "--norc" in bash).
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Karl Hasselström @ 2006-06-08 13:37 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Lukas Sandström, Git Mailing List, junkio
In-Reply-To: <Pine.LNX.4.63.0606081340230.25911@wbgn013.biozentrum.uni-wuerzburg.de>
On 2006-06-08 13:41:04 +0200, Johannes Schindelin wrote:
> On Thu, 8 Jun 2006, Lukas Sandström wrote:
>
> > Johannes Schindelin wrote:
> > > Since there is a global config now, we need a way to access it
> > > conveniently. Now you can say
> > >
> > > git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
> > >
> > > to set the alias globally (it will be stored in ~/.gitconfig).
> > >
> >
> > Wouldn't it make more sense to call the flag --global ?
>
> Sure, why not? Other opinions? (I will not add a test case until
> this is resolved! ;-)
My vote goes to --no-local, but only if we also get a --no-no-local
flag with the opposite meaning. Otherwise, I'd prefer --global. :-)
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Johannes Schindelin @ 2006-06-08 13:35 UTC (permalink / raw)
To: Nikolai Weibull; +Cc: Sven Ekman, git, junkio
In-Reply-To: <dbfc82860606080613n5b5f6a5bs7a8f461a4188228c@mail.gmail.com>
Hi,
On Thu, 8 Jun 2006, Nikolai Weibull wrote:
> Who said anything about something more than one configuration file? It's
> nice to have a directory if we later decide to store other kinds of
> files there as well, e.g., templates or some keyring information or
> something else, perhaps not well-suited for storing in an ini-like file.
My point was: this has nothing to do with the "git config". Gitk, for
example, has its own file there, ~/.gitk.
> > Alternatively, we could introduce a config variable "core.globalConfig" to
> > see where the global config is.
>
> That is a very good idea. We wouldn't need an environment variable in
> that case.
>
> nikolai (who wonders if people can spot irony and sarcasm without extra
> help)
No they can't. You almost had me falling for it...
Ciao,
Dscho
P.S.: I also wanted to mention that we could migrate all the config into
an XML format. And maybe have an SQL backend instead of an object store.
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Nikolai Weibull @ 2006-06-08 13:13 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Sven Ekman, git, junkio
In-Reply-To: <Pine.LNX.4.63.0606081415380.26091@wbgn013.biozentrum.uni-wuerzburg.de>
On 6/8/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> On Thu, 8 Jun 2006, Nikolai Weibull wrote:
> > On 6/8/06, Sven Ekman <svekman@yahoo.se> wrote:
> > > <Johannes.Schindelin@gmx.de> skrev:
> > > Have you considered making ~/.gitconfig a directory?
> > > Maybe Git wants to store more data later.
> > I second that.
> I don't. What's wrong with the simple approach of a single config file?
> You can use a single tool for all the configuration, and do not need to
> care about anything.
Who said anything about something more than one configuration file?
It's nice to have a directory if we later decide to store other kinds of files
there as well, e.g., templates or some keyring information or something else,
perhaps not well-suited for storing in an ini-like file.
> > And it'd be nice if it was configurable through an environment variable,
> > e.g., GIT_USER_CONFIG_HOME.
> Let's see. AFAIK all programs I know (including cvs and vim, for
> one) have a fixed name. Hmm. Perhaps this is for a reason? Like, to reduce
> confusion?
That's hardly a very good reason. It's not like you _have_ to use another name.
I keep as many configuration files as possible in ~/.local/etc/, as it
simplifies
keeping them in a Git repository. Here's an extract from my .zprofile:
XDG_CONFIG_HOME=~/.local/etc
VIMINIT="so $XDG_CONFIG_HOME/vim/vimrc"
INPUTRC=$XDG_CONFIG_HOME/inputrc
INDENT_PROFILE=$XDG_CONFIG_HOME/indentrc
SCREENRC=$XDG_CONFIG_HOME/screenrc
GNUPGHOME=$XDG_CONFIG_HOME/gnupg
IRBRC=$XDG_CONFIG_HOME/irbrc
LFTP_HOME=$XDG_CONFIG_HOME/lftp
MPLAYER_HOME=$XDG_CONFIG_HOME/mplayer
GTK2_RC_FILES=$XDG_CONFIG_HOME/gtkrc
The only programs that don't play along, yet, are Mozilla, OpenSSH,
and Subversion. (Mozilla is actually compile-time configurable.)
But I guess I should be providing a patch instead of just a bunch of
reasoning for someone else to write one...
> Alternatively, we could introduce a config variable "core.globalConfig" to
> see where the global config is.
That is a very good idea. We wouldn't need an environment variable in
that case.
nikolai (who wonders if people can spot irony and sarcasm without extra help)
^ permalink raw reply
* Re: git-cvsservr questions
From: Jon Loeliger @ 2006-06-08 13:03 UTC (permalink / raw)
To: git
> Very strange. The calling line to git-cvsserver should have the
> 'pserver' option. Perhaps the inetd configuration is missing the
> doubled-up pserver?
Oh wow.
I thought I had tried that step already. So I went back and looked.
I _had_ tried that step -- but it was when I didn't have a full path
to the git-cvsserver executable on my inetd.conf line...
In summary, I had to:
use a full path to the excutable,
double the pserver command line arg,
fix the owner of my logfile to be "nobody".
Worked like a charm!
Thanks!
jdl
^ permalink raw reply
* Re: HEAD branch duplicated in remotes/origin
From: Uwe Zeisberger @ 2006-06-08 12:33 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vverc9i4i.fsf@assigned-by-dhcp.cox.net>
Hello Junio,
Junio C Hamano wrote:
> Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:
>
> > when cloning with --use-separate-remote, $GITDIR/remotes/origin contains
> > two references to refs/heads/master.
>
> Thanks for noticing.
>
> Very lightly tested but I think this should fix it.
> -- >8 --
> git-clone: fix duplicated "master" in $GIT_DIR/remotes/origin
>
> Under --use-separate-remote we ended up duplicating the branch
> remote HEAD pointed at in $GIT_DIR/remotes/origin file.
>
> Signed-off-by: Junio C Hamano <junkio@cox.net>
> ---
> diff --git a/git-clone.sh b/git-clone.sh
> index de59904..64318b4 100755
> --- a/git-clone.sh
> +++ b/git-clone.sh
> @@ -391,11 +391,16 @@ Pull: refs/heads/$head_points_at:$origin
> (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
> while read dotslref
> do
> - name=`expr "$dotslref" : './\(.*\)'` &&
> - test "$use_separate_remote" = '' && {
> - test "$head_points_at" = "$name" ||
> - test "$origin" = "$name"
> - } ||
> + name=`expr "$dotslref" : './\(.*\)'`
> + if test "z$head_points_at" = "z$name"
> + then
> + continue
> + fi
> + if test "$use_separate_remote" = '' &&
> + test "z$origin" = "z$name"
> + then
> + continue
> + fi
> echo "Pull: refs/heads/${name}:$remote_top/${name}"
> done >>"$GIT_DIR/remotes/$origin" &&
> case "$use_separate_remote" in
>
I wonder if this is easier not to add the other duplicate. That is let
this as it is and don't add the head HEAD points at. Don't know, didn't
look into it.
Moreover, is it sound to error if a Pull: line is duplicated? In my
eyes at least the error message is wrong/missleading. Otherwise the
patch works for me, but probably I only did the same testing as you.
Best regards
Uwe
--
Uwe Zeisberger
cal 9 1752 | grep 10
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Johannes Schindelin @ 2006-06-08 12:21 UTC (permalink / raw)
To: Nikolai Weibull; +Cc: Sven Ekman, git, junkio
In-Reply-To: <dbfc82860606080506y52dc2771sbf6c90e7246ca4c9@mail.gmail.com>
Hi,
On Thu, 8 Jun 2006, Nikolai Weibull wrote:
> On 6/8/06, Sven Ekman <svekman@yahoo.se> wrote:
> > <Johannes.Schindelin@gmx.de> skrev:
> >
> > > There are three subjects for discussion:
> >
> > Have you considered making ~/.gitconfig a directory?
> > Maybe Git wants to store more data later.
>
> I second that.
I don't. What's wrong with the simple approach of a single config file?
You can use a single tool for all the configuration, and do not need to
care about anything.
After all, it is about _configuration_, not data storing. That is what
$GIT_DIR/objects is for.
> And it'd be nice if it was configurable through an environment variable,
> e.g., GIT_USER_CONFIG_HOME.
<sarcasm ignore=if-possible>
Let's see. AFAIK all programs I know (including cvs and vim, for
one) have a fixed name. Hmm. Perhaps this is for a reason? Like, to reduce
confusion?
Alternatively, we could introduce a config variable "core.globalConfig" to
see where the global config is.
</sarcasm>
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 0/2] Introduce ~/.gitconfig
From: Nikolai Weibull @ 2006-06-08 12:06 UTC (permalink / raw)
To: Sven Ekman; +Cc: Johannes Schindelin, git, junkio
In-Reply-To: <20060608120216.46722.qmail@web25908.mail.ukl.yahoo.com>
On 6/8/06, Sven Ekman <svekman@yahoo.se> wrote:
> <Johannes.Schindelin@gmx.de> skrev:
>
> > There are three subjects for discussion:
>
> Have you considered making ~/.gitconfig a directory?
> Maybe Git wants to store more data later.
I second that. And it'd be nice if it was configurable through
an environment variable, e.g., GIT_USER_CONFIG_HOME.
A better name may be possible ;-).
nikolai
^ permalink raw reply
* SV: [PATCH 0/2] Introduce ~/.gitconfig
From: Sven Ekman @ 2006-06-08 12:02 UTC (permalink / raw)
To: Johannes Schindelin, git, junkio
In-Reply-To: <Pine.LNX.4.63.0606081329200.11910@wbgn013.biozentrum.uni-wuerzburg.de>
<Johannes.Schindelin@gmx.de> skrev:
> There are three subjects for discussion:
Have you considered making ~/.gitconfig a directory?
Maybe Git wants to store more data later.
Maybe, porcelains would want to use this directory,
too. Gitk, tig, maybe Cogito at some time. One could
have the configuration of all these git-related tools
in a common namespace.
People like me, who work on a lot of different
machines, could simply sync this directory across
accounts and always work in their environment.
Sven
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Johannes Schindelin @ 2006-06-08 11:41 UTC (permalink / raw)
To: Lukas Sandström; +Cc: Git Mailing List, junkio
In-Reply-To: <44880BE8.40804@etek.chalmers.se>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 492 bytes --]
Hi,
On Thu, 8 Jun 2006, Lukas Sandström wrote:
> Johannes Schindelin wrote:
> > Since there is a global config now, we need a way to access it
> > conveniently. Now you can say
> >
> > git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
> >
> > to set the alias globally (it will be stored in ~/.gitconfig).
> >
>
> Wouldn't it make more sense to call the flag --global ?
Sure, why not? Other opinions? (I will not add a test case until this is
resolved! ;-)
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 2/2] repo-config: learn the flag "--no-local"
From: Lukas Sandström @ 2006-06-08 11:37 UTC (permalink / raw)
To: Git Mailing List; +Cc: Johannes Schindelin, junkio
In-Reply-To: <Pine.LNX.4.63.0606081331140.11910@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin wrote:
> Since there is a global config now, we need a way to access it
> conveniently. Now you can say
>
> git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
>
> to set the alias globally (it will be stored in ~/.gitconfig).
>
Wouldn't it make more sense to call the flag --global ?
/Lukas
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox