Merge branch 'jc/reflog' into lj/refs
authorJunio C Hamano <junkio@cox.net>
Fri, 27 Oct 2006 01:48:30 +0000 (18:48 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 27 Oct 2006 01:48:30 +0000 (18:48 -0700)
* jc/reflog:
sha1_name.c: avoid compilation warnings.
ref-log: allow ref@{count} syntax.

1  2 
refs.c
diff --combined refs.c
index ed2e3b16a7c843d75da361011b36c74d51f629b8,d7f4aa5d87b0fc33abb25864fa92b8001b415f53..f003a0b1080267b419296b3b37312b858b8b215d
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -721,8 -721,7 +721,8 @@@ static int log_ref_write(struct ref_loc
        char *logrec;
        const char *committer;
  
 -      if (log_all_ref_updates) {
 +      if (log_all_ref_updates &&
 +          !strncmp(lock->ref_name, "refs/heads/", 11)) {
                if (safe_create_leading_directories(lock->log_file) < 0)
                        return error("unable to create directory for %s",
                                lock->log_file);
  
        logfd = open(lock->log_file, oflags, 0666);
        if (logfd < 0) {
 -              if (!log_all_ref_updates && errno == ENOENT)
 +              if (!(oflags & O_CREAT) && errno == ENOENT)
                        return 0;
 -              return error("Unable to append to %s: %s",
 -                      lock->log_file, strerror(errno));
 +
 +              if ((oflags & O_CREAT) && errno == EISDIR) {
 +                      if (remove_empty_directories(lock->log_file)) {
 +                              return error("There are still logs under '%s'",
 +                                           lock->log_file);
 +                      }
 +                      logfd = open(lock->log_file, oflags, 0666);
 +              }
 +
 +              if (logfd < 0)
 +                      return error("Unable to append to %s: %s",
 +                                   lock->log_file, strerror(errno));
        }
  
        committer = git_committer_info(1);
@@@ -806,7 -795,7 +806,7 @@@ int write_ref_sha1(struct ref_lock *loc
        return 0;
  }
  
- int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
+ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1)
  {
        const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
        char *tz_c;
                if (!lastgt)
                        die("Log %s is corrupt.", logfile);
                date = strtoul(lastgt + 1, &tz_c, 10);
-               if (date <= at_time) {
+               if (date <= at_time || cnt == 0) {
                        if (lastrec) {
                                if (get_sha1_hex(lastrec, logged_sha1))
                                        die("Log %s is corrupt.", logfile);
                        return 0;
                }
                lastrec = rec;
+               if (cnt > 0)
+                       cnt--;
        }
  
        rec = logdata;