1. 02 12月, 2014 1 次提交
    • N
      reflog: avoid constructing .lock path with git_path · 1fdc2abf
      Nguyễn Thái Ngọc Duy 提交于
      Among pathnames in $GIT_DIR, e.g. "index" or "packed-refs", we want to
      automatically and silently map some of them to the $GIT_DIR of the
      repository we are borrowing from via $GIT_COMMON_DIR mechanism.  When
      we formulate the pathname for its lockfile, we want it to be in the
      same location as its final destination.  "index" is not shared and
      needs to remain in the borrowing repository, while "packed-refs" is
      shared and needs to go to the borrowed repository.
      
      git_path() could be taught about the ".lock" suffix and map
      "index.lock" and "packed-refs.lock" the same way their basenames are
      mapped, but instead the caller can help by asking where the basename
      (e.g. "index") is mapped to git_path() and then appending ".lock"
      after the mapping is done.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1fdc2abf
  2. 17 10月, 2014 1 次提交
    • J
      prune: keep objects reachable from recent objects · d3038d22
      Jeff King 提交于
      Our current strategy with prune is that an object falls into
      one of three categories:
      
        1. Reachable (from ref tips, reflogs, index, etc).
      
        2. Not reachable, but recent (based on the --expire time).
      
        3. Not reachable and not recent.
      
      We keep objects from (1) and (2), but prune objects in (3).
      The point of (2) is that these objects may be part of an
      in-progress operation that has not yet updated any refs.
      
      However, it is not always the case that objects for an
      in-progress operation will have a recent mtime. For example,
      the object database may have an old copy of a blob (from an
      abandoned operation, a branch that was deleted, etc). If we
      create a new tree that points to it, a simultaneous prune
      will leave our tree, but delete the blob. Referencing that
      tree with a commit will then work (we check that the tree is
      in the object database, but not that all of its referred
      objects are), as will mentioning the commit in a ref. But
      the resulting repo is corrupt; we are missing the blob
      reachable from a ref.
      
      One way to solve this is to be more thorough when
      referencing a sha1: make sure that not only do we have that
      sha1, but that we have objects it refers to, and so forth
      recursively. The problem is that this is very expensive.
      Creating a parent link would require traversing the entire
      object graph!
      
      Instead, this patch pushes the extra work onto prune, which
      runs less frequently (and has to look at the whole object
      graph anyway). It creates a new category of objects: objects
      which are not recent, but which are reachable from a recent
      object. We do not prune these objects, just like the
      reachable and recent ones.
      
      This lets us avoid the recursive check above, because if we
      have an object, even if it is unreachable, we should have
      its referent. We can make a simple inductive argument that
      with this patch, this property holds (that there are no
      objects with missing referents in the repository):
      
        0. When we have no objects, we have nothing to refer or be
           referred to, so the property holds.
      
        1. If we add objects to the repository, their direct
           referents must generally exist (e.g., if you create a
           tree, the blobs it references must exist; if you create
           a commit to point at the tree, the tree must exist).
           This is already the case before this patch. And it is
           not 100% foolproof (you can make bogus objects using
           `git hash-object`, for example), but it should be the
           case for normal usage.
      
           Therefore for any sequence of object additions, the
           property will continue to hold.
      
        2. If we remove objects from the repository, then we will
           not remove a child object (like a blob) if an object
           that refers to it is being kept. That is the part
           implemented by this patch.
      
           Note, however, that our reachability check and the
           actual pruning are not atomic. So it _is_ still
           possible to violate the property (e.g., an object
           becomes referenced just as we are deleting it). This
           patch is shooting for eliminating problems where the
           mtimes of dependent objects differ by hours or days,
           and one is dropped without the other. It does nothing
           to help with short races.
      
      Naively, the simplest way to implement this would be to add
      all recent objects as tips to the reachability traversal.
      However, this does not perform well. In a recently-packed
      repository, all reachable objects will also be recent, and
      therefore we have to look at each object twice. This patch
      instead performs the reachability traversal, then follows up
      with a second traversal for recent objects, skipping any
      that have already been marked.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d3038d22
  3. 02 10月, 2014 2 次提交
  4. 09 5月, 2014 1 次提交
    • R
      refs.c: add new functions reflog_exists and delete_reflog · 4da58835
      Ronnie Sahlberg 提交于
      Add two new functions, reflog_exists and delete_reflog, to hide the internal
      reflog implementation (that they are files under .git/logs/...) from callers.
      Update checkout.c to use these functions in update_refs_for_switch instead of
      building pathnames and calling out to file access functions. Update reflog.c
      to use these to check if the reflog exists. Now there are still many places
      in reflog.c where we are still leaking the reflog storage implementation but
      this at least reduces the number of such dependencies by one. Finally
      change two places in refs.c itself to use the new function to check if a ref
      exists or not isntead of build-path-and-stat(). Now, this is strictly not all
      that important since these are in parts of refs that are implementing the
      actual file storage backend but on the other hand it will not hurt either.
      Signed-off-by: NRonnie Sahlberg <sahlberg@google.com>
      Acked-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4da58835
  5. 21 2月, 2014 1 次提交
  6. 06 12月, 2013 1 次提交
    • C
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder 提交于
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59556548
  7. 31 8月, 2013 1 次提交
  8. 07 6月, 2013 1 次提交
    • J
      clear parsed flag when we free tree buffers · 6e454b9a
      Jeff King 提交于
      Many code paths will free a tree object's buffer and set it
      to NULL after finishing with it in order to keep memory
      usage down during a traversal. However, out of 8 sites that
      do this, only one actually unsets the "parsed" flag back.
      Those sites that don't are setting a trap for later users of
      the tree object; even after calling parse_tree, the buffer
      will remain NULL, causing potential segfaults.
      
      It is not known whether this is triggerable in the current
      code. Most commands do not do an in-memory traversal
      followed by actually using the objects again. However, it
      does not hurt to be safe for future callers.
      
      In most cases, we can abstract this out to a
      "free_tree_buffer" helper. However, there are two
      exceptions:
      
        1. The fsck code relies on the parsed flag to know that we
           were able to parse the object at one point. We can
           switch this to using a flag in the "flags" field.
      
        2. The index-pack code sets the buffer to NULL but does
           not free it (it is freed by a caller). We should still
           unset the parsed flag here, but we cannot use our
           helper, as we do not want to free the buffer.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6e454b9a
  9. 18 4月, 2013 1 次提交
    • J
      date.c: add parse_expiry_date() · 3d27b9b0
      Junio C Hamano 提交于
      "git reflog --expire=all" tries to expire reflog entries up to the
      current second, because the approxidate() parser gives the current
      timestamp for anything it does not understand (and it does not know
      what time "all" means).  When the user tells us to expire "all" (or
      set the expiration time to "now"), the user wants to remove all the
      reflog entries (no reflog entry should record future time).
      
      Just set it to ULONG_MAX and to let everything that is older that
      timestamp expire.
      
      While at it, allow "now" to be treated the same way for callers that
      parse expiry date timestamp with this function.  Also use an error
      reporting version of approxidate() to report misspelled date.  When
      the user says e.g. "--expire=mnoday" to delete entries two days or
      older on Wednesday, we wouldn't want the "unknown, default to now"
      logic to kick in.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3d27b9b0
  10. 06 3月, 2013 1 次提交
  11. 24 1月, 2013 1 次提交
  12. 08 6月, 2012 1 次提交
  13. 08 11月, 2011 1 次提交
  14. 02 8月, 2011 1 次提交
  15. 23 2月, 2010 1 次提交
    • L
      Move 'builtin-*' into a 'builtin/' subdirectory · 81b50f3c
      Linus Torvalds 提交于
      This shrinks the top-level directory a bit, and makes it much more
      pleasant to use auto-completion on the thing. Instead of
      
      	[torvalds@nehalem git]$ em buil<tab>
      	Display all 180 possibilities? (y or n)
      	[torvalds@nehalem git]$ em builtin-sh
      	builtin-shortlog.c     builtin-show-branch.c  builtin-show-ref.c
      	builtin-shortlog.o     builtin-show-branch.o  builtin-show-ref.o
      	[torvalds@nehalem git]$ em builtin-shor<tab>
      	builtin-shortlog.c  builtin-shortlog.o
      	[torvalds@nehalem git]$ em builtin-shortlog.c
      
      you get
      
      	[torvalds@nehalem git]$ em buil<tab>		[type]
      	builtin/   builtin.h
      	[torvalds@nehalem git]$ em builtin		[auto-completes to]
      	[torvalds@nehalem git]$ em builtin/sh<tab>	[type]
      	shortlog.c     shortlog.o     show-branch.c  show-branch.o  show-ref.c     show-ref.o
      	[torvalds@nehalem git]$ em builtin/sho		[auto-completes to]
      	[torvalds@nehalem git]$ em builtin/shor<tab>	[type]
      	shortlog.c  shortlog.o
      	[torvalds@nehalem git]$ em builtin/shortlog.c
      
      which doesn't seem all that different, but not having that annoying
      break in "Display all 180 possibilities?" is quite a relief.
      
      NOTE! If you do this in a clean tree (no object files etc), or using an
      editor that has auto-completion rules that ignores '*.o' files, you
      won't see that annoying 'Display all 180 possibilities?' message - it
      will just show the choices instead.  I think bash has some cut-off
      around 100 choices or something.
      
      So the reason I see this is that I'm using an odd editory, and thus
      don't have the rules to cut down on auto-completion.  But you can
      simulate that by using 'ls' instead, or something similar.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      81b50f3c
  16. 11 11月, 2009 1 次提交
  17. 13 9月, 2009 1 次提交
    • J
      use write_str_in_full helper to avoid literal string lengths · 2b7ca830
      Jim Meyering 提交于
      In 2d14d65c (Use a clearer style to issue commands to remote helpers,
      2009-09-03) I happened to notice two changes like this:
      
      -	write_in_full(helper->in, "list\n", 5);
      +
      +	strbuf_addstr(&buf, "list\n");
      +	write_in_full(helper->in, buf.buf, buf.len);
      +	strbuf_reset(&buf);
      
      IMHO, it would be better to define a new function,
      
          static inline ssize_t write_str_in_full(int fd, const char *str)
          {
                 return write_in_full(fd, str, strlen(str));
          }
      
      and then use it like this:
      
      -       strbuf_addstr(&buf, "list\n");
      -       write_in_full(helper->in, buf.buf, buf.len);
      -       strbuf_reset(&buf);
      +       write_str_in_full(helper->in, "list\n");
      
      Thus not requiring the added allocation, and still avoiding
      the maintenance risk of literal string lengths.
      These days, compilers are good enough that strlen("literal")
      imposes no run-time cost.
      
      Transformed via this:
      
          perl -pi -e \
              's/write_in_full\((.*?), (".*?"), \d+\)/write_str_in_full($1, $2)/'\
            $(git grep -l 'write_in_full.*"')
      Signed-off-by: NJim Meyering <meyering@redhat.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2b7ca830
  18. 06 8月, 2009 1 次提交
  19. 23 4月, 2009 2 次提交
  20. 20 4月, 2009 2 次提交
  21. 02 4月, 2009 2 次提交
  22. 31 10月, 2008 1 次提交
  23. 18 8月, 2008 1 次提交
  24. 11 8月, 2008 1 次提交
  25. 14 7月, 2008 1 次提交
    • S
      Make usage strings dash-less · 1b1dd23f
      Stephan Beyer 提交于
      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: NStephan Beyer <s-beyer@gmx.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1b1dd23f
  26. 29 6月, 2008 2 次提交
    • J
      Make default expiration period of reflog used for stash infinite · 60bce2bb
      Junio C Hamano 提交于
      This makes the default expiration period for the reflog that implements
      stash infinite.
      
      The original behaviour to autoexpire old stashes can be restored by using
      the gc.refs/stash.{reflogexpire,reflogexpireunreachable} configration
      variables introduced by the previous commit.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      60bce2bb
    • J
      Per-ref reflog expiry configuration · 3cb22b8e
      Junio C Hamano 提交于
      In addition to gc.reflogexpireunreachable and gc.reflogexpire, this lets
      you set gc.<pattern>.reflogexpireunreachable and gc.<pattern>.reflogexpire
      variables.
      
      When "git reflog expire" expires reflog entry for $ref, the expiry timers
      are taken from the first <pattern> that matches $ref (and if there isn't
      the global default value is used).
      
      For example, you could:
      
      	[gc "refs/stash"]
      		reflogexpire = never
      		reflogexpireunreachable = never
      
      	[gc "refs/remotes/*"]
      		reflogexpire = 7 days
      		reflogexpireunreachable = 3 days
      
      	[gc]
      		reflogexpire = 90 days
      		reflogexpireunreachable = 30 days
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3cb22b8e
  27. 16 6月, 2008 1 次提交
  28. 15 5月, 2008 1 次提交
  29. 28 2月, 2008 1 次提交
  30. 23 2月, 2008 4 次提交
  31. 12 2月, 2008 1 次提交
  32. 30 1月, 2008 1 次提交
    • J
      reflog-expire: Avoid creating new files in a directory inside readdir(3) loop · bda3a31c
      Junio C Hamano 提交于
      "git reflog expire --all" opened a directory in $GIT_DIR/logs/,
      read reflog files in there readdir(3), and rewrote the file by
      creating a new file and renaming it back inside the loop.  This
      code structure can cause the newly created file to be returned
      by subsequent call to readdir(3), and fall into an infinite loop
      in the worst case.
      
      This separates the processing to two phase.  Running
      for_each_reflog() to find out and collect all refs, and then
      iterate over them, calling expire_reflog().  This way, the
      program would behave exactly the same way as if all the refs
      were given by the user from the command line.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bda3a31c