summaryrefslogtreecommitdiff
path: root/builtin-name-rev.c
AgeCommit message (Collapse)AuthorFilesLines
2008-08-03Merge branch 'maint'Libravatar Junio C Hamano1-7/+5
* maint: git-name-rev: don't use printf without format
2008-08-03git-name-rev: don't use printf without formatLibravatar René Scharfe1-7/+5
printf() without an explicit format string is not a good coding practise, unless the printed string is guaranteed to not contain percent signs. While fixing this, we might as well combine the calls to fwrite() and printf(). Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-02Merge branch 'maint'Libravatar Junio C Hamano1-37/+46
* maint: git-name-rev: allow --name-only in combination with --stdin builtin-name-rev.c: split deeply nested part from the main function Conflicts: Documentation/git-name-rev.txt
2008-08-02git-name-rev: allow --name-only in combination with --stdinLibravatar Pieter de Bie1-2/+7
Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-02builtin-name-rev.c: split deeply nested part from the main functionLibravatar Junio C Hamano1-37/+41
The main function of this command implementation tries to do too many things. Split out a handling of single input line into a separate function to reduce nesting level and clutter. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-13Make usage strings dash-lessLibravatar Stephan Beyer1-1/+1
When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-06Merge branch 'maint'Libravatar Junio C Hamano1-2/+6
* maint: git-for-each-ref.txt: minor improvements name-rev: Fix segmentation fault when using --all
2008-06-05name-rev: Fix segmentation fault when using --allLibravatar Björn Steinbrink1-2/+6
In commit da2478db "describe --always: fall back to showing an abbreviated object name" we lost the check that skips empty entries in the object hash table when iterating over it in cmd_name_rev. That may cause a NULL pointer being handed to show_name(), leading to a segmentation fault. So add that check back again. Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-14Provide git_config with a callback-data parameterLibravatar Johannes Schindelin1-1/+1
git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-03describe --always: fall back to showing an abbreviated object nameLibravatar Junio C Hamano1-29/+30
Some callers may find it useful if "git describe" always gave back a string that can be used as a shorter name for a commit object, rather than checking its exit status (while squelching its error message, which could potentially talk about more grave errors that should not be squelched) and implementing a fallback themselves. This teaches describe/name-rev a new option, --always, to use an abbreviated object name when no tags or refs to use is found. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-12-26git-name-rev: add a --(no-)undefined option.Libravatar Pierre Habouzit1-10/+24
Rework get_rev_name to return NULL rather than "undefined" when a reference is undefined. If --undefined is passed (default), git-name-rev prints "undefined" for the name, else it die()s. Make git-describe use --no-undefined when calling git-name-rev so that --contains behavior matches the standard git-describe one. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-10-29Make builtin-name-rev.c use parse_options.Libravatar Pierre Habouzit1-39/+25
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-08-27name-rev: Fix non-shortest descriptionLibravatar Johannes Schindelin1-10/+11
Uwe Kleine-König noticed that under certain circumstances, name-rev picked a non-optimal tag. Jeff King analyzed that name-rev only takes into account the number of merge traversals, and then the _last_ number in the description. As an easy way to fix it, use a weighting factor for merge traversals: A merge traversal is now made 65535 times more expensive than a first-parent traversal. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-07War on whitespaceLibravatar Junio C Hamano1-1/+0
This uses "git-apply --whitespace=strip" to fix whitespace errors that have crept in to our source files over time. There are a few files that need to have trailing whitespaces (most notably, test vectors). The results still passes the test, and build result in Documentation/ area is unchanged. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-05-24Merge branch 'maint'Libravatar Junio C Hamano1-0/+4
* maint: fix memory leak in parse_object when check_sha1_signature fails name-rev: tolerate clock skew in committer dates Update bash completion for git-config options Teach bash completion about recent log long options Teach bash completion about 'git remote update' Update bash completion header documentation Remove a duplicate --not option in bash completion Teach bash completion about git-shortlog Hide the plumbing diff-{files,index,tree} from bash completion Update bash completion to ignore some more plumbing commands
2007-05-24name-rev: tolerate clock skew in committer datesLibravatar Junio C Hamano1-0/+4
In git.git repository, "git-name-rev v1.3.0~158" cannot name the rev, while adjacent revs can be named. This was because it gives up traversal from the tips of existing refs as soon as it sees a commit that has older commit timestamp than what is being named. This is usually a good heuristics, but v1.3.0~158 has a slightly older commit timestamp than v1.3.0~157 (i.e. it's child), as these two were made in a separate repostiory (in fact, in a different continent). This adds a hardcoded slop value (1 day) to the cut-off heuristics to work this kind of problem around. The current algorithm essentially runs around from the available tips down to ancient commits and names every single rev available that are newer than cut-off date, so a single day slop would not add that much overhead in repositories with long enough history where the performance of name-rev matters. I think the algorithm could be made a bit smarter by deepening the graph on demand as a new commit is asked to be named (this would require rewriting of name_rev() function not to recurse itself but use a traversal list like revision.c traverser does), but that would be a separate issue. Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-21Teach git-describe how to run name-revLibravatar Shawn O. Pearce1-6/+17
Often users want to know not which tagged version a commit came after, but which tagged version a commit is contained within. This latter task is the job of git-name-rev, but most users are looking to git-describe to do the job. Junio suggested we make `git describe --contains` run the correct tool, `git name-rev`, and that's exactly what we do here. The output of name-rev was adjusted slightly through the new --name-only option, allowing describe to execv into name-rev and maintain its current output format. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-15git name-rev writes beyond the end of malloc() with large generationsLibravatar Andy Whitcroft1-1/+4
When using git name-rev on my kernel tree I triggered a malloc() corruption warning from glibc. apw@pinky$ git log --pretty=one $N/base.. | git name-rev --stdin *** glibc detected *** malloc(): memory corruption: 0x0bff8950 *** Aborted This comes from name_rev() which is building the name of the revision in a malloc'd string, which it sprintf's into: char *new_name = xmalloc(len + 8); [...] sprintf(new_name, "%.*s~%d^%d", len, tip_name, generation, parent_number); This allocation is only sufficient if the generation number is less than 5 digits, in my case generation was 13432. In reality parent_number can be up to 16 so that also can require two digits, reducing us to 3 digits before we are at risk of blowing this allocation. This patch introduces a decimal_length() which approximates the number of digits a type may hold, it produces the following: Type Longest Value Len Est ---- ------------- --- --- unsigned char 256 3 4 unsigned short 65536 5 6 unsigned long 4294967296 10 11 unsigned long long 18446744073709551616 20 21 char -128 4 4 short -32768 6 6 long -2147483648 11 11 long long -9223372036854775808 20 21 This is then used to size the new_name. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20Merge branch 'js/name-rev-fix'Libravatar Junio C Hamano1-7/+16
* js/name-rev-fix: name-rev: avoid "^0" when unneeded
2007-02-20Mechanical conversion to use prefixcmp()Libravatar Junio C Hamano1-4/+4
This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-19name-rev: avoid "^0" when unneededLibravatar Johannes Schindelin1-7/+16
When naming by a tag, we used to add "^0" even if this was not really necessary. For example, `git name-rev de6f0def` now outputs de6f0def tags/v1.5.0.1~9 instead of de6f0def tags/v1.5.0.1^0~9 Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-17name-rev: introduce the --refs=<pattern> optionLibravatar Johannes Schindelin1-6/+17
Instead of (or, in addition to) --tags, to use only tags for naming, you can now use --refs=<pattern> to specify a shell glob pattern which the refs must match to be used for naming. Example: $ git name-rev --refs=*v1* 33db5f4d 33db5f4d tags/v1.0rc1^0~1593 Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-20simplify inclusion of system header files.Libravatar Junio C Hamano1-1/+0
This is a mechanical clean-up of the way *.c files include system header files. (1) sources under compat/, platform sha-1 implementations, and xdelta code are exempt from the following rules; (2) the first #include must be "git-compat-util.h" or one of our own header file that includes it first (e.g. config.h, builtin.h, pkt-line.h); (3) system headers that are included in "git-compat-util.h" need not be included in individual C source files. (4) "git-compat-util.h" does not have to include subsystem specific header files (e.g. expat.h). Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-20Tell between packed, unpacked and symbolic refs.Libravatar Junio C Hamano1-1/+1
This adds a "int *flag" parameter to resolve_ref() and makes for_each_ref() family to call callback function with an extra "int flag" parameter. They are used to give two bits of information (REF_ISSYMREF and REF_ISPACKED) about the ref. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-20Add callback data to for_each_ref() family.Libravatar Junio C Hamano1-4/+4
This is a long overdue fix to the API for for_each_ref() family of functions. It allows the callers to specify a callback data pointer, so that the caller does not have to use static variables to communicate with the callback funciton. The updated for_each_ref() family takes a function of type int (*fn)(const char *, const unsigned char *, void *) and a void pointer as parameters, and calls the function with the name of the ref and its SHA-1 with the caller-supplied void pointer as parameters. The commit updates two callers, builtin-name-rev.c and builtin-pack-refs.c as an example. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-02Replace uses of strdup with xstrdup.Libravatar Shawn Pearce1-1/+1
Like xmalloc and xrealloc xstrdup dies with a useful message if the native strdup() implementation returns NULL rather than a valid pointer. I just tried to use xstrdup in new code and found it to be missing. However I expected it to be present as xmalloc and xrealloc are already commonly used throughout the code. [jc: removed the part that deals with last_XXX, which I am finding more and more dubious these days.] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-15remove unnecessary initializationsLibravatar David Rientjes1-1/+1
[jc: I needed to hand merge the changes to the updated codebase, so the result needs to be checked.] Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-03Make git-name-rev a builtinLibravatar Matthias Kestenholz1-0/+256
Signed-off-by: Matthias Kestenholz <matthias@spinlock.ch> Signed-off-by: Junio C Hamano <junkio@cox.net>