* [FYI PATCH v2] Added a git search and replace command
From: Sverre Rabbelier @ 2008-07-23 19:55 UTC (permalink / raw)
To: git; +Cc: Sverre Rabbelier
A simple script that uses 'git ls-files' and a bash for
loop to search and replace (using sed) all the specified
files. There is a config option for the pathspec. This
allows the user to set 'sar.pathspec' and then specify only
the sed on the commandline.
---
Not meant for inclusion, just a simple script I wrote up
when I wanted to change a function name in my repository
but didn't want to figure out which magic argument to
find does what I want. Another advantage of using git
ls-files is that it will prevent that any unrevertable
changes will be made (since the script checks if the tree
is dirty or not). I'm sure there's plenty of room for
improvement here, it's probably not portable at all
either, so comments are welcome :).
Changes since v2, the use of xargs was taken out and
replaced by a bash for loop. Also I added a config value
because I'm too lazy to type the pathspec each time.
Interdiff below:
diff --git a/git-sar.sh b/git-sar.sh
index db6317b..e64b9bd 100755
--- a/git-sar.sh
+++ b/git-sar.sh
@@ -1,24 +1,26 @@
#!/bin/bash
-do_sed () {
- sed "$2" $3 > $3.replaced
- mv $3.replaced $3
-}
-
do_git_find() {
# Sanity check
if is_dirty_tree
then
echo "Refusing to work on a dirty tree"
+ exit 1
fi
files=`git ls-files "$1"`
+
+ # See if there were any matching files
if test -z "$files"
then
echo "Your pathspec did not match any files."
exit 1
fi
- echo "$files" | xargs -n 1 git-sar --replace $2
+
+ # Change them in-place
+ for file in $files; do
+ sed -i "$2" "$file";
+ done
}
is_dirty_tree () {
@@ -33,27 +35,28 @@ do_show_usage() {
do_main() {
# Verify argument size
- if test "$#" -le 1 -o "$#" -ge 4
+ if test "$#" -ge 3
then
do_show_usage
fi
- # Two argument form
- if test "$#" -eq 2
+ if test "$#" -eq 1
then
- do_git_find "$@"
- fi
+ glob=`git config --get sar.pathspec`
- # Three argument form, we're calling ourselves through sed
- if test "$#" -eq 3
- then
- # Double check if the user typoed or if we are indeed meta-calling
- if test "$1" != "--replace"
+ if test -z "$glob"
then
+ echo "No sar.pathspec set"
do_show_usage
fi
- do_sed "$@"
+ do_git_find "$glob" "$1"
+ fi
+
+ # Two argument form
+ if test "$#" -eq 2
+ then
+ do_git_find "$@"
fi
}
.gitignore | 1 +
Makefile | 1 +
git-sar.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 0 deletions(-)
create mode 100755 git-sar.sh
diff --git a/.gitignore b/.gitignore
index a213e8e..451cb93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -108,6 +108,7 @@ git-rev-list
git-rev-parse
git-revert
git-rm
+git-sar
git-send-email
git-send-pack
git-sh-setup
diff --git a/Makefile b/Makefile
index b01cf1c..979e9ea 100644
--- a/Makefile
+++ b/Makefile
@@ -252,6 +252,7 @@ SCRIPT_SH += git-sh-setup.sh
SCRIPT_SH += git-stash.sh
SCRIPT_SH += git-submodule.sh
SCRIPT_SH += git-web--browse.sh
+SCRIPT_SH += git-sar.sh
SCRIPT_PERL += git-add--interactive.perl
SCRIPT_PERL += git-archimport.perl
diff --git a/git-sar.sh b/git-sar.sh
new file mode 100755
index 0000000..e64b9bd
--- /dev/null
+++ b/git-sar.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+do_git_find() {
+ # Sanity check
+ if is_dirty_tree
+ then
+ echo "Refusing to work on a dirty tree"
+ exit 1
+ fi
+
+ files=`git ls-files "$1"`
+
+ # See if there were any matching files
+ if test -z "$files"
+ then
+ echo "Your pathspec did not match any files."
+ exit 1
+ fi
+
+ # Change them in-place
+ for file in $files; do
+ sed -i "$2" "$file";
+ done
+}
+
+is_dirty_tree () {
+ `git diff --quiet`
+ test $? -ne 0
+}
+
+do_show_usage() {
+ echo "usage: git-sar pathspec sed"
+ exit 128
+}
+
+do_main() {
+ # Verify argument size
+ if test "$#" -ge 3
+ then
+ do_show_usage
+ fi
+
+ if test "$#" -eq 1
+ then
+ glob=`git config --get sar.pathspec`
+
+ if test -z "$glob"
+ then
+ echo "No sar.pathspec set"
+ do_show_usage
+ fi
+
+ do_git_find "$glob" "$1"
+ fi
+
+ # Two argument form
+ if test "$#" -eq 2
+ then
+ do_git_find "$@"
+ fi
+}
+
+do_main "$@"
+
--
1.6.0.rc0.15.gc85d5
^ permalink raw reply related
* Re: [PATCH] Respect crlf attribute even if core.autocrlf has not been set
From: Eyvind Bernhardsen @ 2008-07-23 19:20 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Avery Pennarun, Joshua Jensen, Junio C Hamano, git
In-Reply-To: <alpine.DEB.1.00.0807231956280.8986@racer>
On 23. juli. 2008, at 20.57, Johannes Schindelin wrote:
> Hi,
>
> On Wed, 23 Jul 2008, Avery Pennarun wrote:
>
>> 1. always CRLF on all platforms (eg. for .bat files)
>> 2. always LF on all platforms (eg. for shell scripts and perl
>> scripts)
>> 3. just leave it alone no matter what (eg. for binary files)
>
> These are not different, but equal. "Do no harm to the contents of
> this
> file".
That is only true until someone edits the file in an editor which
prefers the wrong end-of-line marker, and converts to it when saving.
It will be obvious that this has happened if the user does a "git
diff" before committing, but I think the intent of nos. 1 and 2 is for
git to automatically convert the line endings back instead of kicking
up a fuss.
Might be too magical, though.
Eyvind Bernhardsen
^ permalink raw reply
* Re: q: faster way to integrate/merge lots of topic branches?
From: Junio C Hamano @ 2008-07-23 20:01 UTC (permalink / raw)
To: Ingo Molnar; +Cc: SZEDER Gábor, git
In-Reply-To: <20080723140441.GA9537@elte.hu>
Ingo Molnar <mingo@elte.hu> writes:
> hm, it's very slow:
>
> $ time git branch --no-merged
> [...]
>
> real 0m9.177s
> user 0m9.027s
> sys 0m0.129s
>
> when running it on tip/master:
>
> http://people.redhat.com/mingo/tip.git/README
Hmmm, does not reproduce for me with a copy of that repository.
$ time git branch -a --no-merged mingo/master
linus/master
mingo/acpi-for-len
mingo/auto-cpus4096-next
mingo/auto-kmemcheck-next
mingo/auto-test
mingo/auto-test-fixes
mingo/core/futex-64bit
mingo/core/kill-the-BKL
mingo/core/percpu-zerobased
mingo/cpus4096-for-linus
mingo/kmemcheck-for-linus
mingo/stackprotector-for-linus
mingo/timers/for-linus
mingo/tip
mingo/tracing/ftrace
mingo/tracing/immediates
mingo/tracing/markers
mingo/tracing/stopmachine-allcpus
mingo/tracing/textedit
mingo/x86/acpi-rename-acpi_nmi
mingo/x86/audit-speedup
mingo/x86/crashdump
mingo/x86/header-guards
mingo/x86/prototypes
mingo/x86/sparse-fixes
mingo/x86/unify-mce
mingo/x86/x2apic
real 0m1.442s
user 0m1.360s
sys 0m0.084s
With the patch I posted earlier, the time becomes:
real 0m0.600s
user 0m0.560s
sys 0m0.040s
^ permalink raw reply
* Re: [PATCH] Respect crlf attribute even if core.autocrlf has not been set
From: Johannes Schindelin @ 2008-07-23 20:07 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vhcagcsmj.fsf@gitster.siamese.dyndns.org>
Hi,
On Wed, 23 Jul 2008, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > On Wed, 23 Jul 2008, Junio C Hamano wrote:
> > ...
> >> If you are on a sane system, you do not even want to pay the price of
> >> conversion. Only people on systems with CRLF line endings should pay
> >> the price (because your aim is to convert on such systems). Are we
> >> throwing that out of the window when the project decides to use
> >> gitattributes?
> >
> > Well, if you do not want that, why do you set crlf in the
> > gitattributes to begin with?
>
> It is not _me_ but the project upstream that needs to interact also with
> Windows people who manages gitattributes. And me personally knows my
> editors are not helpful to add CR at the end of lines, so I do not need
> the conversion.
I know you do. And I know those users don't. They do not even know that
they should set autocrlf = input in their cygwin Git.
Or at least, now they do. After a few hundred commits that have been
published _after_ their broken checkins.
Sigh,
Dscho
^ permalink raw reply
* [PATCH] svnimport: newer libsvn wants us to ask for the root with "", not "/"
From: P. Christeas @ 2008-07-23 20:08 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Gerrit Pape
In r27729, libsvn introduced an assert which explicitly
forbids searching the tree at "/". Luckily enough, it
still accepts an empty string "" as the starting point.
http://svn.collab.net/viewvc/svn/trunk/subversion/libsvn_ra/ra_loader.c?r1=27653&r2=27729
Tested against libsvn0-1.5.0-4mdv2009.0 (needs the fix),
libsvn0-1.4.6-5mdv2008.1 (works anyway)
Signed-off-by: P. Christeas <p_christ@hol.gr>
---
contrib/examples/git-svnimport.perl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/contrib/examples/git-svnimport.perl
b/contrib/examples/git-svnimport.perl
index ea8c1b2..a13bb6a 100755
--- a/contrib/examples/git-svnimport.perl
+++ b/contrib/examples/git-svnimport.perl
@@ -933,7 +933,7 @@ while ($to_rev < $opt_l) {
$to_rev = $from_rev + $repack_after;
$to_rev = $opt_l if $opt_l < $to_rev;
print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
- $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\&commit_all);
+ $svn->{'svn'}->get_log("",$from_rev,$to_rev,0,1,1,\&commit_all);
my $pid = fork();
die "Fork: $!\n" unless defined $pid;
unless($pid) {
--
1.5.6
^ permalink raw reply related
* Re: [RFC] Git User's Survey 2008
From: Dmitry Potapov @ 2008-07-23 20:09 UTC (permalink / raw)
To: Matthias Kestenholz; +Cc: Jakub Narebski, git, Stephan Beyer
In-Reply-To: <1216827806.9938.18.camel@localhost>
On Wed, Jul 23, 2008 at 05:43:26PM +0200, Matthias Kestenholz wrote:
> On Wed, 2008-07-23 at 18:38 +0400, Dmitry Potapov wrote:
> > On Wed, Jul 23, 2008 at 03:25:03AM +0200, Jakub Narebski wrote:
> > > 02. What is your preferred non-programming language?
> > > (or) What is the language you want computer communicate with you?
> >
> > IMHO, the later wording of the question is much better.
>
> I think these are two separate questions. In my case the first is
> (swiss) german, the second is english. I don't like localized software
> too much, I always have to think what a certain german term might mean
> in english to understand computing-specific texts.
Wellcome to the club of those who don't like localized software :)
>
> That being said I think that the first question is irrelevant for the
> git survey.
Exactly. That is why I said the later wording is better. I believe the
implied question was what language would you like Git to talk with you.
Dmitry
^ permalink raw reply
* Re: q: faster way to integrate/merge lots of topic branches?
From: Pierre Habouzit @ 2008-07-23 20:27 UTC (permalink / raw)
To: Linus Torvalds, Ingo Molnar, git
In-Reply-To: <20080723190920.GG20614@artemis.madism.org>
[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]
On Wed, Jul 23, 2008 at 07:09:20PM +0000, Pierre Habouzit wrote:
> On Wed, Jul 23, 2008 at 05:59:01PM +0000, Linus Torvalds wrote:
> > In fact, the two top entries in a profile look roughly like:
> >
> > 102161 70.2727 libz.so.1.2.3 libz.so.1.2.3 (no symbols)
> > 7685 5.2862 git git find_pack_entry_one
> > ...
> >
> > ie 70% of the time is just purely unpacking the data, and another 5% is
> > just finding it. We could perhaps improve on it, but not a whole lot.
>
> Well there is an easy way though, that could reduce that: using
> adaptative compression. I proposed a patch once upon a time, that set
> the compression strengh to 0 for "small" objects with a configurable
> cut-off. If you do that, most trees, commits messages and so on aren't
> compressed, and it will reduce (with IIRC a 5-liner) this time quite
> dramatically.
>
> I could maybe resurect it to see if for people that do the kind of
> things Ingo does it helps. By setting the cut-off at 1k, I had packs
> being less than 1% bigger IIRC. I'll try to find it again and run your
> tests with it to see how much it helps.
Unsurprisingly with a 1024o cutoff, the numbers are (first run is
forced cold-cache with /proc/.../drop_caches, second is the best run of 5):
default git:
3.10user 0.16system 0:08.10elapsed 40%CPU (0avgtext+0avgdata 0maxresident)k
116152inputs+0outputs (671major+35286minor)pagefaults 0swaps
2.01user 0.11system 0:02.12elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+35958minor)pagefaults 0swaps
With a 1024k cutoff:
1.16user 0.13system 0:08.29elapsed 15%CPU (0avgtext+0avgdata 0maxresident)k
154208inputs+0outputs (947major+39777minor)pagefaults 0swaps
0.76user 0.06system 0:00.82elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+40724minor)pagefaults 0swaps
According to [0], a 1k cutoff meant something like a 10% larger pack. 512o
meant an almost identical pack in size, but with reduced performance
improvements.
[0] http://thread.gmane.org/gmane.comp.version-control.git/70019/focus=70250
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* Re: [PATCH] Rename ".dotest/" to ".git/rebase" and ".dotest-merge" to "rebase-merge"
From: Junio C Hamano @ 2008-07-23 20:40 UTC (permalink / raw)
To: Stephan Beyer
Cc: Olivier Marin, Theodore Tso, Nanako Shiraishi,
Johannes Schindelin, René Scharfe, Joe Fiorini, git,
Jari Aalto
In-Reply-To: <20080723011341.GE5904@leksak.fem-net>
Stephan Beyer <s-beyer@gmx.net> writes:
>> Just being a bit defensive -- in this case I think it might be Ok to say
>> "read-tree --reset -u ORIG_HEAD", but I haven't checked in a conflicted
>> case.
>
> Well, the test suite fails:
> ...
> So no reason to be defensive ;)
Ok, so it is not just being defensive but actually is necessary.
^ permalink raw reply
* Re: q: faster way to integrate/merge lots of topic branches?
From: Pierre Habouzit @ 2008-07-23 20:40 UTC (permalink / raw)
To: Linus Torvalds, Ingo Molnar, git
In-Reply-To: <20080723202722.GA18160@artemis.madism.org>
[-- Attachment #1: Type: text/plain, Size: 3120 bytes --]
On mer, jui 23, 2008 at 08:27:22 +0000, Pierre Habouzit wrote:
> On Wed, Jul 23, 2008 at 07:09:20PM +0000, Pierre Habouzit wrote:
> > On Wed, Jul 23, 2008 at 05:59:01PM +0000, Linus Torvalds wrote:
> > > In fact, the two top entries in a profile look roughly like:
> > >
> > > 102161 70.2727 libz.so.1.2.3 libz.so.1.2.3 (no symbols)
> > > 7685 5.2862 git git find_pack_entry_one
> > > ...
> > >
> > > ie 70% of the time is just purely unpacking the data, and another 5% is
> > > just finding it. We could perhaps improve on it, but not a whole lot.
> >
> > Well there is an easy way though, that could reduce that: using
> > adaptative compression. I proposed a patch once upon a time, that set
> > the compression strengh to 0 for "small" objects with a configurable
> > cut-off. If you do that, most trees, commits messages and so on aren't
> > compressed, and it will reduce (with IIRC a 5-liner) this time quite
> > dramatically.
> >
> > I could maybe resurect it to see if for people that do the kind of
> > things Ingo does it helps. By setting the cut-off at 1k, I had packs
> > being less than 1% bigger IIRC. I'll try to find it again and run your
> > tests with it to see how much it helps.
>
> Unsurprisingly with a 1024o cutoff, the numbers are (first run is
> forced cold-cache with /proc/.../drop_caches, second is the best run of 5):
>
> default git:
>
> 3.10user 0.16system 0:08.10elapsed 40%CPU (0avgtext+0avgdata 0maxresident)k
> 116152inputs+0outputs (671major+35286minor)pagefaults 0swaps
>
> 2.01user 0.11system 0:02.12elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (0major+35958minor)pagefaults 0swaps
>
> With a 1024k cutoff:
>
> 1.16user 0.13system 0:08.29elapsed 15%CPU (0avgtext+0avgdata 0maxresident)k
> 154208inputs+0outputs (947major+39777minor)pagefaults 0swaps
>
> 0.76user 0.06system 0:00.82elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (0major+40724minor)pagefaults 0swaps
With a 512o cutoff:
1.49user 0.17system 0:07.50elapsed 22%CPU (0avgtext+0avgdata 0maxresident)k
127648inputs+0outputs (780major+36687minor)pagefaults 0swaps
1.54user 0.07system 0:01.61elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+37467minor)pagefaults 0swaps
What I bench, I see I forgot to mention, is: git merge v2.6.14. And
the respective pack sizes:
214M .git-0/objects/pack/pack-bfeec11abed1ec6d046bc954b94d70ba81716356.pack
225M .git-512/objects/pack/pack-bfeec11abed1ec6d046bc954b94d70ba81716356.pack
243M .git-1024/objects/pack/pack-bfeec11abed1ec6d046bc954b94d70ba81716356.pack
.git-0 is cheating because it was generated with a way deeper window and
memory window that the other ones, but it allow to give rough
impressions.
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* [PATCH] bash completion: Add long options for 'git rm'
From: Lee Marlow @ 2008-07-23 21:21 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git, Lee Marlow
Options added: --cached --dry-run --ignore-unmatch --quiet
Signed-off-by: Lee Marlow <lee.marlow@gmail.com>
---
contrib/completion/git-completion.bash | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2edb341..4b7ef69 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1170,6 +1170,20 @@ _git_reset ()
__gitcomp "$(__git_refs)"
}
+_git_rm ()
+{
+ __git_has_doubledash && return
+
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ case "$cur" in
+ --*)
+ __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
+ return
+ ;;
+ esac
+ COMPREPLY=()
+}
+
_git_shortlog ()
{
__git_has_doubledash && return
@@ -1425,6 +1439,7 @@ _git ()
rebase) _git_rebase ;;
remote) _git_remote ;;
reset) _git_reset ;;
+ rm) _git_rm ;;
send-email) _git_send_email ;;
shortlog) _git_shortlog ;;
show) _git_show ;;
--
1.6.0.rc0.14.g95f8
^ permalink raw reply related
* [PATCH 1/9] builtin-verify-tag.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-verify-tag.c | 25 +++++++++++++++----------
1 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/builtin-verify-tag.c b/builtin-verify-tag.c
index 7d837f0..590038b 100644
--- a/builtin-verify-tag.c
+++ b/builtin-verify-tag.c
@@ -9,10 +9,13 @@
#include "builtin.h"
#include "tag.h"
#include "run-command.h"
+#include "parse-options.h"
#include <signal.h>
-static const char builtin_verify_tag_usage[] =
- "git verify-tag [-v|--verbose] <tag>...";
+static const char * const builtin_verify_tag_usage[] = {
+ "git verify-tag [-v|--verbose] <tag>...",
+ NULL
+};
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
@@ -88,23 +91,25 @@ static int verify_tag(const char *name, int verbose)
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
{
- int i = 1, verbose = 0, had_error = 0;
+ int verbose = 0, had_error = 0;
git_config(git_default_config, NULL);
+ const struct option options[] = {
+ OPT__VERBOSE(&verbose),
+ OPT_END()
+ };
+
if (argc == 1)
- usage(builtin_verify_tag_usage);
+ usage_with_options(builtin_verify_tag_usage, options);
- if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")) {
- verbose = 1;
- i++;
- }
+ argc = parse_options(argc, argv, options, builtin_verify_tag_usage, 0);
/* sometimes the program was terminated because this signal
* was received in the process of writing the gpg input: */
signal(SIGPIPE, SIG_IGN);
- while (i < argc)
- if (verify_tag(argv[i++], verbose))
+ while (argc-- > 0)
+ if (verify_tag(*argv++, verbose))
had_error = 1;
return had_error;
}
--
1.5.6.3
^ permalink raw reply related
* [PATCH 0/9] Extend use of parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
These patches spread the use of parse_options() to some more commands.
I tried to come up with a short description for every option, but
I'm not sure I fully succeeded. In particular, the option "sparse"
in builtin-rev-list.c has no description.
Michele Ballabio (9):
builtin-verify-tag.c: use parse_options()
builtin-write-tree.c: use parse_options()
builtin-prune-packed.c: use parse_options()
builtin-ls-tree.c: use parse_options()
builtin-rev-list.c: use parse_options()
builtin-init-db.c: use parse_options()
builtin-checkout-index.c: use parse_options()
builtin-fetch-pack.c: use parse_options()
builtin-mailinfo.c: use parse_options()
builtin-checkout-index.c | 146 +++++++++++++++++++++++++---------------------
builtin-fetch-pack.c | 144 ++++++++++++++++++++++++++++-----------------
builtin-init-db.c | 56 +++++++++++-------
builtin-ls-tree.c | 92 +++++++++++------------------
builtin-mailinfo.c | 39 +++++++------
builtin-prune-packed.c | 38 ++++++------
builtin-rev-list.c | 132 ++++++++++++++++++++---------------------
builtin-verify-tag.c | 25 +++++---
builtin-write-tree.c | 31 +++++-----
9 files changed, 376 insertions(+), 327 deletions(-)
^ permalink raw reply
* [PATCH 2/9] builtin-write-tree.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-write-tree.c | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 52a3c01..25f3d8a 100644
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
@@ -7,9 +7,12 @@
#include "cache.h"
#include "tree.h"
#include "cache-tree.h"
+#include "parse-options.h"
-static const char write_tree_usage[] =
-"git write-tree [--missing-ok] [--prefix=<prefix>/]";
+static const char * const write_tree_usage[] = {
+ "git write-tree [--missing-ok] [--prefix=<directory>/]",
+ NULL
+};
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{
@@ -19,19 +22,19 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
const char *me = "git-write-tree";
git_config(git_default_config, NULL);
- while (1 < argc) {
- const char *arg = argv[1];
- if (!strcmp(arg, "--missing-ok"))
- missing_ok = 1;
- else if (!prefixcmp(arg, "--prefix="))
- prefix = arg + 9;
- else
- usage(write_tree_usage);
- argc--; argv++;
- }
- if (argc > 2)
- die("too many options");
+ const struct option options[] = {
+ OPT_BOOLEAN(0, "missing-ok", &missing_ok,
+ "disable existence check"),
+ OPT_STRING(0, "prefix", &prefix, "directory",
+ "write a tree object for <directory>"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, write_tree_usage, 0);
+
+ if (argc > 0)
+ usage_with_options(write_tree_usage, options);
ret = write_cache_as_tree(sha1, missing_ok, prefix);
switch (ret) {
--
1.5.6.3
^ permalink raw reply related
* [PATCH 4/9] builtin-ls-tree.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-ls-tree.c | 92 +++++++++++++++++++++--------------------------------
1 files changed, 36 insertions(+), 56 deletions(-)
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index d25767a..a0b17aa 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -9,6 +9,7 @@
#include "commit.h"
#include "quote.h"
#include "builtin.h"
+#include "parse-options.h"
static int line_termination = '\n';
#define LS_RECURSIVE 1
@@ -22,8 +23,10 @@ static const char **pathspec;
static int chomp_prefix;
static const char *ls_tree_prefix;
-static const char ls_tree_usage[] =
- "git ls-tree [-d] [-r] [-t] [-l] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
+static const char * const ls_tree_usage[] = {
+ "git ls-tree [options] <tree-ish> [path...]",
+ NULL
+};
static int show_recursive(const char *base, int baselen, const char *pathname)
{
@@ -122,70 +125,47 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
unsigned char sha1[20];
struct tree *tree;
+ const struct option options[] = {
+ OPT_SET_INT('z', NULL, &line_termination,
+ "\\0 line termination on output", 0),
+ OPT_BIT('r', NULL, &ls_options,
+ "recurse into sub-trees", LS_RECURSIVE),
+ OPT_BIT('d', NULL, &ls_options,
+ "show only the tree, not its children",
+ LS_TREE_ONLY),
+ OPT_BIT('t', NULL, &ls_options,
+ "show tree entries", LS_SHOW_TREES),
+ OPT_BIT('l', "long", &ls_options,
+ "show object size of blob (file) entries",
+ LS_SHOW_SIZE),
+ OPT_BIT(0, "name-only", &ls_options,
+ "list only filenames", LS_NAME_ONLY),
+ OPT_BIT(0, "name-status", &ls_options,
+ "same as --name-only", LS_NAME_ONLY),
+ OPT_SET_INT(0, "full-name", &chomp_prefix,
+ "show the full path name", 0),
+ OPT__ABBREV(&abbrev),
+ OPT_END()
+ };
+
git_config(git_default_config, NULL);
ls_tree_prefix = prefix;
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
- while (1 < argc && argv[1][0] == '-') {
- switch (argv[1][1]) {
- case 'z':
- line_termination = 0;
- break;
- case 'r':
- ls_options |= LS_RECURSIVE;
- break;
- case 'd':
- ls_options |= LS_TREE_ONLY;
- break;
- case 't':
- ls_options |= LS_SHOW_TREES;
- break;
- case 'l':
- ls_options |= LS_SHOW_SIZE;
- break;
- case '-':
- if (!strcmp(argv[1]+2, "name-only") ||
- !strcmp(argv[1]+2, "name-status")) {
- ls_options |= LS_NAME_ONLY;
- break;
- }
- if (!strcmp(argv[1]+2, "long")) {
- ls_options |= LS_SHOW_SIZE;
- break;
- }
- if (!strcmp(argv[1]+2, "full-name")) {
- chomp_prefix = 0;
- break;
- }
- if (!prefixcmp(argv[1]+2, "abbrev=")) {
- abbrev = strtoul(argv[1]+9, NULL, 10);
- if (abbrev && abbrev < MINIMUM_ABBREV)
- abbrev = MINIMUM_ABBREV;
- else if (abbrev > 40)
- abbrev = 40;
- break;
- }
- if (!strcmp(argv[1]+2, "abbrev")) {
- abbrev = DEFAULT_ABBREV;
- break;
- }
- /* otherwise fallthru */
- default:
- usage(ls_tree_usage);
- }
- argc--; argv++;
- }
+
+ argc = parse_options(argc, argv, options, ls_tree_usage, 0);
+
/* -d -r should imply -t, but -d by itself should not have to. */
if ( (LS_TREE_ONLY|LS_RECURSIVE) ==
((LS_TREE_ONLY|LS_RECURSIVE) & ls_options))
ls_options |= LS_SHOW_TREES;
- if (argc < 2)
- usage(ls_tree_usage);
- if (get_sha1(argv[1], sha1))
- die("Not a valid object name %s", argv[1]);
+ if (argc < 1)
+ usage_with_options(ls_tree_usage, options);
+ if (get_sha1(argv[0], sha1))
+ die("Not a valid object name %s", argv[0]);
- pathspec = get_pathspec(prefix, argv + 2);
+ pathspec = get_pathspec(prefix, argv + 1);
tree = parse_tree_indirect(sha1);
if (!tree)
die("not a tree object");
--
1.5.6.3
^ permalink raw reply related
* [PATCH 3/9] builtin-prune-packed.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-prune-packed.c | 38 ++++++++++++++++++--------------------
1 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/builtin-prune-packed.c b/builtin-prune-packed.c
index 10cb8df..5866871 100644
--- a/builtin-prune-packed.c
+++ b/builtin-prune-packed.c
@@ -1,12 +1,15 @@
#include "builtin.h"
#include "cache.h"
#include "progress.h"
+#include "parse-options.h"
-static const char prune_packed_usage[] =
-"git prune-packed [-n] [-q]";
+static const char * const prune_packed_usage[] = {
+ "git prune-packed [-n] [-q]",
+ NULL
+};
#define DRY_RUN 01
-#define VERBOSE 02
+#define QUIET 02
static struct progress *progress;
@@ -43,7 +46,7 @@ void prune_packed_objects(int opts)
const char *dir = get_object_directory();
int len = strlen(dir);
- if (opts == VERBOSE)
+ if (!opts)
progress = start_progress_delay("Removing duplicate objects",
256, 95, 2);
@@ -67,24 +70,19 @@ void prune_packed_objects(int opts)
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
{
- int i;
- int opts = VERBOSE;
+ int opts = 0;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
+ const struct option options[] = {
+ OPT_BIT('n', "dry-run", &opts, "dry run", DRY_RUN),
+ OPT_BIT('q', "quiet", &opts, "be quiet", QUIET),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, prune_packed_usage, 0);
+
+ if (argc > 0)
+ usage_with_options(prune_packed_usage, options);
- if (*arg == '-') {
- if (!strcmp(arg, "-n"))
- opts |= DRY_RUN;
- else if (!strcmp(arg, "-q"))
- opts &= ~VERBOSE;
- else
- usage(prune_packed_usage);
- continue;
- }
- /* Handle arguments here .. */
- usage(prune_packed_usage);
- }
prune_packed_objects(opts);
return 0;
}
--
1.5.6.3
^ permalink raw reply related
* [PATCH 5/9] builtin-rev-list.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-rev-list.c | 132 +++++++++++++++++++++++++--------------------------
1 files changed, 65 insertions(+), 67 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 893762c..9200b20 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -11,44 +11,16 @@
#include "builtin.h"
#include "log-tree.h"
#include "graph.h"
+#include "parse-options.h"
/* bits #0-15 in revision.h */
#define COUNTED (1u<<16)
-static const char rev_list_usage[] =
-"git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
-" limiting output:\n"
-" --max-count=nr\n"
-" --max-age=epoch\n"
-" --min-age=epoch\n"
-" --sparse\n"
-" --no-merges\n"
-" --remove-empty\n"
-" --all\n"
-" --branches\n"
-" --tags\n"
-" --remotes\n"
-" --stdin\n"
-" --quiet\n"
-" ordering output:\n"
-" --topo-order\n"
-" --date-order\n"
-" --reverse\n"
-" formatting output:\n"
-" --parents\n"
-" --children\n"
-" --objects | --objects-edge\n"
-" --unpacked\n"
-" --header | --pretty\n"
-" --abbrev=nr | --no-abbrev\n"
-" --abbrev-commit\n"
-" --left-right\n"
-" special purpose:\n"
-" --bisect\n"
-" --bisect-vars\n"
-" --bisect-all"
-;
+static const char * const rev_list_usage[] = {
+ "git rev-list [OPTION] <commit-id>... [ -- paths... ]",
+ NULL
+};
static struct rev_info revs;
@@ -575,15 +547,65 @@ static struct commit_list *find_bisection(struct commit_list *list,
return best;
}
+static int parse_header_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct rev_info *t_revs = opt->value;
+ t_revs->verbose_header = unset ? 0 : 1;
+ return 0;
+}
+
int cmd_rev_list(int argc, const char **argv, const char *prefix)
{
struct commit_list *list;
- int i;
int read_from_stdin = 0;
int bisect_show_vars = 0;
int bisect_find_all = 0;
int quiet = 0;
+ const struct option options[] = {
+ OPT_GROUP("limiting output:"),
+ OPT_ARGUMENT("max-count=nr", "limit number of commits output"),
+ OPT_ARGUMENT("max-age=epoch", "limit commits output by time"),
+ OPT_ARGUMENT("min-age=epoch", "limit commits output by time"),
+ OPT_ARGUMENT("sparse", ""),
+ OPT_ARGUMENT("no-merges", "do not print merges"),
+ OPT_ARGUMENT("remove-empty", "stop when a given path disappears from the tree"),
+ OPT_ARGUMENT("all", "all refs"),
+ OPT_ARGUMENT("branches", "show local branches"),
+ OPT_ARGUMENT("tags", "show tags"),
+ OPT_ARGUMENT("remotes", "show remote-tracking branches"),
+ OPT_BOOLEAN(0, "stdin", &read_from_stdin,
+ "read commits also from command line"),
+ OPT__QUIET(&quiet),
+ OPT_GROUP("ordering output:"),
+ OPT_ARGUMENT("topo-order", "show commits in topological order"),
+ OPT_ARGUMENT("date-order", "use date order, preserving topology"),
+ OPT_ARGUMENT("reverse", "output commits in reverse order"),
+ OPT_GROUP("formatting output:"),
+ OPT_ARGUMENT("parents", "print the parents of the commit"),
+ OPT_ARGUMENT("children", "print the children of the commit"),
+ OPT_ARGUMENT("objects", "print all objects"),
+ OPT_ARGUMENT("objects-edge", "similar to --objects, used by git-pack-objects"),
+ OPT_ARGUMENT("unpacked", "print objects not in packs"),
+ { OPTION_CALLBACK, 0, "header", &revs, NULL,
+ "use raw-format", PARSE_OPT_NOARG, parse_header_cb, 0 },
+ OPT_ARGUMENT("pretty", "print contents in a given format"),
+ OPT_BOOLEAN(0, "timestamp", &show_timestamp,
+ "print the raw commit timestamp"),
+ OPT_ARGUMENT("abbrev-commit", "show short sha1"),
+ OPT_ARGUMENT("abbrev=nr", "number of digits used for short sha1"),
+ OPT_ARGUMENT("no-abbrev", "do not use short sha1"),
+ OPT_ARGUMENT("left-right", "mark side of symmetric diff"),
+ OPT_ARGUMENT("graph", "show an ASCII graph"),
+ OPT_GROUP("special purpose:"),
+ OPT_BOOLEAN(0, "bisect", &bisect_list, "useful for binary searches"),
+ OPT_BOOLEAN(0, "bisect-all", &bisect_find_all,
+ "order commits by their distance from given commits"),
+ OPT_BOOLEAN(0, "bisect-vars", &bisect_show_vars,
+ "like --bisect, but ready to be eval'ed"),
+ OPT_END()
+ };
+
git_config(git_default_config, NULL);
init_revisions(&revs, prefix);
revs.abbrev = 0;
@@ -591,40 +613,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
argc = setup_revisions(argc, argv, &revs, NULL);
quiet = DIFF_OPT_TST(&revs.diffopt, QUIET);
- for (i = 1 ; i < argc; i++) {
- const char *arg = argv[i];
+ argc = parse_options(argc, argv, options, rev_list_usage, 0);
- if (!strcmp(arg, "--header")) {
- revs.verbose_header = 1;
- continue;
- }
- if (!strcmp(arg, "--timestamp")) {
- show_timestamp = 1;
- continue;
- }
- if (!strcmp(arg, "--bisect")) {
- bisect_list = 1;
- continue;
- }
- if (!strcmp(arg, "--bisect-all")) {
- bisect_list = 1;
- bisect_find_all = 1;
- continue;
- }
- if (!strcmp(arg, "--bisect-vars")) {
- bisect_list = 1;
- bisect_show_vars = 1;
- continue;
- }
- if (!strcmp(arg, "--stdin")) {
- if (read_from_stdin++)
- die("--stdin given twice?");
- read_revisions_from_stdin(&revs);
- continue;
- }
- usage(rev_list_usage);
+ if (argc > 0)
+ usage_with_options(rev_list_usage, options);
+
+ if (bisect_find_all || bisect_show_vars)
+ bisect_list = 1;
+ if (read_from_stdin)
+ read_revisions_from_stdin(&revs);
- }
if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
/* The command line has a --pretty */
hdr_termination = '\n';
@@ -643,7 +641,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
(!(revs.tag_objects||revs.tree_objects||revs.blob_objects) &&
!revs.pending.nr)) ||
revs.diff)
- usage(rev_list_usage);
+ usage_with_options(rev_list_usage, options);
save_commit_buffer = revs.verbose_header || revs.grep_filter;
if (bisect_list)
--
1.5.6.3
^ permalink raw reply related
* [PATCH 7/9] builtin-checkout-index.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-checkout-index.c | 146 +++++++++++++++++++++++++---------------------
1 files changed, 79 insertions(+), 67 deletions(-)
diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c
index 71ebabf..429c850 100644
--- a/builtin-checkout-index.c
+++ b/builtin-checkout-index.c
@@ -40,6 +40,7 @@
#include "cache.h"
#include "quote.h"
#include "cache-tree.h"
+#include "parse-options.h"
#define CHECKOUT_ALL 4
static int line_termination = '\n';
@@ -153,18 +154,76 @@ static void checkout_all(const char *prefix, int prefix_length)
exit(128);
}
-static const char checkout_cache_usage[] =
-"git checkout-index [-u] [-q] [-a] [-f] [-n] [--stage=[123]|all] [--prefix=<string>] [--temp] [--] <file>...";
+static const char * const checkout_cache_usage[] = {
+ "git checkout-index [options] [--] <file>...",
+ NULL
+};
+
+static int parse_state_force_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct checkout *t_state = opt->value;
+ t_state->force = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_state_quiet_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct checkout *t_state = opt->value;
+ t_state->quiet = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_state_no_create_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct checkout *t_state = opt->value;
+ t_state->not_new = 1;
+ return 0;
+}
+
+static int parse_state_index_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct checkout *t_state = opt->value;
+ t_state->refresh_cache = unset ? 0 : 1;
+ return 0;
+}
static struct lock_file lock_file;
int cmd_checkout_index(int argc, const char **argv, const char *prefix)
{
- int i;
int newfd = -1;
int all = 0;
int read_from_stdin = 0;
int prefix_length;
+ char *stage = NULL;
+
+ const struct option options[] = {
+ OPT_BOOLEAN('a', "all", &all,
+ "checks out all files in the index"),
+ { OPTION_CALLBACK, 'f', "force", &state, NULL,
+ "force overwrite of existing files",
+ PARSE_OPT_NOARG, parse_state_force_cb, 0 },
+ { OPTION_CALLBACK, 'q', "quiet", &state, NULL, "be quiet",
+ PARSE_OPT_NOARG, parse_state_quiet_cb, 0 },
+ { OPTION_CALLBACK, 'n', "no-create", &state, NULL,
+ "do not checkout new files, refresh existing ones",
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ parse_state_no_create_cb, 0 },
+ { OPTION_CALLBACK, 'u', "index", &state, NULL,
+ "update stat information in the index",
+ PARSE_OPT_NOARG, parse_state_index_cb, 0 },
+ OPT_SET_INT('z', NULL, &line_termination,
+ "separate paths with NUL", 0),
+ OPT_BOOLEAN(0, "stdin", &read_from_stdin,
+ "read paths from stdin"),
+ OPT_BOOLEAN(0, "temp", &to_tempfile,
+ "write content to temporary files"),
+ OPT_STRING(0, "prefix", &state.base_dir, "string",
+ "prepend <string> when creating files"),
+ OPT_STRING(0, "stage", &stage, "1|2|3|all",
+ "copy out files from the named stage"),
+ OPT_END()
+ };
git_config(git_default_config, NULL);
state.base_dir = "";
@@ -174,71 +233,24 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
die("invalid cache");
}
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
+ argc = parse_options(argc, argv, options, checkout_cache_usage, 0);
- if (!strcmp(arg, "--")) {
- i++;
- break;
- }
- if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
- all = 1;
- continue;
- }
- if (!strcmp(arg, "-f") || !strcmp(arg, "--force")) {
- state.force = 1;
- continue;
- }
- if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) {
- state.quiet = 1;
- continue;
- }
- if (!strcmp(arg, "-n") || !strcmp(arg, "--no-create")) {
- state.not_new = 1;
- continue;
- }
- if (!strcmp(arg, "-u") || !strcmp(arg, "--index")) {
- state.refresh_cache = 1;
- if (newfd < 0)
- newfd = hold_locked_index(&lock_file, 1);
- continue;
- }
- if (!strcmp(arg, "-z")) {
- line_termination = 0;
- continue;
- }
- if (!strcmp(arg, "--stdin")) {
- if (i != argc - 1)
- die("--stdin must be at the end");
- read_from_stdin = 1;
- i++; /* do not consider arg as a file name */
- break;
- }
- if (!strcmp(arg, "--temp")) {
+ if ((state.refresh_cache) && (newfd < 0))
+ newfd = hold_locked_index(&lock_file, 1);
+ if (state.base_dir)
+ state.base_dir_len = strlen(state.base_dir);
+
+ if (stage) {
+ if (!strcmp(stage, "all")) {
to_tempfile = 1;
- continue;
- }
- if (!prefixcmp(arg, "--prefix=")) {
- state.base_dir = arg+9;
- state.base_dir_len = strlen(state.base_dir);
- continue;
- }
- if (!prefixcmp(arg, "--stage=")) {
- if (!strcmp(arg + 8, "all")) {
- to_tempfile = 1;
- checkout_stage = CHECKOUT_ALL;
- } else {
- int ch = arg[8];
- if ('1' <= ch && ch <= '3')
- checkout_stage = arg[8] - '0';
- else
- die("stage should be between 1 and 3 or all");
- }
- continue;
+ checkout_stage = CHECKOUT_ALL;
+ } else {
+ int ch = stage[0];
+ if ('1' <= ch && ch <= '3')
+ checkout_stage = stage[0] - '0';
+ else
+ die("stage should be between 1 and 3 or all");
}
- if (arg[0] == '-')
- usage(checkout_cache_usage);
- break;
}
if (state.base_dir_len || to_tempfile) {
@@ -253,8 +265,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
}
/* Check out named files first */
- for ( ; i < argc; i++) {
- const char *arg = argv[i];
+ while (argc-- > 0) {
+ const char *arg = *argv++;
const char *p;
if (all)
--
1.5.6.3
^ permalink raw reply related
* [PATCH 6/9] builtin-init-db.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-init-db.c | 56 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 38b4fcb..ea1bed7 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -6,6 +6,7 @@
#include "cache.h"
#include "builtin.h"
#include "exec_cmd.h"
+#include "parse-options.h"
#ifndef DEFAULT_GIT_TEMPLATE_DIR
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -353,8 +354,17 @@ static int guess_repository_type(const char *git_dir)
return 1;
}
-static const char init_db_usage[] =
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
+static const char * const init_db_usage[] = {
+ "git init [-q | --quiet] [--bare] [--template=<dir>] [--shared[=<type>]]",
+ NULL
+};
+
+static int parse_opt_shared_cb(const struct option *opt, const char *arg,
+ int unset)
+{
+ *(int *)(opt->value) = unset ? 0 : git_config_perm("arg", arg);
+ return 0;
+}
/*
* If you want to, you can share the DB area with any number of branches.
@@ -367,25 +377,29 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
const char *git_dir;
const char *template_dir = NULL;
unsigned int flags = 0;
- int i;
-
- for (i = 1; i < argc; i++, argv++) {
- const char *arg = argv[1];
- if (!prefixcmp(arg, "--template="))
- template_dir = arg+11;
- else if (!strcmp(arg, "--bare")) {
- static char git_dir[PATH_MAX+1];
- is_bare_repository_cfg = 1;
- setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
- sizeof(git_dir)), 0);
- } else if (!strcmp(arg, "--shared"))
- shared_repository = PERM_GROUP;
- else if (!prefixcmp(arg, "--shared="))
- shared_repository = git_config_perm("arg", arg+9);
- else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
- flags |= INIT_DB_QUIET;
- else
- usage(init_db_usage);
+ int bare = 0;
+
+ const struct option options[] = {
+ OPT_STRING(0, "template", &template_dir, "dir",
+ "directory from which templates will be used"),
+ OPT_BOOLEAN(0, "bare", &bare, "set up a bare repo"),
+ { OPTION_CALLBACK, 0, "shared", &shared_repository,
+ "type", "type of shared repository",
+ PARSE_OPT_OPTARG, parse_opt_shared_cb, PERM_GROUP },
+ OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, init_db_usage, 0);
+
+ if (argc > 0)
+ usage_with_options(init_db_usage, options);
+
+ if (bare) {
+ static char git_dir[PATH_MAX+1];
+ is_bare_repository_cfg = 1;
+ setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+ sizeof(git_dir)), 0);
}
/*
--
1.5.6.3
^ permalink raw reply related
* [PATCH 9/9] builtin-mailinfo.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-mailinfo.c | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index f974b9d..f1ed269 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -6,6 +6,7 @@
#include "builtin.h"
#include "utf8.h"
#include "strbuf.h"
+#include "parse-options.h"
static FILE *cmitmsg, *patchfile, *fin, *fout;
@@ -905,8 +906,10 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
return 0;
}
-static const char mailinfo_usage[] =
- "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
+static const char * const mailinfo_usage[] = {
+ "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info",
+ NULL
+};
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{
@@ -920,22 +923,22 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset;
- while (1 < argc && argv[1][0] == '-') {
- if (!strcmp(argv[1], "-k"))
- keep_subject = 1;
- else if (!strcmp(argv[1], "-u"))
- metainfo_charset = def_charset;
- else if (!strcmp(argv[1], "-n"))
- metainfo_charset = NULL;
- else if (!prefixcmp(argv[1], "--encoding="))
- metainfo_charset = argv[1] + 11;
- else
- usage(mailinfo_usage);
- argc--; argv++;
- }
+ const struct option options[] = {
+ OPT_BOOLEAN('k', NULL, &keep_subject,
+ "keep subject, don't clean it up"),
+ OPT_SET_PTR('u', NULL, &metainfo_charset,
+ "re-code in UTF-8", (intptr_t)def_charset),
+ OPT_SET_PTR('n', NULL, &metainfo_charset,
+ "disable re-coding", (intptr_t)NULL),
+ OPT_STRING(0, "encoding", &metainfo_charset,
+ "encoding", "override default encoding"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, mailinfo_usage, 0);
- if (argc != 3)
- usage(mailinfo_usage);
+ if (argc != 2)
+ usage_with_options(mailinfo_usage, options);
- return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[1], argv[2]);
+ return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[0], argv[1]);
}
--
1.5.6.3
^ permalink raw reply related
* [PATCH] git-completion.bash: provide completion for 'show-branch'
From: Thomas Rast @ 2008-07-23 21:36 UTC (permalink / raw)
To: git; +Cc: gitster, Shawn O. Pearce
It previously used the same as 'log', but the options are quite
different and the arguments must be single refs (or globs).
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
contrib/completion/git-completion.bash | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5d260e2..4cfe927 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1210,6 +1210,22 @@ _git_show ()
__git_complete_file
}
+_git_show_branch ()
+{
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --all --remotes --topo-order --current --more=
+ --list --independent --merge-base --no-name
+ --sha1-name --topics --reflog
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
_git_stash ()
{
local subcommands='save list show apply clear drop pop create'
@@ -1428,7 +1444,7 @@ _git ()
send-email) _git_send_email ;;
shortlog) _git_shortlog ;;
show) _git_show ;;
- show-branch) _git_log ;;
+ show-branch) _git_show_branch ;;
stash) _git_stash ;;
submodule) _git_submodule ;;
svn) _git_svn ;;
--
1.6.0.rc0.16.g0680f
^ permalink raw reply related
* [PATCH 8/9] builtin-fetch-pack.c: use parse_options()
From: Michele Ballabio @ 2008-07-23 21:42 UTC (permalink / raw)
To: git; +Cc: gitster
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-fetch-pack.c | 144 +++++++++++++++++++++++++++++++-------------------
1 files changed, 90 insertions(+), 54 deletions(-)
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 273239a..701be41 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -9,6 +9,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "run-command.h"
+#include "parse-options.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -17,8 +18,10 @@ static struct fetch_pack_args args = {
/* .uploadpack = */ "git-upload-pack",
};
-static const char fetch_pack_usage[] =
-"git fetch-pack [--all] [--quiet|-q] [--keep|-k] [--thin] [--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] [--no-progress] [-v] [<host>:]<directory> [<refs>...]";
+static const char * const fetch_pack_usage[] = {
+ "git fetch-pack [options] [<host>:]<directory> [<refs>...]",
+ NULL
+};
#define COMPLETE (1U << 0)
#define COMMON (1U << 1)
@@ -667,6 +670,56 @@ static void fetch_pack_setup(void)
did_setup = 1;
}
+static int parse_opt_keep_pack_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->lock_pack = t_args->keep_pack;
+ t_args->keep_pack = 1;
+ return 0;
+}
+
+static int parse_opt_thin_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->use_thin_pack = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_include_tag_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->include_tag = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_no_progress_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->no_progress = 1;
+ return 0;
+}
+
+static int parse_opt_fetch_all_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->fetch_all = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_quiet_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->quiet = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_verbose_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->verbose = unset ? 0 : 1;
+ return 0;
+}
+
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
{
int i, ret, nr_heads;
@@ -677,60 +730,43 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
nr_heads = 0;
heads = NULL;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- if (*arg == '-') {
- if (!prefixcmp(arg, "--upload-pack=")) {
- args.uploadpack = arg + 14;
- continue;
- }
- if (!prefixcmp(arg, "--exec=")) {
- args.uploadpack = arg + 7;
- continue;
- }
- if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
- args.quiet = 1;
- continue;
- }
- if (!strcmp("--keep", arg) || !strcmp("-k", arg)) {
- args.lock_pack = args.keep_pack;
- args.keep_pack = 1;
- continue;
- }
- if (!strcmp("--thin", arg)) {
- args.use_thin_pack = 1;
- continue;
- }
- if (!strcmp("--include-tag", arg)) {
- args.include_tag = 1;
- continue;
- }
- if (!strcmp("--all", arg)) {
- args.fetch_all = 1;
- continue;
- }
- if (!strcmp("-v", arg)) {
- args.verbose = 1;
- continue;
- }
- if (!prefixcmp(arg, "--depth=")) {
- args.depth = strtol(arg + 8, NULL, 0);
- continue;
- }
- if (!strcmp("--no-progress", arg)) {
- args.no_progress = 1;
- continue;
- }
- usage(fetch_pack_usage);
- }
- dest = (char *)arg;
- heads = (char **)(argv + i + 1);
- nr_heads = argc - i - 1;
- break;
- }
+ const struct option options[] = {
+ { OPTION_CALLBACK, 0, "all", &args, NULL,
+ "fetch all remote refs", PARSE_OPT_NOARG,
+ parse_opt_fetch_all_cb },
+ OPT_STRING(0, "upload-pack", &args.uploadpack, "git-upload-pack",
+ "specify path to git-upload-pack on remote"),
+ OPT_STRING(0, "exec", &args.uploadpack, "git-upload-pack",
+ "same as --upload-pack <git-upload-pack>."),
+ { OPTION_CALLBACK, 0, "no-progress", &args, NULL,
+ "do not show the progress", PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ parse_opt_no_progress_cb },
+ { OPTION_CALLBACK, 'q', "quiet", &args, NULL,
+ "be quiet", PARSE_OPT_NOARG, parse_opt_quiet_cb },
+ { OPTION_CALLBACK, 'v', "verbose", &args, NULL,
+ "be verbose", PARSE_OPT_NOARG, parse_opt_verbose_cb },
+ OPT_INTEGER(0, "depth", &args.depth, "fetch chains not longer than <n>"),
+ { OPTION_CALLBACK, 'k', "keep", &args, NULL,
+ "create a single packfile of received data",
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_keep_pack_cb },
+ { OPTION_CALLBACK, 0, "include-tag", &args, NULL,
+ "download annotated tags too", PARSE_OPT_NOARG,
+ parse_opt_include_tag_cb },
+ { OPTION_CALLBACK, 0, "thin", &args, NULL,
+ "minimize number of objects to be sent",
+ PARSE_OPT_NOARG, parse_opt_thin_cb },
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, fetch_pack_usage, 0);
+
+ dest = (char *)argv[0];
+ heads = (char **)(argv + 1);
+ nr_heads = argc - 1;
+
if (!dest)
- usage(fetch_pack_usage);
+ usage_with_options(fetch_pack_usage, options);
conn = git_connect(fd, (char *)dest, args.uploadpack,
args.verbose ? CONNECT_VERBOSE : 0);
--
1.5.6.3
^ permalink raw reply related
* Re: HP-UX issues (WAS: Re: [RFC] Git User's Survey 2008)
From: Jakub Narebski @ 2008-07-23 21:38 UTC (permalink / raw)
To: Miklos Vajna; +Cc: Junio C Hamano, git
In-Reply-To: <20080723074747.GA32057@genesis.frugalware.org>
On Wed, 23 July 2008, Miklos Vajna wrote:
> Being more constructive, what a user using HP-UX is supported to do?
>
> 1) Use the patched git from HP.
>
> 2) Have coreutils installed. (But then I think it would be good to list
> this dependency in INSTALL.)
It would be good idea, although "POSIX-compliant shells" implies
coreutils somewhat; shell scripts usually do require some utilities,
like sed, grep, cat, test etc.
> 3) Patch git to use automake's install-sh. (Would such a patch be ever
> accepted?)
I think it would. It would allow us also to uncomment the
AC_PROG_INSTALL line in configure.ac file to find 'install'
automatically (autoconf requires having install.sh or install-sh
fallback in the sources).
The problem is coming up with minimal yet portable (at least as
portable as git itself) fallback install.sh script.
--
Jakub Narebski
Poland
^ permalink raw reply
* Re: [RFC] Git User's Survey 2008
From: Petr Baudis @ 2008-07-23 21:44 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git, Stephan Beyer
In-Reply-To: <200807230325.04184.jnareb@gmail.com>
On Wed, Jul 23, 2008 at 03:25:03AM +0200, Jakub Narebski wrote:
> 18. Which (main) git web interface do you use for your projects?
> (zero or more: multiple choice)
> - gitweb, cgit, wit (Ruby), git-php, viewgit (PHP), other
> + should there be a question about web server (Apache, IIS, ...)
> used to host git web interface?
> 18b.If you selected "other web interface", what it was?
> (free form)
I think many people "just use GitHub", or repo.or.cz, or Gitorious; for
GitHub or Gitorious, there's even no good answer to the question above.
So I would either make a separate question for these or include them in
the list above.
> 19. How do you publish/propagate your changes?
> (zero or more: multiple choice)
> - push, pull request, format-patch + email, bundle, other
I agree about the git-svn mention.
Petr "Pasky" Baudis
^ permalink raw reply
* Re: [PATCH 2/2] sort_in_topological_order(): avoid setting a commit flag
From: Petr Baudis @ 2008-07-23 21:49 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
In-Reply-To: <7v7ibdifbp.fsf@gitster.siamese.dyndns.org>
On Tue, Jul 22, 2008 at 06:01:30PM -0700, Junio C Hamano wrote:
> Do people still actively use show-branch as a G/CUI, especially after that
> "log --graph" thing was introduced?
To me, show-branch is just more convenient to use; I can see more easily
which patches are with which branches, which is useful especially for my
new sick-twisted use of feature branches for individual patches, thus
having a lot of interdependencies.
> If that is the case, it might also make sense to stop using the object
> flags but allocate necessary number of bits (not restricted to 25 or so)
> pointed at by commit->util field to remove its limitation.
>
> Hint, hint...
Maybe I will hit it soon... ;-)
--
Petr "Pasky" Baudis
As in certain cults it is possible to kill a process if you know
its true name. -- Ken Thompson and Dennis M. Ritchie
^ permalink raw reply
* Re: [RFC] Git User's Survey 2008
From: Jakub Narebski @ 2008-07-23 21:49 UTC (permalink / raw)
To: Dmitry Potapov; +Cc: git
In-Reply-To: <20080723143810.GR2925@dpotapov.dyndns.org>
On Wed, 23 Jul 2008, Dmitry Potapov wrote:
> On Wed, Jul 23, 2008 at 03:25:03AM +0200, Jakub Narebski wrote:
> >
> > 02. What is your preferred non-programming language?
> > (or) What is the language you want computer communicate with you?
>
> IMHO, the later wording of the question is much better.
First just satisfies demographic curiosity. Second is more question
about internationalization (i18n).
I'm not sure however if it is worth it, and not just simply remove
this question from the survey.
> > 05. How did you hear about Git?
> > (single choice?, in 2007 it was free-form)
> > - Linux kernel news (LKML, LWN, KernelTrap, KernelTraffic,...),
> > news site or magazine, blog entry, some project uses it,
> > presentation or seminar (real life, not on-line), SCM research,
> > IRC, mailing list, other Internet, other off-line, other(*)
>
> I think "friend" would be a reasonable choice here too.
Or: "word of mouth (off-line)". Good catch, thanks.
> > 09. When did you start using git? From which version?
> > - pre 1.0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
> > + might be important when checking "what did you find hardest" etc.
> > + perhaps we should ask in addition to this question, or in place
> > of this question (replacing it) what git version one uses; it
> > should be multiple choice, and allow 'master', 'next', 'pu',
> > 'dirty (with own modifications)' versions in addition.
>
> I think: "What version do you use now?" and "How long do you use git?"
> may be more useful here. From which version may give rather confusing
> results because someone may "start" with 1.4 a week ago just because
> that is the version included in Debian Etch and after realizing that
> version 1.4 has serious usability issues upgraded git to 1.5. Besides,
> 1.5 is around for a long time now (as most as long as all previous
> versions), so 1.5 can mean either one month of usage or 18 months...
Good idea (provided that for "How long do you use git?" there is an
answer "Don't remember").
Should "What version do you use now?" be multiple choice (using git
on more than one machine / operating system)? What should be possible
choices for "How long do you use git?"? Perhaps.
10. How long do you use git?
(single choice)
- never/few days/few weeks/month/few months/year/few years/
from beginning/I wrote it(*)
+ (*) just kidding ;-)
--
Jakub Narebski
Poland
^ 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