* Re: [PATCH v3] contrib git-resurrect: find traces of a branch name and resurrect it
From: Junio C Hamano @ 2009-02-02 2:31 UTC (permalink / raw)
To: Thomas Rast; +Cc: git, Boyd Stephen Smith Jr.
In-Reply-To: <1233524085-25342-1-git-send-email-trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
>> Reading everything down to the root commit sounds like fun. rev-list
>> gives you the output from newer to older so you may want to break out once
>> you have found enough candidates.
>>
>> Anyway, if I were doing this script, I'd write this part like this without
>> a shell loop:
>>
>> _x40="[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
>> _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
>>
>> git rev-list --all --grep="Merge branch '$1'" \
>> --pretty=tformat:"%H %P %s" |
>> sed -ne "s/^$_x40 $_x40 \($_x40\) Merge .*/\1/p"
>
> Nice trick. The same also works for scan_merge_targets() and gives it
> a nice speed boost too. Unfortunately my sed-fu is not good enough to
> figure out how to only print the first line (for resurrections from
> pu, we expect there to be a single match).
Do you mean something like this?
sed -n -e "/^$_x40 $_x40 \($_x40\) Merge .*/ {
s//\1/p
q
}"
^ permalink raw reply
* Re: [PATCH v2 1/4] Add log.mailmap as configurational option for mailmap location
From: Junio C Hamano @ 2009-02-02 3:01 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: git
In-Reply-To: <ce94ea88e3182e97997c23f71e184e0db64fa708.1233520945.git.marius@trolltech.com>
Marius Storm-Olsen <marius@trolltech.com> writes:
> This allows us to override a repo mailmap file, or to use
> mailmap files elsewhere than the repository root.
I think the new feature is not so well conceived.
Should it always be a wholesale override, or should it also support
augmenting the repository version with a private copy?
> diff --git a/builtin-blame.c b/builtin-blame.c
> index aae14ef..4b63775 100644
> --- a/builtin-blame.c
> +++ b/builtin-blame.c
> @@ -2394,7 +2394,7 @@ parse_done:
> die("reading graft file %s failed: %s",
> revs_file, strerror(errno));
>
> - read_mailmap(&mailmap, ".mailmap", NULL);
> + read_mailmap(&mailmap, NULL, NULL);
Your callers always seem to pass NULL for the second argument. Doesn't it
make a lot more sense to get rid of it?
^ permalink raw reply
* Re: [PATCH v2 0/4] Extend mailmap functionality
From: Junio C Hamano @ 2009-02-02 3:03 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: git
In-Reply-To: <cover.1233520945.git.marius@trolltech.com>
Marius Storm-Olsen <marius@trolltech.com> writes:
> 2) Lets you replace both name and email of an author/committer, based
> on a name and/or email. So, should you have done commits with faulty
> address, or if an old email simply isn't valid anymore, you can add
> a mapping for that to replace it. So, the old style mapping is
> Proper Name <commit@email.xx>
>
> while this patch series adds support for
> Proper Name <proper@email.xx> <commit@email.xx>
> Proper Name <proper@email.xx> Commit Name <commit@email.xx>
>
> This extended mapping is necessary when a company wants to have their
> repositories open to the public, but needs to protect the identities
> of the developers. It enables you to only show nicks and standardized
> emails, like 'Dev123 <bugs@company.xx>' in the public repo, but by
> using an private mailmap file, map the name back to
> 'John Doe <john.doe@company.xx>' inside the company.
I do not find the "necessary" argument very convincing nor I find the
particular use case sane. You may want to do things that way, but I do
not know if it is the best way to go about it.
The new mapping however brings in more flexibility, and there may be other
use cases where people benefit from that flexibility. I am slightly in
favor than neutral to this new feature.
^ permalink raw reply
* Re: [PATCH v2 2/4] Add find_insert_index, insert_at_index and clear_func functions to string_list
From: Junio C Hamano @ 2009-02-02 3:03 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: git
In-Reply-To: <75a7d437c1b32600c509bdef5010e6ac30b6cb08.1233520945.git.marius@trolltech.com>
Marius Storm-Olsen <marius@trolltech.com> writes:
> string_list_find_insert_index() and string_list_insert_at_index() enables you to see if an item is in the string_list, and to insert at the appropriate index in the list, if not there.
> This is usefull if you need to manipulate an existing item, if present, and insert a new item if not.
>
> Future mailmap code will use this construct to enable complex (old_name, old_email) -> (new_name, new_email) lookups.
>
> The string_list_clear_func() allows to call a custom cleanup function on each item in a string_list, which is useful is the util member points to a complex structure.
What's with these overlong lines? You do not have them in your other
patches.
^ permalink raw reply
* Re: [PATCH] git-svn: allow disabling expensive broken symlink checks
From: Junio C Hamano @ 2009-02-02 3:03 UTC (permalink / raw)
To: Eric Wong; +Cc: git, Markus Heidelberg
In-Reply-To: <20090201021844.GB18855@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> writes:
> Since dbc6c74d0858d77e61e092a48d467e725211f8e9, git-svn has had
> an expensive check for broken symlinks that exist in some
> repositories. This leads to a heavy performance hit on
> repositories with many empty blobs that are not supposed to be
> symlinks.
>
> The workaround is enabled by default; and may be disabled via:
>
> git config svn.brokenSymlinkWorkaround false
>
> Reported by Markus Heidelberg.
>
> Signed-off-by: Eric Wong <normalperson@yhbt.net>
How common is this breakage in people's subversion repositories that
dbc6c74d (git-svn: handle empty files marked as symlinks in SVN,
2009-01-11) works around?
What's the way to recover from a broken import, when the subversion
repository does have such a breakage, and the user used git-svn that
predates dbc6c74? Is it very involved, and it is much better to have the
safety by default than to force everybody else who interacts with
non-broken subversion repository suffer from this performance penalty?
Because the fix (that is broken from the performance angle) is relatively
recent, I am wondering if it makes more sense to turn it off by default,
and allow people with such a broken history to optionally turn it on.
^ permalink raw reply
* Re: [PATCH] builtin-config: add --exec-editor for use in scripts
From: Junio C Hamano @ 2009-02-02 3:04 UTC (permalink / raw)
To: Eric Wong; +Cc: git
In-Reply-To: <20090201025349.GA22160@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> writes:
> This exposes the launch_editor() library function for use by
> various scripting languages. This allows the ensure consistent
> handling of GIT_EDITOR/VISUAL/EDITOR environment variables as
> well as the handling of special characters such as spaces in the
> various environment variables.
>
> Signed-off-by: Eric Wong <normalperson@yhbt.net>
> ---
>
> I'm not sure if git-config is the best place to stick it. I plan to
> start using this in git-svn but I don't want to implement Git::Editor
> in Perl and have to keep track of editor.c. Of course this also makes
> the logic/rules used in libgit usable to any other scripting language
> capable of launching other programs.
I agree that git-config is probably a wrong place. A separate command
"git editor" (or "git user-preference --editor", if you extend it to pager
and others) perhaps?
I also agree that something like this would make scripting Porcelains a
much pleasant experience.
^ permalink raw reply
* Re: [RFC PATCH] add -p: prompt for single characters
From: Suraj Kurapati @ 2009-02-02 3:31 UTC (permalink / raw)
To: Thomas Rast; +Cc: git, Jeff King
In-Reply-To: <1233520511-13061-1-git-send-email-trast@student.ethz.ch>
On Sun, Feb 1, 2009 at 12:35 PM, Thomas Rast <trast@student.ethz.ch> wrote:
> http://thread.gmane.org/gmane.comp.version-control.git/100146
>
> I can't find the v4 promised there, so I assume Suraj dropped it.
Yes, I lost the motivation to develop the patch any further. Sorry.
But I am glad to see you carrying the torch forward. Good luck! :)
^ permalink raw reply
* [PATCH 0/3] "add -p" enhancements
From: Junio C Hamano @ 2009-02-02 3:42 UTC (permalink / raw)
To: git; +Cc: William Pursell
I've looked at an earlier series by William Pursell to add "Find hunk"
action to "git add -p" and it was fairly trivial to resurrect. I'll be
queuing them to 'next' unless people object.
William Pursell (3):
git-add -i/-p: Change prompt separater from slash to comma
Add / command in add --patch
In add --patch, Handle K,k,J,j slightly more gracefully.
git-add--interactive.perl | 81 +++++++++++++++++++++++++++++++++------------
1 files changed, 60 insertions(+), 21 deletions(-)
^ permalink raw reply
* [PATCH 1/3] git-add -i/-p: Change prompt separater from slash to comma
From: Junio C Hamano @ 2009-02-02 3:42 UTC (permalink / raw)
To: git; +Cc: William Pursell
In-Reply-To: <1233546159-30347-1-git-send-email-gitster@pobox.com>
From: William Pursell <bill.pursell@gmail.com>
Otherwise the find command '/' soon to be introduced will be hard to see.
Signed-off-by: William Pursell <bill.pursell@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
git-add--interactive.perl | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index ca60356..ca50363 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -929,22 +929,22 @@ sub patch_update_file {
for ($i = 0; $i < $ix; $i++) {
if (!defined $hunk[$i]{USE}) {
$prev = 1;
- $other .= '/k';
+ $other .= ',k';
last;
}
}
if ($ix) {
- $other .= '/K';
+ $other .= ',K';
}
for ($i = $ix + 1; $i < $num; $i++) {
if (!defined $hunk[$i]{USE}) {
$next = 1;
- $other .= '/j';
+ $other .= ',j';
last;
}
}
if ($ix < $num - 1) {
- $other .= '/J';
+ $other .= ',J';
}
if ($num > 1) {
$other .= '/g';
@@ -958,13 +958,13 @@ sub patch_update_file {
last if (!$undecided);
if (hunk_splittable($hunk[$ix]{TEXT})) {
- $other .= '/s';
+ $other .= ',s';
}
- $other .= '/e';
+ $other .= ',e';
for (@{$hunk[$ix]{DISPLAY}}) {
print;
}
- print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? ";
+ print colored $prompt_color, "Stage this hunk [y,n,a,d$other,?]? ";
my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {
--
1.6.1.2.331.g8c4c8
^ permalink raw reply related
* [PATCH 2/3] Add / command in add --patch
From: Junio C Hamano @ 2009-02-02 3:42 UTC (permalink / raw)
To: git; +Cc: William Pursell
In-Reply-To: <1233546159-30347-2-git-send-email-gitster@pobox.com>
From: William Pursell <bill.pursell@gmail.com>
This command allows the user to skip hunks that don't match the specified
regex.
Signed-off-by: William Pursell <bill.pursell@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
git-add--interactive.perl | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index ca50363..64ad289 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -801,6 +801,7 @@ n - do not stage this hunk
a - stage this and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining hunks in the file
g - select a hunk to go to
+/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
@@ -964,7 +965,7 @@ sub patch_update_file {
for (@{$hunk[$ix]{DISPLAY}}) {
print;
}
- print colored $prompt_color, "Stage this hunk [y,n,a,d$other,?]? ";
+ print colored $prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {
@@ -1013,6 +1014,31 @@ sub patch_update_file {
}
next;
}
+ elsif ($line =~ m|^/(.*)|) {
+ my $search_string;
+ eval {
+ $search_string = qr{$1}m;
+ };
+ if ($@) {
+ my ($err,$exp) = ($@, $1);
+ $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
+ print STDERR "Malformed search regexp $exp: $err\n";
+ next;
+ }
+ my $iy = $ix;
+ while (1) {
+ my $text = join ("", @{$hunk[$iy]{TEXT}});
+ last if ($text =~ $search_string);
+ $iy++;
+ $iy = 0 if ($iy >= $num);
+ if ($ix == $iy) {
+ print STDERR "No hunk matches the given pattern\n";
+ last;
+ }
+ }
+ $ix = $iy;
+ next;
+ }
elsif ($other =~ /K/ && $line =~ /^K/) {
$ix--;
next;
--
1.6.1.2.331.g8c4c8
^ permalink raw reply related
* [PATCH 3/3] In add --patch, Handle K,k,J,j slightly more gracefully.
From: Junio C Hamano @ 2009-02-02 3:42 UTC (permalink / raw)
To: git; +Cc: William Pursell
In-Reply-To: <1233546159-30347-3-git-send-email-gitster@pobox.com>
From: William Pursell <bill.pursell@gmail.com>
Instead of printing the help menu, this will print "No next hunk" and then
process the given hunk again.
Signed-off-by: William Pursell <bill.pursell@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
git-add--interactive.perl | 43 ++++++++++++++++++++++++++++---------------
1 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 64ad289..30ddab2 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1039,29 +1039,42 @@ sub patch_update_file {
$ix = $iy;
next;
}
- elsif ($other =~ /K/ && $line =~ /^K/) {
- $ix--;
+ elsif ($line =~ /^K/) {
+ if ($other =~ /K/) {
+ $ix--;
+ }
+ else {
+ print STDERR "No previous hunk\n";
+ }
next;
}
- elsif ($other =~ /J/ && $line =~ /^J/) {
- $ix++;
+ elsif ($line =~ /^J/) {
+ if ($other =~ /J/) {
+ $ix++;
+ }
+ else {
+ print STDERR "No next hunk\n";
+ }
next;
}
- elsif ($other =~ /k/ && $line =~ /^k/) {
- while (1) {
- $ix--;
- last if (!$ix ||
- !defined $hunk[$ix]{USE});
+ elsif ($line =~ /^k/) {
+ if ($other =~ /k/) {
+ while (1) {
+ $ix--;
+ last if (!$ix ||
+ !defined $hunk[$ix]{USE});
+ }
+ }
+ else {
+ print STDERR "No previous hunk\n";
}
next;
}
- elsif ($other =~ /j/ && $line =~ /^j/) {
- while (1) {
- $ix++;
- last if ($ix >= $num ||
- !defined $hunk[$ix]{USE});
+ elsif ($line =~ /^j/) {
+ if ($other !~ /j/) {
+ print STDERR "No next hunk\n";
+ next;
}
- next;
}
elsif ($other =~ /s/ && $line =~ /^s/) {
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
--
1.6.1.2.331.g8c4c8
^ permalink raw reply related
* [PATCH] Support various HTTP authentication methods
From: Moriyoshi Koizumi @ 2009-02-02 4:09 UTC (permalink / raw)
Cc: Junio C Hamano
In-Reply-To: <7v3af2h1b0.fsf@gitster.siamese.dyndns.org>
Currently there is no way to specify the preferred authentication
method for the HTTP backend and it always falls back to the CURL's default
settings.
This patch allows users to specify the authentication method if supported
by CURL, adding a couple of new settings and environment variables
listed below (the names within the parentheses indicate the environment
variables.)
- http.auth (GIT_HTTP_AUTH)
Specifies the preferred authentication method for HTTP. This can
be a method name or the combination of those separated by comma. Valid
values are "basic", "digest", "gss" and "ntlm". You can also specify
"any" (all of the above), "anysafe" (all of the above except "basic").
Note that the strings are treated case-insensitive.
- http.proxy_auth (GIT_HTTP_PROXY_AUTH)
Specifies the preferred authentication method method for HTTP proxy.
The same thing as above applies to this setting.
Signed-off-by: Moriyoshi <mozo@mozo.jp>
---
http.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 114 insertions(+), 6 deletions(-)
diff --git a/http.c b/http.c
index ee58799..41e8e8c 100644
--- a/http.c
+++ b/http.c
@@ -13,18 +13,24 @@ static CURL *curl_default;
char curl_errorstr[CURL_ERROR_SIZE];
static int curl_ssl_verify = -1;
-static const char *ssl_cert = NULL;
+static const char *ssl_cert;
#if LIBCURL_VERSION_NUM >= 0x070902
-static const char *ssl_key = NULL;
+static const char *ssl_key;
#endif
#if LIBCURL_VERSION_NUM >= 0x070908
-static const char *ssl_capath = NULL;
+static const char *ssl_capath;
#endif
-static const char *ssl_cainfo = NULL;
+static const char *ssl_cainfo;
static long curl_low_speed_limit = -1;
static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv = 0;
-static const char *curl_http_proxy = NULL;
+static const char *curl_http_proxy;
+#if LIBCURL_VERSION_NUM >= 0x070a06
+static const char *curl_http_auth;
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070a07
+static const char *curl_http_proxy_auth;
+#endif
static struct curl_slist *pragma_header;
@@ -153,11 +159,69 @@ static int http_options(const char *var, const char *value, void *cb)
return git_config_string(&curl_http_proxy, var, value);
return 0;
}
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (!strcmp("http.auth", var)) {
+ if (curl_http_auth == NULL)
+ return git_config_string(&curl_http_auth, var, value);
+ return 0;
+ }
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (!strcmp("http.proxy_auth", var)) {
+ if (curl_http_proxy_auth == NULL)
+ return git_config_string(&curl_http_proxy_auth, var, value);
+ return 0;
+ }
+#endif
/* Fall back on the default ones */
return git_default_config(var, value, cb);
}
+#if LIBCURL_VERSION_NUM >= 0x070a06
+static long get_curl_auth_bitmask(const char* auth_method)
+{
+ char buf[4096];
+ const unsigned char *p = (const unsigned char *)auth_method;
+ long mask = CURLAUTH_NONE;
+
+ strlcpy(buf, auth_method, sizeof(buf));
+
+ for (;;) {
+ char *q = buf;
+ while (*p && isspace(*p))
+ ++p;
+
+ while (*p && *p != ',')
+ *q++ = tolower(*p++);
+
+ while (--q >= buf && isspace(*q));
+ ++q;
+
+ *q = '\0';
+
+ if (!strcmp(buf, "basic"))
+ mask |= CURLAUTH_BASIC;
+ else if (!strcmp(buf, "digest"))
+ mask |= CURLAUTH_DIGEST;
+ else if (!strcmp(buf, "gss"))
+ mask |= CURLAUTH_GSSNEGOTIATE;
+ else if (!strcmp(buf, "ntlm"))
+ mask |= CURLAUTH_NTLM;
+ else if (!strcmp(buf, "any"))
+ mask |= CURLAUTH_ANY;
+ else if (!strcmp(buf, "anysafe"))
+ mask |= CURLAUTH_ANYSAFE;
+
+ if (!*p)
+ break;
+ ++p;
+ }
+
+ return mask;
+}
+#endif
+
static CURL* get_curl_handle(void)
{
CURL* result = curl_easy_init();
@@ -207,9 +271,24 @@ static CURL* get_curl_handle(void)
if (curl_ftp_no_epsv)
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
- if (curl_http_proxy)
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (curl_http_auth) {
+ long n = get_curl_auth_bitmask(curl_http_auth);
+ curl_easy_setopt(result, CURLOPT_HTTPAUTH, n);
+ }
+#endif
+
+ if (curl_http_proxy) {
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (curl_http_proxy_auth) {
+ long n = get_curl_auth_bitmask(curl_http_proxy_auth);
+ curl_easy_setopt(result, CURLOPT_PROXYAUTH, n);
+ }
+#endif
+ }
+
return result;
}
@@ -258,6 +337,21 @@ void http_init(struct remote *remote)
if (low_speed_time != NULL)
curl_low_speed_time = strtol(low_speed_time, NULL, 10);
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ {
+ char *http_auth = getenv("GIT_HTTP_AUTH");
+ if (http_auth)
+ curl_http_auth = xstrdup(http_auth);
+ }
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ {
+ char *http_proxy_auth = getenv("GIT_HTTP_PROXY_AUTH");
+ if (http_proxy_auth)
+ curl_http_proxy_auth = xstrdup(http_proxy_auth);
+ }
+#endif
+
git_config(http_options, NULL);
if (curl_ssl_verify == -1)
@@ -309,6 +403,20 @@ void http_cleanup(void)
free((void *)curl_http_proxy);
curl_http_proxy = NULL;
}
+
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (curl_http_auth) {
+ free((void *)curl_http_auth);
+ curl_http_auth = NULL;
+ }
+#endif
+
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (curl_http_proxy_auth) {
+ free((void *)curl_http_proxy_auth);
+ curl_http_proxy_auth = NULL;
+ }
+#endif
}
struct active_request_slot *get_active_slot(void)
--
1.5.6.3
^ permalink raw reply related
* [PATCH 2/4] builtin-replace: teach "git replace" to actually replace
From: Christian Couder @ 2009-02-02 5:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Teach the syntax: "git replace <object> <replacement>", so that
"git replace" can now create replace refs. These replace refs
will be used by read_sha1_file to substitute <object> with
<replacement> for most of the commands.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-replace.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
t/t6050-replace.sh | 10 ++++++++++
2 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/builtin-replace.c b/builtin-replace.c
index b5c40aa..e3767b9 100644
--- a/builtin-replace.c
+++ b/builtin-replace.c
@@ -14,6 +14,7 @@
#include "parse-options.h"
static const char * const git_replace_usage[] = {
+ "git replace [-f] <object> <replacement>",
"git replace -d <object>...",
"git replace -l [<pattern>]",
NULL
@@ -77,12 +78,46 @@ static int delete_replace_ref(const char *name, const char *ref,
return 0;
}
+static int replace_object(const char *object_ref, const char *replace_ref,
+ int force)
+{
+ unsigned char object[20], prev[20], repl[20];
+ char ref[PATH_MAX];
+ struct ref_lock *lock;
+
+ if (get_sha1(object_ref, object))
+ die("Failed to resolve '%s' as a valid ref.", object_ref);
+ if (get_sha1(replace_ref, repl))
+ die("Failed to resolve '%s' as a valid ref.", replace_ref);
+
+ if (snprintf(ref, sizeof(ref),
+ "refs/replace/%s",
+ sha1_to_hex(object)) > sizeof(ref) - 1)
+ die("replace ref name too long: %.*s...", 50, ref);
+ if (check_ref_format(ref))
+ die("'%s' is not a valid ref name.", ref);
+
+ if (!resolve_ref(ref, prev, 1, NULL))
+ hashclr(prev);
+ else if (!force)
+ die("replace ref '%s' already exists", ref);
+
+ lock = lock_any_ref_for_update(ref, prev, 0);
+ if (!lock)
+ die("%s: cannot lock the ref", ref);
+ if (write_ref_sha1(lock, repl, NULL) < 0)
+ die("%s: cannot update the ref", ref);
+
+ return 0;
+}
+
int cmd_replace(int argc, const char **argv, const char *prefix)
{
- int list = 0, delete = 0;
+ int list = 0, delete = 0, force = 0;
struct option options[] = {
OPT_BOOLEAN('l', NULL, &list, "list replace refs"),
OPT_BOOLEAN('d', NULL, &delete, "delete replace refs"),
+ OPT_BOOLEAN('f', NULL, &force, "replace the ref if it exists"),
OPT_END()
};
@@ -91,15 +126,28 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
if (list && delete)
usage_with_options(git_replace_usage, options);
+ if (force && (list || delete))
+ usage_with_options(git_replace_usage, options);
+
+ /* Delete refs */
if (delete) {
if (argc < 1)
usage_with_options(git_replace_usage, options);
return for_each_replace_name(argv, delete_replace_ref);
}
+ /* Replace object */
+ if (!list && argc) {
+ if (argc != 2)
+ usage_with_options(git_replace_usage, options);
+ return replace_object(argv[0], argv[1], force);
+ }
+
/* List refs, even if "list" is not set */
if (argc > 1)
usage_with_options(git_replace_usage, options);
+ if (force)
+ usage_with_options(git_replace_usage, options);
return list_replace_refs(argv[0]);
}
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index bf4c93f..448a19a 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -114,9 +114,19 @@ test_expect_success '"git replace" listing and deleting' '
test_must_fail git replace -d &&
test_must_fail git replace -l -d $HASH2 &&
git replace -d $HASH2 &&
+ git show $HASH2 | grep "A U Thor" &&
test -z "$(git replace -l)"
'
+test_expect_success '"git replace" replacing' '
+ git replace $HASH2 $R &&
+ git show $HASH2 | grep "O Thor" &&
+ test_must_fail git replace $HASH2 $R &&
+ git replace -f $HASH2 $R &&
+ test_must_fail git replace -f &&
+ test "$HASH2" = "$(git replace)"
+'
+
#
#
test_done
--
1.6.1.2.353.g99fdd.dirty
^ permalink raw reply related
* [PATCH 1/4] Add new "git replace" command
From: Christian Couder @ 2009-02-02 5:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This command can only be used now to list replace refs in
"refs/replace/" and to delete them.
The option to list replace refs is "-l".
The option to delete replace refs is "-d".
The behavior should be consistent with how "git tag" and "git branch"
are working.
The code has been copied from "builtin-tag.c" by Kristian Høgsberg
<krh@redhat.com> and Carlos Rica <jasampler@gmail.com> that was itself
based on git-tag.sh and mktag.c by Linus Torvalds.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Makefile | 1 +
builtin-replace.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++
builtin.h | 1 +
git.c | 1 +
t/t6050-replace.sh | 12 ++++++
5 files changed, 120 insertions(+), 0 deletions(-)
create mode 100644 builtin-replace.c
This patch series comes on top of my previous "replace" series in pu.
It should make it easier to test and use the previous code.
But there is no documentation yet for the new "git replace" command
introduced in this series.
diff --git a/Makefile b/Makefile
index 9f91013..ee28569 100644
--- a/Makefile
+++ b/Makefile
@@ -570,6 +570,7 @@ BUILTIN_OBJS += builtin-read-tree.o
BUILTIN_OBJS += builtin-receive-pack.o
BUILTIN_OBJS += builtin-reflog.o
BUILTIN_OBJS += builtin-remote.o
+BUILTIN_OBJS += builtin-replace.o
BUILTIN_OBJS += builtin-rerere.o
BUILTIN_OBJS += builtin-reset.o
BUILTIN_OBJS += builtin-rev-list.o
diff --git a/builtin-replace.c b/builtin-replace.c
new file mode 100644
index 0000000..b5c40aa
--- /dev/null
+++ b/builtin-replace.c
@@ -0,0 +1,105 @@
+/*
+ * Builtin "git replace"
+ *
+ * Copyright (c) 2008 Christian Couder <chriscool@tuxfamily.org>
+ *
+ * Based on builtin-tag.c by Kristian Høgsberg <krh@redhat.com>
+ * and Carlos Rica <jasampler@gmail.com> that was itself based on
+ * git-tag.sh and mktag.c by Linus Torvalds.
+ */
+
+#include "cache.h"
+#include "builtin.h"
+#include "refs.h"
+#include "parse-options.h"
+
+static const char * const git_replace_usage[] = {
+ "git replace -d <object>...",
+ "git replace -l [<pattern>]",
+ NULL
+};
+
+static int show_reference(const char *refname, const unsigned char *sha1,
+ int flag, void *cb_data)
+{
+ const char *pattern = cb_data;
+
+ if (!fnmatch(pattern, refname, 0))
+ printf("%s\n", refname);
+
+ return 0;
+}
+
+static int list_replace_refs(const char *pattern)
+{
+ if (pattern == NULL)
+ pattern = "*";
+
+ for_each_replace_ref(show_reference, (void *) pattern);
+
+ return 0;
+}
+
+typedef int (*each_replace_name_fn)(const char *name, const char *ref,
+ const unsigned char *sha1);
+
+static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
+{
+ const char **p;
+ char ref[PATH_MAX];
+ int had_error = 0;
+ unsigned char sha1[20];
+
+ for (p = argv; *p; p++) {
+ if (snprintf(ref, sizeof(ref), "refs/replace/%s", *p)
+ >= sizeof(ref)) {
+ error("replace ref name too long: %.*s...", 50, *p);
+ had_error = 1;
+ continue;
+ }
+ if (!resolve_ref(ref, sha1, 1, NULL)) {
+ error("replace ref '%s' not found.", *p);
+ had_error = 1;
+ continue;
+ }
+ if (fn(*p, ref, sha1))
+ had_error = 1;
+ }
+ return had_error;
+}
+
+static int delete_replace_ref(const char *name, const char *ref,
+ const unsigned char *sha1)
+{
+ if (delete_ref(ref, sha1, 0))
+ return 1;
+ printf("Deleted replace ref '%s'\n", name);
+ return 0;
+}
+
+int cmd_replace(int argc, const char **argv, const char *prefix)
+{
+ int list = 0, delete = 0;
+ struct option options[] = {
+ OPT_BOOLEAN('l', NULL, &list, "list replace refs"),
+ OPT_BOOLEAN('d', NULL, &delete, "delete replace refs"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, git_replace_usage, 0);
+
+ if (list && delete)
+ usage_with_options(git_replace_usage, options);
+
+ if (delete) {
+ if (argc < 1)
+ usage_with_options(git_replace_usage, options);
+ return for_each_replace_name(argv, delete_replace_ref);
+ }
+
+ /* List refs, even if "list" is not set */
+ if (argc > 1)
+ usage_with_options(git_replace_usage, options);
+
+ return list_replace_refs(argv[0]);
+}
diff --git a/builtin.h b/builtin.h
index 1495cf6..70c5daf 100644
--- a/builtin.h
+++ b/builtin.h
@@ -110,5 +110,6 @@ extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
extern int cmd_verify_pack(int argc, const char **argv, const char *prefix);
extern int cmd_show_ref(int argc, const char **argv, const char *prefix);
extern int cmd_pack_refs(int argc, const char **argv, const char *prefix);
+extern int cmd_replace(int argc, const char **argv, const char *prefix);
#endif
diff --git a/git.c b/git.c
index c2b181e..92d47b0 100644
--- a/git.c
+++ b/git.c
@@ -335,6 +335,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "receive-pack", cmd_receive_pack },
{ "reflog", cmd_reflog, RUN_SETUP },
{ "remote", cmd_remote, RUN_SETUP },
+ { "replace", cmd_replace, RUN_SETUP },
{ "repo-config", cmd_config },
{ "rerere", cmd_rerere, RUN_SETUP },
{ "reset", cmd_reset, RUN_SETUP },
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 17f6063..bf4c93f 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -105,6 +105,18 @@ test_expect_success 'repack, clone and fetch work' '
cd ..
'
+test_expect_success '"git replace" listing and deleting' '
+ test "$HASH2" = "$(git replace -l)" &&
+ test "$HASH2" = "$(git replace)" &&
+ aa=${HASH2%??????????????????????????????????????} &&
+ test "$HASH2" = "$(git replace -l "$aa*")" &&
+ test_must_fail git replace -d $R &&
+ test_must_fail git replace -d &&
+ test_must_fail git replace -l -d $HASH2 &&
+ git replace -d $HASH2 &&
+ test -z "$(git replace -l)"
+'
+
#
#
test_done
--
1.6.1.2.353.g99fdd.dirty
^ permalink raw reply related
* [PATCH 3/4] parse-options: add new function "usage_msg_opt"
From: Christian Couder @ 2009-02-02 5:12 UTC (permalink / raw)
To: Junio C Hamano, Pierre Habouzit; +Cc: git
This function can be used instead of "usage_with_options" when you
want to print an error message before the usage string.
It may be useful because:
if (condition)
usage_msg_opt("condition is false", usage, opts);
is shorter than:
if (condition) {
fprintf(stderr, "condition is false\n\n");
usage_with_options(usage, opts);
}
and may be more consistent.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
parse-options.c | 8 ++++++++
parse-options.h | 4 ++++
2 files changed, 12 insertions(+), 0 deletions(-)
This patch may be generaly useful.
diff --git a/parse-options.c b/parse-options.c
index 4c5d09d..7a5fde8 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -449,6 +449,14 @@ void usage_with_options(const char * const *usagestr,
exit(129);
}
+void usage_msg_opt(const char *msg,
+ const char * const *usagestr,
+ const struct option *options)
+{
+ fprintf(stderr, "%s\n\n", msg);
+ usage_with_options(usagestr, options);
+}
+
int parse_options_usage(const char * const *usagestr,
const struct option *opts)
{
diff --git a/parse-options.h b/parse-options.h
index 9122905..6061a19 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -113,6 +113,10 @@ extern int parse_options(int argc, const char **argv,
extern NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);
+extern NORETURN void usage_msg_opt(const char *msg,
+ const char * const *usagestr,
+ const struct option *options);
+
/*----- incremantal advanced APIs -----*/
enum {
--
1.6.1.2.353.g99fdd.dirty
^ permalink raw reply related
* [PATCH 4/4] builtin-replace: use "usage_msg_opt" to give better error messages
From: Christian Couder @ 2009-02-02 5:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-replace.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/builtin-replace.c b/builtin-replace.c
index e3767b9..b15f709 100644
--- a/builtin-replace.c
+++ b/builtin-replace.c
@@ -124,30 +124,36 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, options, git_replace_usage, 0);
if (list && delete)
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("-l and -d cannot be used together",
+ git_replace_usage, options);
if (force && (list || delete))
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("-f cannot be used with -d or -l",
+ git_replace_usage, options);
/* Delete refs */
if (delete) {
if (argc < 1)
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("-d needs at least one argument",
+ git_replace_usage, options);
return for_each_replace_name(argv, delete_replace_ref);
}
/* Replace object */
if (!list && argc) {
if (argc != 2)
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("bad number of arguments",
+ git_replace_usage, options);
return replace_object(argv[0], argv[1], force);
}
/* List refs, even if "list" is not set */
if (argc > 1)
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("only one pattern can be given with -l",
+ git_replace_usage, options);
if (force)
- usage_with_options(git_replace_usage, options);
+ usage_msg_opt("-f needs some arguments",
+ git_replace_usage, options);
return list_replace_refs(argv[0]);
}
--
1.6.1.2.353.g99fdd.dirty
^ permalink raw reply related
* Re: [PATCH v2 0/4] Extend mailmap functionality
From: Sverre Rabbelier @ 2009-02-02 5:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Marius Storm-Olsen, git
In-Reply-To: <7vpri1o801.fsf@gitster.siamese.dyndns.org>
On Mon, Feb 2, 2009 at 04:03, Junio C Hamano <gitster@pobox.com> wrote:
> The new mapping however brings in more flexibility, and there may be other
> use cases where people benefit from that flexibility. I am slightly in
> favor than neutral to this new feature.
It sure does, I use git-svn for a project hosted on Google Code, and
the e-mail addresses are totally borked (e.g., "gmail-account-id"
<gmail-account-id@the-svn-repo-uuid>). Not only that, but some
developers (including me I must admit) have a rather obscure
gmail-account-id, which is uses as the user's name for the commit
message. It would be very nice if I could provide a mapping from
"borked svn id's" to "normal, sensible e-mail addresses, including
real names", a feature which this series seems to add :).
--
Cheers,
Sverre Rabbelier
^ permalink raw reply
* Re: [PATCH] Support various HTTP authentication methods
From: Junio C Hamano @ 2009-02-02 6:31 UTC (permalink / raw)
To: git; +Cc: Moriyoshi Koizumi
In-Reply-To: <E1LTqDN-0003MF-DP@lena.gsc.riken.jp>
Moriyoshi Koizumi <mozo@mozo.jp> writes:
> diff --git a/http.c b/http.c
> index ee58799..41e8e8c 100644
> --- a/http.c
> +++ b/http.c
> @@ -13,18 +13,24 @@ static CURL *curl_default;
> char curl_errorstr[CURL_ERROR_SIZE];
>
> static int curl_ssl_verify = -1;
> -static const char *ssl_cert = NULL;
> +static const char *ssl_cert;
> #if LIBCURL_VERSION_NUM >= 0x070902
> -static const char *ssl_key = NULL;
> +static const char *ssl_key;
> #endif
> #if LIBCURL_VERSION_NUM >= 0x070908
> -static const char *ssl_capath = NULL;
> +static const char *ssl_capath;
> #endif
> -static const char *ssl_cainfo = NULL;
> +static const char *ssl_cainfo;
> static long curl_low_speed_limit = -1;
> static long curl_low_speed_time = -1;
> static int curl_ftp_no_epsv = 0;
> -static const char *curl_http_proxy = NULL;
> +static const char *curl_http_proxy;
Applying style fixes to the existing code is very much appreciated, *but*
please make such a clean-up patch a separate one. A two-patch series
whose [1/2] is such a pure clean-up without any feature change, with [2/2]
that adds code to the cleaned-up state would be much less distracting for
people who nitpick your changes.
> @@ -153,11 +159,69 @@ static int http_options(const char *var, const char *value, void *cb)
> return git_config_string(&curl_http_proxy, var, value);
> return 0;
> }
> +#if LIBCURL_VERSION_NUM >= 0x070a06
> + if (!strcmp("http.auth", var)) {
> + if (curl_http_auth == NULL)
> + return git_config_string(&curl_http_auth, var, value);
> + return 0;
> + }
> +#endif
> +#if LIBCURL_VERSION_NUM >= 0x070a07
> + if (!strcmp("http.proxy_auth", var)) {
> + if (curl_http_proxy_auth == NULL)
> + return git_config_string(&curl_http_proxy_auth, var, value);
> + return 0;
> + }
> +#endif
If you follow config.c::git_config() you will notice that we read from
/etc/gitconfig, $HOME/.gitconfig and then finally $GIT_DIR/config. By
implementing "if we already have read curl_http_auth already, we will
ignore the later setting" like above code does, you break the general
expectation that system-wide defaults is overridable by $HOME/.gitconfig
and that is in turn overridable by per-repository $GIT_DIR/config.
The preferred order would be:
- Use the value obtained from command line parameters, if any;
- Otherwise, if an environment variable is there, use it;
- Otherwise, the value obtained from git_config(), with "later one wins"
rule.
I think you are not adding any command line option, so favoring
environment and then using configuration is fine, but the configuration
parser must follow the usual "later one wins" rule to avoid dissapointing
the users.
> +#if LIBCURL_VERSION_NUM >= 0x070a06
> +static long get_curl_auth_bitmask(const char* auth_method)
In git codebase, asterisk that means "a pointer" sticks to the variable
name not to type name; "const char *auth_method" (I see this file is
already infested with such style violations, but if you are doing a
separate clean-up patch it would be appreciated to clean them up).
> +{
> + char buf[4096];
Do you need that much space?
> + const unsigned char *p = (const unsigned char *)auth_method;
> + long mask = CURLAUTH_NONE;
> +
> + strlcpy(buf, auth_method, sizeof(buf));
A tab is 8-char wide.
What happens when auth_method is longer than 4kB?
> +
> + for (;;) {
> + char *q = buf;
> + while (*p && isspace(*p))
> + ++p;
If there is no particular reason to choose one over the other, please use
postincrement, p++, as other existing parts of the codebase.
I'll try to demonstrate what (I think) this patch should look like as a
pair of follow-up messages to this one, but I am not sure about my rewrite
of get_curl_auth_bitmask(). Please consider it as an easter-egg bughunt
;-)
^ permalink raw reply
* Re: [PATCH] Support various HTTP authentication methods
From: Junio C Hamano @ 2009-02-02 6:31 UTC (permalink / raw)
To: git; +Cc: Moriyoshi Koizumi
In-Reply-To: <1233556274-1354-1-git-send-email-gitster@pobox.com>
Moriyoshi Koizumi <mozo@mozo.jp> writes:
> diff --git a/http.c b/http.c
> index ee58799..41e8e8c 100644
> --- a/http.c
> +++ b/http.c
> @@ -13,18 +13,24 @@ static CURL *curl_default;
> char curl_errorstr[CURL_ERROR_SIZE];
>
> static int curl_ssl_verify = -1;
> -static const char *ssl_cert = NULL;
> +static const char *ssl_cert;
> #if LIBCURL_VERSION_NUM >= 0x070902
> -static const char *ssl_key = NULL;
> +static const char *ssl_key;
> #endif
> #if LIBCURL_VERSION_NUM >= 0x070908
> -static const char *ssl_capath = NULL;
> +static const char *ssl_capath;
> #endif
> -static const char *ssl_cainfo = NULL;
> +static const char *ssl_cainfo;
> static long curl_low_speed_limit = -1;
> static long curl_low_speed_time = -1;
> static int curl_ftp_no_epsv = 0;
> -static const char *curl_http_proxy = NULL;
> +static const char *curl_http_proxy;
Applying style fixes to the existing code is very much appreciated, *but*
please make such a clean-up patch a separate one. A two-patch series
whose [1/2] is such a pure clean-up without any feature change, with [2/2]
that adds code to the cleaned-up state would be much less distracting for
people who nitpick your changes.
> @@ -153,11 +159,69 @@ static int http_options(const char *var, const char *value, void *cb)
> return git_config_string(&curl_http_proxy, var, value);
> return 0;
> }
> +#if LIBCURL_VERSION_NUM >= 0x070a06
> + if (!strcmp("http.auth", var)) {
> + if (curl_http_auth == NULL)
> + return git_config_string(&curl_http_auth, var, value);
> + return 0;
> + }
> +#endif
> +#if LIBCURL_VERSION_NUM >= 0x070a07
> + if (!strcmp("http.proxy_auth", var)) {
> + if (curl_http_proxy_auth == NULL)
> + return git_config_string(&curl_http_proxy_auth, var, value);
> + return 0;
> + }
> +#endif
If you follow config.c::git_config() you will notice that we read from
/etc/gitconfig, $HOME/.gitconfig and then finally $GIT_DIR/config. By
implementing "if we already have read curl_http_auth already, we will
ignore the later setting" like above code does, you break the general
expectation that system-wide defaults is overridable by $HOME/.gitconfig
and that is in turn overridable by per-repository $GIT_DIR/config.
The preferred order would be:
- Use the value obtained from command line parameters, if any;
- Otherwise, if an environment variable is there, use it;
- Otherwise, the value obtained from git_config(), with "later one wins"
rule.
I think you are not adding any command line option, so favoring
environment and then using configuration is fine, but the configuration
parser must follow the usual "later one wins" rule to avoid dissapointing
the users.
> +#if LIBCURL_VERSION_NUM >= 0x070a06
> +static long get_curl_auth_bitmask(const char* auth_method)
In git codebase, asterisk that means "a pointer" sticks to the variable
name not to type name; "const char *auth_method" (I see this file is
already infested with such style violations, but if you are doing a
separate clean-up patch it would be appreciated to clean them up).
> +{
> + char buf[4096];
Do you need that much space?
> + const unsigned char *p = (const unsigned char *)auth_method;
> + long mask = CURLAUTH_NONE;
> +
> + strlcpy(buf, auth_method, sizeof(buf));
A tab is 8-char wide.
What happens when auth_method is longer than 4kB?
> +
> + for (;;) {
> + char *q = buf;
> + while (*p && isspace(*p))
> + ++p;
If there is no particular reason to choose one over the other, please use
postincrement, p++, as other existing parts of the codebase.
I'll try to demonstrate what (I think) this patch should look like as a
pair of follow-up messages to this one, but I am not sure about my rewrite
of get_curl_auth_bitmask(). Please consider it as an easter-egg bughunt
;-)
^ permalink raw reply
* [PATCH 1/2] http.c: fix various style violations
From: Junio C Hamano @ 2009-02-02 6:31 UTC (permalink / raw)
To: git; +Cc: Moriyoshi Koizumi
In-Reply-To: <1233556274-1354-2-git-send-email-gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
http.c | 46 +++++++++++++++++++++-------------------------
1 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/http.c b/http.c
index ee58799..86be906 100644
--- a/http.c
+++ b/http.c
@@ -1,7 +1,7 @@
#include "http.h"
int data_received;
-int active_requests = 0;
+int active_requests;
#ifdef USE_CURL_MULTI
static int max_requests = -1;
@@ -13,22 +13,22 @@ static CURL *curl_default;
char curl_errorstr[CURL_ERROR_SIZE];
static int curl_ssl_verify = -1;
-static const char *ssl_cert = NULL;
+static const char *ssl_cert;
#if LIBCURL_VERSION_NUM >= 0x070902
-static const char *ssl_key = NULL;
+static const char *ssl_key;
#endif
#if LIBCURL_VERSION_NUM >= 0x070908
-static const char *ssl_capath = NULL;
+static const char *ssl_capath;
#endif
-static const char *ssl_cainfo = NULL;
+static const char *ssl_cainfo;
static long curl_low_speed_limit = -1;
static long curl_low_speed_time = -1;
-static int curl_ftp_no_epsv = 0;
-static const char *curl_http_proxy = NULL;
+static int curl_ftp_no_epsv;
+static const char *curl_http_proxy;
static struct curl_slist *pragma_header;
-static struct active_request_slot *active_queue_head = NULL;
+static struct active_request_slot *active_queue_head;
size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
{
@@ -94,9 +94,8 @@ static void process_curl_messages(void)
static int http_options(const char *var, const char *value, void *cb)
{
if (!strcmp("http.sslverify", var)) {
- if (curl_ssl_verify == -1) {
+ if (curl_ssl_verify == -1)
curl_ssl_verify = git_config_bool(var, value);
- }
return 0;
}
@@ -158,9 +157,9 @@ static int http_options(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
-static CURL* get_curl_handle(void)
+static CURL *get_curl_handle(void)
{
- CURL* result = curl_easy_init();
+ CURL *result = curl_easy_init();
if (!curl_ssl_verify) {
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);
@@ -322,15 +321,13 @@ struct active_request_slot *get_active_slot(void)
/* Wait for a slot to open up if the queue is full */
while (active_requests >= max_requests) {
curl_multi_perform(curlm, &num_transfers);
- if (num_transfers < active_requests) {
+ if (num_transfers < active_requests)
process_curl_messages();
- }
}
#endif
- while (slot != NULL && slot->in_use) {
+ while (slot != NULL && slot->in_use)
slot = slot->next;
- }
if (slot == NULL) {
newslot = xmalloc(sizeof(*newslot));
newslot->curl = NULL;
@@ -341,9 +338,8 @@ struct active_request_slot *get_active_slot(void)
if (slot == NULL) {
active_queue_head = newslot;
} else {
- while (slot->next != NULL) {
+ while (slot->next != NULL)
slot = slot->next;
- }
slot->next = newslot;
}
slot = newslot;
@@ -404,7 +400,7 @@ struct fill_chain {
struct fill_chain *next;
};
-static struct fill_chain *fill_cfg = NULL;
+static struct fill_chain *fill_cfg;
void add_fill_function(void *data, int (*fill)(void *))
{
@@ -535,9 +531,8 @@ static void finish_active_slot(struct active_request_slot *slot)
}
/* Run callback if appropriate */
- if (slot->callback_func != NULL) {
+ if (slot->callback_func != NULL)
slot->callback_func(slot->callback_data);
- }
}
void finish_all_active_slots(void)
@@ -567,8 +562,10 @@ static inline int needs_quote(int ch)
static inline int hex(int v)
{
- if (v < 10) return '0' + v;
- else return 'A' + v - 10;
+ if (v < 10)
+ return '0' + v;
+ else
+ return 'A' + v - 10;
}
static char *quote_ref_url(const char *base, const char *ref)
@@ -591,8 +588,7 @@ static char *quote_ref_url(const char *base, const char *ref)
*dp++ = '%';
*dp++ = hex((ch >> 4) & 0xF);
*dp++ = hex(ch & 0xF);
- }
- else
+ } else
*dp++ = ch;
}
*dp = 0;
--
1.6.1.2.333.ged98f
^ permalink raw reply related
* [PATCH 2/2] Support various HTTP authentication methods
From: Junio C Hamano @ 2009-02-02 6:31 UTC (permalink / raw)
To: git; +Cc: Moriyoshi Koizumi
In-Reply-To: <1233556274-1354-3-git-send-email-gitster@pobox.com>
From: Moriyoshi Koizumi <mozo@mozo.jp>
Currently there is no way to specify the preferred authentication
method for the HTTP backend and it always falls back to the CURL's default
settings.
This patch allows users to specify the authentication method if supported
by CURL, adding a couple of new settings and environment variables
listed below (the names within the parentheses indicate the environment
variables.)
- http.auth (GIT_HTTP_AUTH)
Specifies the preferred authentication method for HTTP. This can
be a method name or the combination of those separated by comma. Valid
values are "basic", "digest", "gss" and "ntlm". You can also specify
"any" (all of the above), "anysafe" (all of the above except "basic").
Note that the strings are treated case-insensitive.
- http.proxy_auth (GIT_HTTP_PROXY_AUTH)
Specifies the preferred authentication method method for HTTP proxy.
The same thing as above applies to this setting.
Signed-off-by: Moriyoshi Koizumi <mozo@mozo.jp>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
http.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 127 insertions(+), 1 deletions(-)
diff --git a/http.c b/http.c
index 86be906..7eb849b 100644
--- a/http.c
+++ b/http.c
@@ -25,6 +25,14 @@ static long curl_low_speed_limit = -1;
static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv;
static const char *curl_http_proxy;
+#if LIBCURL_VERSION_NUM >= 0x070a06
+static const char *curl_http_auth;
+static long http_auth_bitmask;
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070a07
+static const char *curl_http_proxy_auth;
+static long http_proxy_auth_bitmask;
+#endif
static struct curl_slist *pragma_header;
@@ -152,11 +160,78 @@ static int http_options(const char *var, const char *value, void *cb)
return git_config_string(&curl_http_proxy, var, value);
return 0;
}
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (!strcmp("http.auth", var)) {
+ if (curl_http_auth == NULL)
+ return git_config_string(&curl_http_auth, var, value);
+ return 0;
+ }
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (!strcmp("http.proxy_auth", var)) {
+ if (curl_http_proxy_auth == NULL)
+ return git_config_string(&curl_http_proxy_auth, var, value);
+ return 0;
+ }
+#endif
/* Fall back on the default ones */
return git_default_config(var, value, cb);
}
+#if LIBCURL_VERSION_NUM >= 0x070a06
+#define is_delim(x) (isspace(x) || x == ',')
+
+static long get_curl_auth_bitmask(const char *auth_method)
+{
+ char buf[20];
+ const unsigned char *p = (const unsigned char *)auth_method;
+ long mask = CURLAUTH_NONE;
+
+ for (;;) {
+ char *q = buf;
+ int toolong = 0;
+
+ while (*p && is_delim(*p))
+ p++;
+ if (!*p)
+ break;
+
+ while (*p && !is_delim(*p)) {
+ if (q < buf + sizeof(buf) - 1)
+ *q++ = tolower(*p);
+ else
+ toolong = 1;
+ p++;
+ }
+ if (toolong)
+ continue;
+
+ while (--q >= buf && is_delim(*q))
+ ;
+ q++;
+ *q = '\0';
+
+ if (!strcmp(buf, "basic"))
+ mask |= CURLAUTH_BASIC;
+ else if (!strcmp(buf, "digest"))
+ mask |= CURLAUTH_DIGEST;
+ else if (!strcmp(buf, "gss"))
+ mask |= CURLAUTH_GSSNEGOTIATE;
+ else if (!strcmp(buf, "ntlm"))
+ mask |= CURLAUTH_NTLM;
+ else if (!strcmp(buf, "any"))
+ mask |= CURLAUTH_ANY;
+ else if (!strcmp(buf, "anysafe"))
+ mask |= CURLAUTH_ANYSAFE;
+ p++;
+ }
+
+ return mask;
+}
+#undef is_delim
+#endif
+
static CURL *get_curl_handle(void)
{
CURL *result = curl_easy_init();
@@ -206,12 +281,48 @@ static CURL *get_curl_handle(void)
if (curl_ftp_no_epsv)
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
- if (curl_http_proxy)
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (curl_http_auth)
+ curl_easy_setopt(result, CURLOPT_HTTPAUTH,
+ http_auth_bitmask);
+#endif
+
+ if (curl_http_proxy) {
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (curl_http_proxy_auth)
+ curl_easy_setopt(result, CURLOPT_PROXYAUTH,
+ http_proxy_auth_bitmask);
+#endif
+ }
return result;
}
+static void prepare_http_auth_settings(void)
+{
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ char *val;
+
+ val = getenv("GIT_HTTP_AUTH");
+ if (val)
+ curl_http_auth = val;
+
+ if (curl_http_auth) {
+ http_auth_bitmask = get_curl_auth_bitmask(curl_http_auth);
+ }
+
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ val = getenv("GIT_HTTP_PROXY_AUTH");
+ if (val)
+ curl_http_proxy_auth = val;
+ if (curl_http_proxy_auth) {
+ http_proxy_auth_bitmask = get_curl_auth_bitmask(curl_http_proxy_auth);
+ }
+#endif
+#endif
+}
+
void http_init(struct remote *remote)
{
char *low_speed_limit;
@@ -258,6 +369,7 @@ void http_init(struct remote *remote)
curl_low_speed_time = strtol(low_speed_time, NULL, 10);
git_config(http_options, NULL);
+ prepare_http_auth_settings();
if (curl_ssl_verify == -1)
curl_ssl_verify = 1;
@@ -308,6 +420,20 @@ void http_cleanup(void)
free((void *)curl_http_proxy);
curl_http_proxy = NULL;
}
+
+#if LIBCURL_VERSION_NUM >= 0x070a06
+ if (curl_http_auth) {
+ free((void *)curl_http_auth);
+ curl_http_auth = NULL;
+ }
+#endif
+
+#if LIBCURL_VERSION_NUM >= 0x070a07
+ if (curl_http_proxy_auth) {
+ free((void *)curl_http_proxy_auth);
+ curl_http_proxy_auth = NULL;
+ }
+#endif
}
struct active_request_slot *get_active_slot(void)
--
1.6.1.2.333.ged98f
^ permalink raw reply related
* Re: [PATCH] builtin-blame.c: Use utf8_strwidth for author's names
From: Junio C Hamano @ 2009-02-02 6:48 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Geoffrey Thomas, git
In-Reply-To: <alpine.DEB.1.00.0902012333060.3586@pacific.mpi-cbg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> On Fri, 30 Jan 2009, Geoffrey Thomas wrote:
>
>> Currently, however, printf("%*.*s", width, width, author) is simply
>> wrong, because printf only cares about bytes, not screen columns. Do you
>> think I should fall back on the old behavior if i18n.commitencoding is
>> set, or if at least one of the author names isn't parseable as UTF-8, or
>> something? Or should I be doing this with iconv and assuming all commits
>> are encoded in the current encoding specified via $LANG or $LC_whatever?
>
> I do not know what encoding the author is at that point, but if you cannot
> be sure that it is UTF-8, using utf8_strwidth() is just as wrong as the
> current code, IMHO.
That is true, but then we are not losing anything.
This codepath is not about the payload (the contents of the files) but the
author name part of the commit log message, and UTF-8 would probably be
the only sensible encoding to standardize on.
If your project uses UTF-8 for everybody, great, we will align them better
than we did before. If not, sorry, you will get a different misaligned
names.
That assumes utf8_width() does not barf when fed an invalid byte sequence,
but I did not think it is that fragile (I didn't actually audit the
codepath, though).
^ permalink raw reply
* Re: [PATCH] Switch receive.denyCurrentBranch to "refuse"
From: Sam Vilain @ 2009-02-02 7:00 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Nanako Shiraishi, Johannes Schindelin, Jay Soffian, git
In-Reply-To: <7vbptlsuyv.fsf@gitster.siamese.dyndns.org>
On Sun, 2009-02-01 at 13:33 -0800, Junio C Hamano wrote:
> > I just can't understand the
> > resistance to this safety feature. People who encounter the bug can
> > just change the setting and move on... it seems like an argument based
> > on "principles", usually a sign that one has run out of actual
> > arguments..
>
> There is no resitance to any safety feature. The resistance is to
> something entirely different.
[...]
> Perhaps you already forgot the fiasco after 1.6.0, which moved tons of
> git-foo scripts out of the users' way. It resulted in a better layout in
> the end, but we knew it would break people's working setup from the
> beginning.
[...]
Yeah sure but the changes are a bit different aren't they. One affected
all users who used the previously documented way to access subcommands
(and the names that the man pages all still retain). The other affects
a small number of users who are doing something which is labeled in many
places as a bad thing to want to do.
That being said, I think I like the copy and design of the patch you
just posted. If the path of caution is to be followed for this, then
the way you propose seems a good way to do it.
Sam
^ permalink raw reply
* Re: CR codes from git commands
From: Brent Goodrick @ 2009-02-02 7:09 UTC (permalink / raw)
To: git
In-Reply-To: <200901250319.05665.bss@iguanasuicide.net>
I'm nearing completion on the patch for the --progress and
--no-progress command-line options. I am able to manually validate
the behavior, but am a bit stumped as to how to efficiently code up
the test script. My manual test involves doing a git clone of the git
repository, which produces the volume of I/O sufficiently bulky to
trigger the progress message code. But that bulk means that the test
case will take a long time to complete, hence making using a git clone
of the git code in the test case impractical.
Also, in order for the script to do its job, it will need to tell the
difference between a git run that has progress from one that does not.
The first idea would be to simply use shell command redirection on
the git command itself, but that defeats the tty detection logic, so I
don't think that is an option either.
Does anyone have any recommendations here? If not, then I guess I will
have to forgo the test script and just submit the patch without it.
Thanks,
Brent
On Sun, Jan 25, 2009 at 1:19 AM, Boyd Stephen Smith Jr.
<bss@iguanasuicide.net> wrote:
>
> On Saturday 24 January 2009, Brent Goodrick <bgoodr@gmail.com> wrote
> about 'Re: CR codes from git commands':
> >While I'm at it, what is the standard procedure for submitting git
> >patches for review once I've cooked up and validated it on my end? I'm
> >guessing posting the patch into this mailing list is part of the
> >answer to that question.
>
> If you've got a patch, I assume you've got a checkout. Look in
> Documentation/SubmittingPatches.
> --
> Boyd Stephen Smith Jr. ,= ,-_-. =.
> bss@iguanasuicide.net ((_/)o o(\_))
> ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
> http://iguanasuicide.net/ \_/
^ permalink raw reply
* Re: Linus and whitespace
From: Johannes Gilger @ 2009-02-02 7:22 UTC (permalink / raw)
To: git
In-Reply-To: <87fxix3hub.fsf@jidanni.org>
On 2009-02-01, jidanni@jidanni.org <jidanni@jidanni.org> wrote:
> Gentlemen, I couldn't help but notice a certain Linus B. Torvalds is
> producing mail with trailing whitespace.
Boy, do you have too much free time on your hands...
Greetings,
Jojo
--
Johannes Gilger <heipei@hackvalue.de>
http://hackvalue.de/heipei/
GPG-Key: 0x42F6DE81
GPG-Fingerprint: BB49 F967 775E BB52 3A81 882C 58EE B178 42F6 DE81
^ 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