1. 28 6月, 2009 1 次提交
  2. 26 5月, 2009 1 次提交
    • J
      lock_ref: inform callers of unavailable ref · f475e08e
      Jeff King 提交于
      One of the ways that locking might fail is that there is a
      DF conflict between two refs (e.g., you want to lock
      "foo/bar" but "foo" already exists). In this case, we return
      an error, but there is no way for the caller to know the
      specific problem.
      
      This patch sets errno to ENOTDIR, which is the most sensible
      code. It's what we would see if the refs were stored purely
      in the filesystem (but these days we must check the
      namespace manually due to packed refs).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f475e08e
  3. 14 5月, 2009 1 次提交
  4. 09 5月, 2009 1 次提交
  5. 30 4月, 2009 1 次提交
    • A
      replace direct calls to unlink(2) with unlink_or_warn · 691f1a28
      Alex Riesen 提交于
      This helps to notice when something's going wrong, especially on
      systems which lock open files.
      
      I used the following criteria when selecting the code for replacement:
      - it was already printing a warning for the unlink failures
      - it is in a function which already printing something or is
        called from such a function
      - it is in a static function, returning void and the function is only
        called from a builtin main function (cmd_)
      - it is in a function which handles emergency exit (signal handlers)
      - it is in a function which is obvously cleaning up the lockfiles
      Signed-off-by: NAlex Riesen <raa.lkml@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      691f1a28
  6. 14 4月, 2009 1 次提交
  7. 08 4月, 2009 1 次提交
    • J
      make get_short_ref a public function · 7c2b3029
      Jeff King 提交于
      Often we want to shorten a full ref name to something "prettier"
      to show a user. For example, "refs/heads/master" is often shown
      simply as "master", or "refs/remotes/origin/master" is shown as
      "origin/master".
      
      Many places in the code use a very simple formula: skip common
      prefixes like refs/heads, refs/remotes, etc. This is codified in
      the prettify_ref function.
      
      for-each-ref has a more correct (but more expensive) approach:
      consider the ref lookup rules, and try shortening as much as
      possible while remaining unambiguous.
      
      This patch makes the latter strategy globally available as
      shorten_unambiguous_ref.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7c2b3029
  8. 30 3月, 2009 1 次提交
  9. 25 3月, 2009 1 次提交
    • S
      Don't permit ref/branch names to end with ".lock" · 3e262b95
      Shawn O. Pearce 提交于
      We already skip over loose refs under $GIT_DIR/refs if the name
      ends with ".lock", so creating a branch named "foo.lock" will not
      appear in the output of "git branch", "git for-each-ref", nor will
      its commit be considered reachable by "git rev-list --all".
      
      In the latter case this is especially evil, as it may cause
      repository corruption when objects reachable only through such a
      ref are deleted by "git prune".
      
      It should be reasonably safe to deny use of ".lock" as a ref suffix.
      In prior versions of Git such branches would be "phantom branches";
      you can create it, but you can't see it in "git branch" output.
      Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3e262b95
  10. 24 3月, 2009 2 次提交
    • J
      check_ref_format(): tighten refname rules · cbdffe40
      Junio C Hamano 提交于
      This changes the rules for refnames to forbid:
      
       (1) a refname that contains "@{" in it.
      
           Some people and foreign SCM converter may have named their branches
           as frotz@24 and we still want to keep supporting it.
      
           However, "git branch frotz@{24}" is a disaster.  It cannot even
           checked out because "git checkout frotz@{24}" will interpret it as
           "detach the HEAD at twenty-fourth reflog entry of the frotz branch".
      
       (2) a refname that ends with a dot.
      
           We already reject a path component that begins with a dot, primarily
           to avoid ambiguous range interpretation.  If we allowed ".B" as a
           valid ref, it is unclear if "A...B" means "in dot-B but not in A" or
           "either in A or B but not in both".
      
           But for this to be complete, we need also to forbid "A." to avoid "in
           B but not in A-dot".  This was not a problem in the original range
           notation, but we should have added this restriction when three-dot
           notation was introduced.
      
           Unlike "no dot at the beginning of any path component" rule, this
           rule does not have to be "no dot at the end of any path component",
           because you cannot abbreviate the tail end away, similar to you can
           say "dot-B" to mean "refs/heads/dot-B".
      
      For these reasons, it is not likely people created branches with these
      names on purpose, but we have allowed such names to be used for quite some
      time, and it is possible that people created such branches by mistake or
      by accident.
      
      To help people with branches with such unfortunate names to recover,
      we still allow "branch -d 'bad.'" to delete such branches, and also allow
      "branch -m bad. good" to rename them.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cbdffe40
    • M
  11. 10 3月, 2009 1 次提交
  12. 08 3月, 2009 2 次提交
  13. 26 2月, 2009 1 次提交
    • J
      refactor find_ref_by_name() to accept const list · 5483f799
      Jeff King 提交于
      Since it doesn't actually touch its argument, this makes
      sense.
      
      However, we still want to return a non-const version (which
      requires a cast) so that this:
      
        struct ref *a, *b;
        a = find_ref_by_name(b);
      
      works. Unfortunately, you can also silently strip the const
      from a variable:
      
        struct ref *a;
        const struct ref *b;
        a = find_ref_by_name(b);
      
      This is a classic C const problem because there is no way to
      say "return the type with the same constness that was passed
      to us"; we provide the same semantics as standard library
      functions like strchr.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJay Soffian <jaysoffian@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5483f799
  14. 11 2月, 2009 1 次提交
    • J
      remote prune: warn dangling symrefs · f8948e2f
      Junio C Hamano 提交于
      If you prune from the remote "frotz" that deleted the ref your tracking
      branch remotes/frotz/HEAD points at, the symbolic ref will become
      dangling.  We used to detect this as an error condition and issued a
      message every time refs are enumerated.
      
      This stops the error message, but moves the warning to "remote prune".
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f8948e2f
  15. 20 1月, 2009 1 次提交
  16. 12 11月, 2008 1 次提交
  17. 06 11月, 2008 1 次提交
  18. 01 11月, 2008 1 次提交
  19. 31 10月, 2008 3 次提交
  20. 27 10月, 2008 2 次提交
  21. 20 10月, 2008 1 次提交
  22. 09 9月, 2008 1 次提交
  23. 09 7月, 2008 2 次提交
    • J
      avoid null SHA1 in oldest reflog · d1a4489a
      Jeff King 提交于
      When the user specifies a ref by a reflog entry older than
      one we have (e.g., "HEAD@{20 years ago"}), we issue a
      warning and give them the "from" value of the oldest reflog
      entry. That is, we say "we don't know what happened before
      this entry, but before this we know we had some particular
      SHA1".
      
      However, the oldest reflog entry is often a creation event
      such as clone or branch creation. In this case, the entry
      claims that the ref went from "00000..." (the null sha1) to
      the new value, and the reflog lookup returns the null sha1.
      
      While this is technically correct (the entry tells us that
      the ref didn't exist at the specified time) it is not
      terribly useful to the end user. What they probably want
      instead is "the oldest useful sha1 that this ref ever had".
      This patch changes the behavior such that if the oldest ref
      would return the null sha1, it instead returns the first
      value the ref ever had.
      
      We never discovered this problem in the test scripts because
      we created "fake" reflogs that had only a specified segment
      of history. This patch updates the tests with a creation
      event at the beginning of history.
      Signed-off-by: NJeff King <peff@peff.net>
      Acked-by: NShawn O. Pearce <spearce@spearce.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d1a4489a
    • J
      make deleting a missing ref more quiet · 0b294c0a
      Jeff King 提交于
      If git attempts to delete a ref, but the unlink of the ref
      file fails, we print a message to stderr. This is usually a
      good thing, but if the error is ENOENT, then it indicates
      that the ref has _already_ been deleted. And since that's
      our goal, it doesn't make sense to complain to the user.
      
      This harmonizes the error reporting behavior for the
      unpacked and packed cases; the packed case already printed
      nothing on ENOENT, but the unpacked printed unconditionally.
      
      Additionally, send-pack would, when deleting the tracking
      ref corresponding to a remote delete, print "Failed to
      delete" on any failure. This can be a misleading
      message, since we actually _did_ delete at the remote side,
      but we failed to delete locally. Rather than make the
      message more precise, let's just eliminate it entirely; the
      delete_ref routine already takes care of printing out a much
      more specific message about what went wrong.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0b294c0a
  24. 05 5月, 2008 1 次提交
  25. 30 4月, 2008 1 次提交
  26. 09 4月, 2008 1 次提交
  27. 25 2月, 2008 1 次提交
    • S
      Optimize peel_ref for the current ref of a for_each_ref callback · 0ae91be0
      Shawn O. Pearce 提交于
      Currently the only caller of peel_ref is show-ref, which is using
      this function to show the peeled tag information if it is available
      from an existing packed-refs file.  The call happens during the
      for_each_ref callback function, so we have the proper struct ref_list
      already on the call stack but it is not easily available to return
      the peeled information to the caller.
      
      We now save the current struct ref_list item before calling back
      into the callback function so that future calls to peel_ref from
      within the callback function can quickly access the current ref.
      Doing so will save us an lstat() per ref processed as we no longer
      have to check the filesystem to see if the ref exists as a loose
      file or is packed.  This current ref caching also saves a linear
      scan of the cached packed refs list.
      
      As a micro-optimization we test the address of the passed ref name
      against the current_ref->name before we go into the much more costly
      strcmp().  Nearly any caller of peel_ref will be passing us the same
      string do_for_each_ref passed them, which is current_ref->name.
      Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0ae91be0
  28. 24 2月, 2008 1 次提交
  29. 23 2月, 2008 1 次提交
  30. 17 1月, 2008 3 次提交
    • B
      refs.c: rework ref_locks by abstracting from underlying struct lock_file · b531394d
      Brandon Casey 提交于
      Instead of calling close_lock_file() and commit_lock_file() directly,
      which take a struct lock_file argument, add two new functions:
      close_ref() and commit_ref(), which handle calling the previous
      lock_file functions and modifying the ref_lock structure.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b531394d
    • B
      Improve use of lockfile API · 4ed7cd3a
      Brandon Casey 提交于
      Remove remaining double close(2)'s.  i.e. close() before
      commit_locked_index() or commit_lock_file().
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4ed7cd3a
    • L
      Be more careful about updating refs · c3b0dec5
      Linus Torvalds 提交于
      This makes write_ref_sha1() more careful: it actually checks the SHA1 of
      the ref it is updating, and refuses to update a ref with an object that it
      cannot find.
      
      Perhaps more importantly, it also refuses to update a branch head with a
      non-commit object. I don't quite know *how* the stable series maintainers
      were able to corrupt their repository to have a HEAD that pointed to a tag
      rather than a commit object, but they did. Which results in a totally
      broken repository that cannot be cloned or committed on.
      
      So make it harder for people to shoot themselves in the foot like that.
      
      The test t1400-update-ref.sh is fixed at the same time, as it
      assumed that the commands involved in the particular test would
      not care about corrupted repositories whose refs point at
      nonexistant bogus objects.  That assumption does not hold true
      anymore.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c3b0dec5
  31. 03 1月, 2008 1 次提交
    • J
      Update callers of check_ref_format() · 257f3020
      Junio C Hamano 提交于
      This updates send-pack and fast-import to use symbolic constants
      for checking the return values from check_ref_format(), and also
      futureproof the logic in lock_any_ref_for_update() to explicitly
      name the case that is usually considered an error but is Ok for
      this particular use.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      257f3020
  32. 02 1月, 2008 1 次提交
    • J
      lock_any_ref_for_update(): reject wildcard return from check_ref_format · 5f7b202a
      Junio C Hamano 提交于
      Recent check_ref_format() returns -3 as well as -1 (general
      error) and -2 (less than two levels).  The caller was explicitly
      checking for -1, to allow "HEAD" but still needed to disallow
      bogus refs.
      
      This introduces symbolic constants for the return values from
      check_ref_format() to make them read better and more
      meaningful.  Normal ref creation codepath can still treat
      non-zero return values as errors.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5f7b202a