git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Implementing branch attributes in git config
@ 2006-05-07 21:34 Pavel Roskin
  2006-05-07 22:24 ` Junio C Hamano
  2006-05-08  0:05 ` Linus Torvalds
  0 siblings, 2 replies; 75+ messages in thread
From: Pavel Roskin @ 2006-05-07 21:34 UTC (permalink / raw)
  To: git

Hello!

I have tried to implement branch attributes (more specifically, the
default for git-fetch) in git config.  It turns out that the format of
the config file is to rigid.

Minuses, underscores, colons and dots are not allowed in the section
headers and keys.  I can understand that dots should be allowed either
in the section names or in the key names, but other limitations seem
totally unnecessary.

I think a good implementation should allow any characters in the keys,
even "=", because the key can be quoted.  Section names may disallow
square brackets and dots.

Such limitations make it unpractical to use branch names in section or
key names.  I'd like to have it fixed.

The only remaining place is values.  This means that there should be
multiple entries for the same key.  While this is allowed, it seems
quite fragile and inconvenient.

In particular, git-repo-config leaves the config file locked in the
regex is wrong:

$ git-repo-config branch.fetch "master:origin" +
Invalid pattern: +
$ git-repo-config branch.fetch "master:origin" +
could not lock config file

To fix it, just add "close(fd); unlink(lock_file);" after "Invalid
pattern" in config.c.

I don't quite understand what pattern is needed to add an entry.  "foo"
seems to work fine, I don't know why.

That problem with multiple values is that they are quite fragile and
require special options to access them.  Since regex is used, dots in
the branch names need to be escaped.  Probably more escapes are needed.

Anyway, here's the preliminary patch that implements default fetch
branches.  Unfortunately, it doesn't even come close to the goal of
having per-branch attributes due to the config file limitations.

To add an entry, use

git-repo-config branch.fetch "localbranch:remotebranch" foo


Read the default fetch branch from the config file

From: Pavel Roskin <proski@gnu.org>


---

 git-fetch.sh |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/git-fetch.sh b/git-fetch.sh
index 280f62e..a5ea92b 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -61,12 +61,25 @@ do
 	shift
 done
 
+get_config_rem_branch() {
+	fetch_branch=origin
+	cur_branch=$(expr $(git-symbolic-ref HEAD) : 'refs/heads/\(.*\)')
+	test -z "$cur_branch" && return
+	cur_branch_esc=$(echo $cur_branch | sed 's/\./\\./')
+	branch_map=$(git-repo-config --get branch.fetch "^$cur_branch_esc:")
+	test -z "$branch_map" && return
+	rem_branch=$(expr "$branch_map" : "$cur_branch_esc:\(.*\)")
+	test -z "$rem_branch" && return
+	fetch_branch="$rem_branch"
+}
+
 case "$#" in
 0)
-	test -f "$GIT_DIR/branches/origin" ||
-		test -f "$GIT_DIR/remotes/origin" ||
-			die "Where do you want to fetch from today?"
-	set origin ;;
+	get_config_rem_branch
+	test -f "$GIT_DIR/branches/$fetch_branch" ||
+		test -f "$GIT_DIR/remotes/$fetch_branch" ||
+			die "No remote branch \"$fetch_branch\""
+	set "$fetch_branch" ;;
 esac
 
 remote_nick="$1"


-- 
Regards,
Pavel Roskin

^ permalink raw reply related	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2006-05-11 17:22 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-07 21:34 Implementing branch attributes in git config Pavel Roskin
2006-05-07 22:24 ` Junio C Hamano
2006-05-08  0:43   ` Johannes Schindelin
2006-05-08  0:05 ` Linus Torvalds
2006-05-08  0:18   ` Linus Torvalds
2006-05-08  0:25   ` Linus Torvalds
2006-05-08  1:05     ` Johannes Schindelin
2006-05-08  1:21       ` Pavel Roskin
2006-05-08  1:27         ` Johannes Schindelin
2006-05-08  1:55           ` Pavel Roskin
2006-05-08  9:00             ` Junio C Hamano
2006-05-08 12:17               ` Johannes Schindelin
2006-05-08 15:15               ` Pavel Roskin
     [not found]   ` <20060507203458.439d8815.seanlkml@sympatico.ca>
2006-05-08  0:34     ` sean
2006-05-08  0:55       ` Linus Torvalds
2006-05-08  1:04         ` Pavel Roskin
     [not found]         ` <20060507211145.36fb1be4.seanlkml@sympatico.ca>
2006-05-08  1:11           ` sean
2006-05-08  0:36   ` Pavel Roskin
2006-05-08  0:43     ` Linus Torvalds
2006-05-08  1:27       ` Junio C Hamano
     [not found]         ` <20060507213445.66a2a3b0.seanlkml@sympatico.ca>
2006-05-08  1:34           ` sean
2006-05-08  1:45             ` Johannes Schindelin
     [not found]               ` <20060507214429.623905a6.seanlkml@sympatico.ca>
2006-05-08  1:44                 ` sean
2006-05-08  2:29             ` Junio C Hamano
     [not found]               ` <20060507223918.6112f0c1.seanlkml@sympatico.ca>
2006-05-08  2:39                 ` sean
2006-05-08 23:20                   ` Daniel Barkalow
     [not found]                     ` <20060508193005.40f249a1.seanlkml@sympatico.ca>
2006-05-08 23:30                       ` sean
2006-05-08 23:44                         ` Johannes Schindelin
     [not found]                           ` <20060508200826.2b0f34a6.seanlkml@sympatico.ca>
2006-05-09  0:08                             ` sean
2006-05-09  0:23                               ` Johannes Schindelin
2006-05-09  0:37                               ` Linus Torvalds
     [not found]                                 ` <20060508204933.539ddd8b.seanlkml@sympatico.ca>
2006-05-09  0:49                                   ` sean
2006-05-09  0:54                                 ` Junio C Hamano
2006-05-09  1:05                                   ` Linus Torvalds
2006-05-09  1:18                                     ` Junio C Hamano
2006-05-09  1:30                                       ` Linus Torvalds
2006-05-09  5:31                                         ` Junio C Hamano
2006-05-09  1:57                                       ` Linus Torvalds
     [not found]                                         ` <20060508224721.045a48fb.seanlkml@sympatico.ca>
2006-05-09  2:47                                           ` sean
2006-05-09  3:08                                             ` Linus Torvalds
     [not found]                                               ` <20060508230752.43118643.seanlkml@sympatico.ca>
2006-05-09  3:07                                                 ` sean
2006-05-09  4:11                                                   ` Linus Torvalds
2006-05-09  4:28                                                     ` Jakub Narebski
2006-05-09 11:21                                                       ` Johannes Schindelin
2006-05-09 15:29                                                         ` Linus Torvalds
2006-05-09 18:03                                                         ` Junio C Hamano
2006-05-09 19:24                                                           ` Linus Torvalds
     [not found]                                                             ` <20060509154459.40cc0d13.seanlkml@sympatico.ca>
2006-05-09 19:44                                                               ` sean
     [not found]                                                                 ` <20060509180955.373a2c1d.seanlkml@sympatico.ca>
2006-05-09 22:09                                                                   ` sean
2006-05-09 22:42                                                                     ` Junio C Hamano
     [not found]                                                                       ` <20060509184519.5a707231.seanlkml@sympatico.ca>
2006-05-09 22:45                                                                         ` sean
     [not found]                                                                         ` <20060509190708.4ee6656e.seanlkml@sympatico.ca>
2006-05-09 23:07                                                                           ` sean
2006-05-09 23:23                                                                         ` Pavel Roskin
2006-05-10  0:17                                                                     ` Linus Torvalds
     [not found]                                                                       ` <20060509210857.27df014e.seanlkml@sympatico.ca>
2006-05-10  1:08                                                                         ` sean
2006-05-10  2:08                                                                           ` Linus Torvalds
2006-05-10  7:19                                                                             ` Martin Langhoff
2006-05-10 11:07                                                                               ` Johannes Schindelin
2006-05-10 15:37                                                                               ` Linus Torvalds
2006-05-10 16:03                                                                                 ` Jakub Narebski
2006-05-10 23:17                                                                                 ` Martin Langhoff
2006-05-10 23:55                                                                                   ` Linus Torvalds
2006-05-11  0:11                                                                                     ` Linus Torvalds
2006-05-11  9:51                                                                                       ` Jeff King
2006-05-11 11:39                                                                                         ` Jeff King
2006-05-11  0:13                                                                                     ` Martin Langhoff
2006-05-11 10:30                                                                                       ` Johannes Schindelin
2006-05-11  1:53                                                                                     ` Nicolas Pitre
2006-05-11  6:02                                                                                       ` Jakub Narebski
     [not found]                                                                       ` <20060509213853.0fd8af0f.seanlkml@sympatico.ca>
2006-05-10  1:38                                                                         ` sean
2006-05-11 17:22                                                             ` Junio C Hamano
2006-05-09  4:20                                                 ` Pavel Roskin
2006-05-09 11:26                                               ` Martin Waitz
2006-05-09 11:34                                                 ` Johannes Schindelin
2006-05-08 23:40                     ` Johannes Schindelin

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).