@@ -89,32 +89,43 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
89
89
90
90
Path localRefFile = cacheDir + " /refs/heads/" + localRef;
91
91
92
- /* If the local ref is older than ‘tarball-ttl’ seconds, do a git
93
- fetch to update the local ref to the remote ref. */
92
+ bool doFetch;
94
93
time_t now = time (0 );
95
- struct stat st;
96
- if (stat (localRefFile.c_str (), &st) != 0 ||
97
- st.st_mtime <= now - settings.tarballTtl )
98
- {
99
- if (rev == " " ||
100
- chomp (runProgram (
101
- RunOptions (" git" , { " -C" , cacheDir, " cat-file" , " -t" , rev })
102
- .killStderr (true )).second ) != " commit" )
103
- {
104
- Activity act (*logger, lvlTalkative, actUnknown, fmt (" fetching Git repository '%s'" , uri));
105
-
106
- // FIXME: git stderr messes up our progress indicator, so
107
- // we're using --quiet for now. Should process its stderr.
108
- runProgram (" git" , true , { " -C" , cacheDir, " fetch" , " --quiet" , " --force" , " --" , uri, *ref + " :" + localRef });
109
-
110
- struct timeval times[2 ];
111
- times[0 ].tv_sec = now;
112
- times[0 ].tv_usec = 0 ;
113
- times[1 ].tv_sec = now;
114
- times[1 ].tv_usec = 0 ;
115
-
116
- utimes (localRefFile.c_str (), times);
94
+ /* If a rev was specified, we need to fetch if it's not in the
95
+ repo. */
96
+ if (rev != " " ) {
97
+ try {
98
+ runProgram (" git" , true , { " -C" , cacheDir, " cat-file" , " -e" , rev });
99
+ doFetch = false ;
100
+ } catch (ExecError & e) {
101
+ if (WIFEXITED (e.status )) {
102
+ doFetch = true ;
103
+ } else {
104
+ throw ;
105
+ }
117
106
}
107
+ } else {
108
+ /* If the local ref is older than ‘tarball-ttl’ seconds, do a
109
+ git fetch to update the local ref to the remote ref. */
110
+ struct stat st;
111
+ doFetch = stat (localRefFile.c_str (), &st) != 0 ||
112
+ st.st_mtime <= now - settings.tarballTtl ;
113
+ }
114
+ if (doFetch)
115
+ {
116
+ Activity act (*logger, lvlTalkative, actUnknown, fmt (" fetching Git repository '%s'" , uri));
117
+
118
+ // FIXME: git stderr messes up our progress indicator, so
119
+ // we're using --quiet for now. Should process its stderr.
120
+ runProgram (" git" , true , { " -C" , cacheDir, " fetch" , " --quiet" , " --force" , " --" , uri, *ref + " :" + localRef });
121
+
122
+ struct timeval times[2 ];
123
+ times[0 ].tv_sec = now;
124
+ times[0 ].tv_usec = 0 ;
125
+ times[1 ].tv_sec = now;
126
+ times[1 ].tv_usec = 0 ;
127
+
128
+ utimes (localRefFile.c_str (), times);
118
129
}
119
130
120
131
// FIXME: check whether rev is an ancestor of ref.
0 commit comments