summaryrefslogtreecommitdiff
path: root/sha1_name.c
AgeCommit message (Collapse)Author
2008-03-15Merge branch 'maint'Junio C Hamano
* maint: Make man page building quiet when DOCBOOK_XSL_172 is defined git-new-workdir: Share SVN meta data between work dirs and the repository rev-parse: fix meaning of rev~ vs rev~0. git-svn: don't blindly append '*' to branch/tags config
2008-03-15rev-parse: fix meaning of rev~ vs rev~0.Linus Torvalds
I think it would make more sense for rev~ to have the same guarantees that rev^ has, namely to always return a commit. I would also suggest that not giving a number would have the same effect of defaulting to 1, not 0. Right now it's a bit illogical, but at least it's an _undocumented_ illogical behaviour. This patch makes '^' and '~' act the same for the default count (i.e. both default to 1), and also have the same behaviour for a count of zero. Before (no discernible pattern): [torvalds@woody git]$ git rev-parse v1.5.1 v1.5.1^0 v1.5.1~0 v1.5.1^ v1.5.1~ 45354a57ee7e3e42c7137db6c94fa968c6babe8d 89815cab95268e8f0f58142b848ac4cd5e9cbdcb 45354a57ee7e3e42c7137db6c94fa968c6babe8d 045f5759c97746589a067461e50fad16f60711ac 45354a57ee7e3e42c7137db6c94fa968c6babe8d After (fairly logical): [torvalds@woody git]$ git rev-parse v1.5.1 v1.5.1^0 v1.5.1~0 v1.5.1^ v1.5.1~ 45354a57ee7e3e42c7137db6c94fa968c6babe8d 89815cab95268e8f0f58142b848ac4cd5e9cbdcb 89815cab95268e8f0f58142b848ac4cd5e9cbdcb 045f5759c97746589a067461e50fad16f60711ac 045f5759c97746589a067461e50fad16f60711ac Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-11Merge branch 'jc/cherry-pick' (early part)Junio C Hamano
* 'jc/cherry-pick' (early part): expose a helper function peel_to_type(). merge-recursive: split low-level merge functions out. Conflicts: Makefile builtin-merge-recursive.c sha1_name.c
2008-03-02find_unique_abbrev(): redefine semanticsJunio C Hamano
The function returned NULL when no object that matches the name was found, but that made the callers more complicated, as nobody used that NULL return as an indication that no object with such a name exists. They (at least the careful ones) instead took the full 40-hexdigit and used in such a case, and the careless ones segfaulted. With this "git rev-parse --short 5555555555555555555555555555555555555555" would stop segfaulting. This is based on Jeff King's rewrite to my RFC patch, but "missing" logic swapped to "exists". The final logic reads: For existing objects, make sure the abbreviated string uniquely identifies it. Otherwise, make sure the abbreviated string is long enough so that it would not name any existing object. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-22Avoid unnecessary "if-before-free" tests.Jim Meyering
This change removes all obvious useless if-before-free tests. E.g., it replaces code like this: if (some_expression) free (some_expression); with the now-equivalent: free (some_expression); It is equivalent not just because POSIX has required free(NULL) to work for a long time, but simply because it has worked for so long that no reasonable porting target fails the test. Here's some evidence from nearly 1.5 years ago: http://www.winehq.org/pipermail/wine-patches/2006-October/031544.html FYI, the change below was prepared by running the following: git ls-files -z | xargs -0 \ perl -0x3b -pi -e \ 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\(\s*\1\s*\))/$2/s' Note however, that it doesn't handle brace-enclosed blocks like "if (x) { free (x); }". But that's ok, since there were none like that in git sources. Beware: if you do use the above snippet, note that it can produce syntactically invalid C code. That happens when the affected "if"-statement has a matching "else". E.g., it would transform this if (x) free (x); else foo (); into this: free (x); else foo (); There were none of those here, either. If you're interested in automating detection of the useless tests, you might like the useless-if-before-free script in gnulib: [it *does* detect brace-enclosed free statements, and has a --name=S option to make it detect free-like functions with different names] http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=build-aux/useless-if-before-free Addendum: Remove one more (in imap-send.c), spotted by Jean-Luc Herren <jlh@gmx.ch>. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-19Merge branch 'mk/maint-parse-careful'Junio C Hamano
* mk/maint-parse-careful: peel_onion: handle NULL check return value from parse_commit() in various functions parse_commit: don't fail, if object is NULL revision.c: handle tag->tagged == NULL reachable.c::process_tree/blob: check for NULL process_tag: handle tag->tagged == NULL check results of parse_commit in merge_bases list-objects.c::process_tree/blob: check for NULL reachable.c::add_one_tree: handle NULL from lookup_tree mark_blob/tree_uninteresting: check for NULL get_sha1_oneline: check return value of parse_object read_object_with_reference: don't read beyond the buffer
2008-02-19peel_onion: handle NULLMartin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-19get_sha1_oneline: check return value of parse_objectMartin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-18expose a helper function peel_to_type().Junio C Hamano
This helper function is the core of "$object^{type}" parser. Now it is made available to callers outside sha1_name.c
2008-02-18deref_tag: handle return value NULLMartin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-21Make on-disk index representation separate from in-core oneLinus Torvalds
This converts the index explicitly on read and write to its on-disk format, allowing the in-core format to contain more flags, and be simpler. In particular, the in-core format is now host-endian (as opposed to the on-disk one that is network endian in order to be able to be shared across machines) and as a result we can dispense with all the htonl/ntohl on accesses to the cache_entry fields. This will make it easier to make use of various temporary flags that do not exist in the on-disk format. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-12-05Merge branch 'sp/refspec-match'Junio C Hamano
* sp/refspec-match: refactor fetch's ref matching to use refname_match() push: use same rules as git-rev-parse to resolve refspecs add refname_match() push: support pushing HEAD to real branch name
2007-12-04Allow ':/<oneline-prefix>' syntax to work with save_commit_buffer == 0Johannes Schindelin
Earlier, ':/<oneline-prefix>' would not work (i.e. die) with commands that set save_commit_buffer = 0, such as blame, describe, pack-objects, reflog and bundle. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-19add refname_match()Steffen Prohaska
We use at least two rulesets for matching abbreviated refnames with full refnames (starting with 'refs/'). git-rev-parse and git-fetch use slightly different rules. This commit introduces a new function refname_match (const char *abbrev_name, const char *full_name, const char **rules). abbrev_name is expanded using the rules and matched against full_name. If a match is found the function returns true. rules is a NULL-terminate list of format patterns with "%.*s", for example: const char *ref_rev_parse_rules[] = { "%.*s", "refs/%.*s", "refs/tags/%.*s", "refs/heads/%.*s", "refs/remotes/%.*s", "refs/remotes/%.*s/HEAD", NULL }; Asterisks are included in the format strings because this is the form required in sha1_name.c. Sharing the list with the functions there is a good idea to avoid duplicating the rules. Hopefully this facilitates unified matching rules in the future. This commit makes the rules used by rev-parse for resolving refs to sha1s available for string comparison. Before this change, the rules were buried in get_sha1*() and dwim_ref(). A follow-up commit will refactor the rules used by fetch. refname_match() will be used for matching refspecs in git-send-pack. Thanks to Daniel Barkalow <barkalow@iabervon.org> for pointing out that ref_matches_abbrev in remote.c solves a similar problem and care should be taken to avoid confusion. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-07-14Make show_rfc2822_date() just another date output format.Junio C Hamano
These days, show_date() takes a date_mode parameter to specify the output format, and a separate specialized function for dates in E-mails does not make much sense anymore. This retires show_rfc2822_date() function and make it just another date output format. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-08Active_nr is unsigned, hence can't be < 0Pierre Habouzit
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-05-30rev-parse: Identify short sha1 sums correctly.James Bowes
find_short_packed_object was not loading the pack index files. Teach it to do so. Signed-off-by: James Bowes <jbowes@dangerouslyinc.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-27Attempt to delay prepare_alt_odb during get_sha1Shawn O. Pearce
Not every input value passed to get_sha1 is an abbreviated SHA-1. Its actually quite common for refs to be passed and for those refs to resolve to full SHA-1s, in which case we may not need to initialize the alternate object database list in this process. I'm relocating the call to prepare_alt_odb closer to the code that actually needs it to maintain the fix first introduced by Junio in 99a19b43 (to avoid ambiguous SHA-1 abbreviations from being accepted). This allows us to avoid the alt_odb list setup if we won't actually need it. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-24add get_sha1_with_modeMartin Koegler
get_sha1_with_mode basically behaves as get_sha1. It has an additional parameter for storing the mode of the object. If the mode can not be determined, it stores S_IFINVALID. Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-10get rid of num_packed_objects()Nicolas Pitre
The coming index format change doesn't allow for the number of objects to be determined from the size of the index file directly. Instead, Let's initialize a field in the packed_git structure with the object count when the index is validated since the count is always known at that point. While at it let's reorder some struct packed_git fields to avoid padding due to needed 64-bit alignment for some of them. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-05clean up and optimize nth_packed_object_sha1() usageNicolas Pitre
Let's avoid the open coded pack index reference in pack-object and use nth_packed_object_sha1() instead. This will help encapsulating index format differences in one place. And while at it there is no reason to copy SHA1's over and over while a direct pointer to it in the index will do just fine. Signed-off-by: Nicolas Pitre <nico@cam.org> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-12Re-fix get_sha1_oneline()Linus Torvalds
What the function wants to return is not if we saw any return from pop_most_recent_commit(), but if we found what was asked for. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-11I like the idea of the new ':/<oneline prefix>' notation, and gave itJim Meyering
a try, but all I could get was a segfault. It was dereferencing a NULL commit list. Fix below. With it, this example now works: $ mkdir .j; cd .j; touch f $ git-init; git-add f; git-commit -mc f; echo x >f; git-commit -md f $ git-diff -p :/c :/d diff --git a/f b/f index e69de29..587be6b 100644 --- a/f +++ b/f @@ -0,0 +1 @@ +x Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-07Use uint32_t for all packed object counts.Shawn O. Pearce
As we permit up to 2^32-1 objects in a single packfile we cannot use a signed int to represent the object offset within a packfile, after 2^31-1 objects we will start seeing negative indexes and error out or compute bad addresses within the mmap'd index. This is a minor cleanup that does not introduce any significant logic changes. It is roach free. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-24object name: introduce ':/<oneline prefix>' notationJohannes Schindelin
To name a commit, you can now say $ git rev-parse ':/Initial revision of "git"' and it will return the hash of the youngest commit whose commit message (the oneline) begins with the given prefix. For future extension, a leading exclamation mark is treated specially: if you want to match a commit message starting with a '!', just repeat the exclamation mark. So, to match a commit which starts with '!Hello World', use $ git show ':/!!Hello World' Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-09reflog: handle $name => remotes/%s/HEAD mapping consistently for logsJunio C Hamano
When refs/remotes/gfi/master and refs/remotes/gfi/HEAD exist, and the latter is a symref that points at the former, dwim_ref() resolves string "gfi" to "refs/remotes/gfi/master" as expected, but dwim_log() does not understand "gfi@{1.day}" and needs to be told "gfi/master@{1.day}". This is confusing. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-09log --reflog: use dwim_logJohannes Schindelin
Since "git log origin/master" uses dwim_log() to match "refs/remotes/origin/master", it makes sense to do that for "git log --reflog", too. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-04Enable HEAD@{...} and make it independent from the current branchNicolas Pitre
Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-02provide a nice @{...} syntax to always mean the current branch reflogNicolas Pitre
This is shorter than HEAD@{...} and being nameless it has no semantic issues. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-02prevent HEAD reflog to be interpreted as current branch reflogNicolas Pitre
The work in progress to enable separate reflog for HEAD will make it independent from reflog of any branch HEAD might be pointing to. In the mean time disallow HEAD@{...} until that work is completed. Otherwise people might get used to the current behavior which makes HEAD@{...} an alias for <current_branch>@{...} which won't be the case later. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-20Extend read_ref_at() to be usable from places other than sha1_name.Junio C Hamano
You can pass an extra argument to the function to receive the reflog message information. Also when the log does not go back beyond the point the user asked, the cut-off time and count are given back to the caller for emitting the error messages as appropriately. We could later add configuration for get_sha1_basic() to make it an error instead of it being just a warning. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-20dwim_ref(): Separate name-to-ref DWIM code out.Junio C Hamano
I'll be using this in another function to figure out what to pass to resolve_ref(). Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-11-01Merge branch 'lj/refs'Junio C Hamano
* lj/refs: (63 commits) Fix show-ref usagestring t3200: git-branch testsuite update sha1_name.c: avoid compilation warnings. Make git-branch a builtin ref-log: fix D/F conflict coming from deleted refs. git-revert with conflicts to behave as git-merge with conflicts core.logallrefupdates thinko-fix git-pack-refs --all core.logallrefupdates create new log file only for branch heads. Remove bashism from t3210-pack-refs.sh ref-log: allow ref@{count} syntax. pack-refs: call fflush before fsync. pack-refs: use lockfile as everybody else does. git-fetch: do not look into $GIT_DIR/refs to see if a tag exists. lock_ref_sha1_basic does not remove empty directories on BSD Do not create tag leading directories since git update-ref does it. Check that a tag exists using show-ref instead of looking for the ref file. Use git-update-ref to delete a tag instead of rm()ing the ref file. Fix refs.c;:repack_without_ref() clean-up path Clean up "git-branch.sh" and add remove recursive dir test cases. ...
2006-10-24sha1_name.c: avoid compilation warnings.Junio C Hamano
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-19Reject hexstring longer than 40-bytes in get_short_sha1()pclouds@gmail.com
Such a string can never be a valid object name. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-06ref-log: allow ref@{count} syntax.Junio C Hamano
Often I find myself wanting to say 'tip of "next" before I merged the last three topics'. Now I can say that with: git log next@{3}..next Since small integers alone are invalid input strings to approxidate, there is no fear of confusion. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-28Merge branch 'master' into lj/refsJunio C Hamano
* master: (72 commits) runstatus: do not recurse into subdirectories if not needed grep: fix --fixed-strings combined with expression. grep: free expressions and patterns when done. Corrected copy-and-paste thinko in ignore executable bit test case. An illustration of rev-list --parents --pretty=raw Allow git-checkout when on a non-existant branch. gitweb: Decode long title for link tooltips git-svn: Fix fetch --no-ignore-externals with GIT_SVN_NO_LIB=1 Ignore executable bit when adding files if filemode=0. Remove empty ref directories that prevent creating a ref. Use const for interpolate arguments git-archive: update documentation Deprecate merge-recursive.py gitweb: fix over-eager application of esc_html(). Allow '(no author)' in git-svn's authors file. Allow 'svn fetch' on '(no date)' revisions in Subversion. git-repack: allow git-repack to run in subdirectory Remove upload-tar and make git-tar-tree a thin wrapper to git-archive git-tar-tree: Move code for git-archive --format=tar to archive-tar.c git-tar-tree: Remove duplicate git_config() call ...
2006-09-21Tell between packed, unpacked and symbolic refs.Junio C Hamano
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-20sha1_name.c: understand "describe" output as a valid object nameJunio C Hamano
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-18Make ref resolution sanerLinus Torvalds
The old code used to totally mix up the notion of a ref-name and the path that that ref was associated with. That was not only horribly ugly (a number of users got the path, and then wanted to try to turn it back into a ref-name again), but it fundamnetally doesn't work at all once we do any setup where a ref doesn't have a 1:1 relationship with a particular pathname. This fixes things up so that we use the ref-name throughout, and only turn it into a pathname once we actually look it up in the filesystem. That makes a lot of things much clearer and more straightforward. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-02Replace uses of strdup with xstrdup.Shawn Pearce
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-23Convert memset(hash,0,20) to hashclr(hash).Junio C Hamano
In the same spirit as hashcmp() and hashcpy(). Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-23Convert memcpy(a,b,20) to hashcpy(a,b).Shawn Pearce
This abstracts away the size of the hash values when copying them from memory location to memory location, much as the introduction of hashcmp abstracted away hash value comparsion. A few call sites were using char* rather than unsigned char* so I added the cast rather than open hashcpy to be void*. This is a reasonable tradeoff as most call sites already use unsigned char* and the existing hashcmp is also declared to be unsigned char*. [jc: Splitted the patch to "master" part, to be followed by a patch for merge-recursive.c which is not in "master" yet. Fixed the cast in the latter hunk to combine-diff.c which was wrong in the original. Also converted ones left-over in combine-diff.c, diff-lib.c and upload-pack.c ] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-17Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.David Rientjes
Introduces global inline: hashcmp(const unsigned char *sha1, const unsigned char *sha2) Uses memcmp for comparison and returns the result based on the length of the hash name (a future runtime decision). Acked-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-15make inline is_null_sha1 globalDavid Rientjes
Replace sha1 comparisons to null_sha1 with a global inline (which previously an unused static inline in builtin-apply.c) [jc: with a fix from Jonas Fonseca.] Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-09find_unique_abbrev() with len=0 should not abbreviateJunio C Hamano
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-13Remove TYPE_* constant macros and use object_type enums consistently.Linus Torvalds
This updates the type-enumeration constants introduced to reduce the memory footprint of "struct object" to match the type bits already used in the packfile format, by removing the former (i.e. TYPE_* constant macros) and using the latter (i.e. enum object_type) throughout the code for consistency. Eventually we can stop passing around the "type strings" entirely, and this will help - no confusion about two different integer enumeration. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-25Rename safe_strncpy() to strlcpy().Peter Eriksen
This cleans up the use of safe_strncpy() even more. Since it has the same semantics as strlcpy() use this name instead. Also move the definition from inside path.c to its own file compat/strlcpy.c, and use it conditionally at compile time, since some platforms already has strlcpy(). It's included in the same way as compat/setenv.c. Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-18Shrink "struct object" a bitLinus Torvalds
This shrinks "struct object" by a small amount, by getting rid of the "struct type *" pointer and replacing it with a 3-bit bitfield instead. In addition, we merge the bitfields and the "flags" field, which incidentally should also remove a useless 4-byte padding from the object when in 64-bit mode. Now, our "struct object" is still too damn large, but it's now less obviously bloated, and of the remaining fields, only the "util" (which is not used by most things) is clearly something that should be eventually discarded. This shrinks the "git-rev-list --all" memory use by about 2.5% on the kernel archive (and, perhaps more importantly, on the larger mozilla archive). That may not sound like much, but I suspect it's more on a 64-bit platform. There are other remaining inefficiencies (the parent lists, for example, probably have horrible malloc overhead), but this was pretty obvious. Most of the patch is just changing the comparison of the "type" pointer from one of the constant string pointers to the appropriate new TYPE_xxx small integer constant. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-17Implement safe_strncpy() as strlcpy() and use it more.Peter Eriksen
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>