Merge branch 'wh/normalize-alt-odb-path'
* wh/normalize-alt-odb-path: sha1_file: normalize alt_odb path before comparing and storing
This commit is contained in:
		
							
								
								
									
										37
									
								
								sha1_file.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								sha1_file.c
									
									
									
									
									
								
							@ -248,27 +248,30 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
 | 
				
			|||||||
	const char *objdir = get_object_directory();
 | 
						const char *objdir = get_object_directory();
 | 
				
			||||||
	struct alternate_object_database *ent;
 | 
						struct alternate_object_database *ent;
 | 
				
			||||||
	struct alternate_object_database *alt;
 | 
						struct alternate_object_database *alt;
 | 
				
			||||||
	/* 43 = 40-byte + 2 '/' + terminating NUL */
 | 
						int pfxlen, entlen;
 | 
				
			||||||
	int pfxlen = len;
 | 
						struct strbuf pathbuf = STRBUF_INIT;
 | 
				
			||||||
	int entlen = pfxlen + 43;
 | 
					 | 
				
			||||||
	int base_len = -1;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!is_absolute_path(entry) && relative_base) {
 | 
						if (!is_absolute_path(entry) && relative_base) {
 | 
				
			||||||
		/* Relative alt-odb */
 | 
							strbuf_addstr(&pathbuf, real_path(relative_base));
 | 
				
			||||||
		if (base_len < 0)
 | 
							strbuf_addch(&pathbuf, '/');
 | 
				
			||||||
			base_len = strlen(relative_base) + 1;
 | 
					 | 
				
			||||||
		entlen += base_len;
 | 
					 | 
				
			||||||
		pfxlen += base_len;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						strbuf_add(&pathbuf, entry, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						normalize_path_copy(pathbuf.buf, pathbuf.buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pfxlen = strlen(pathbuf.buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * The trailing slash after the directory name is given by
 | 
				
			||||||
 | 
						 * this function at the end. Remove duplicates.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						while (pfxlen && pathbuf.buf[pfxlen-1] == '/')
 | 
				
			||||||
 | 
							pfxlen -= 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						entlen = pfxlen + 43; /* '/' + 2 hex + '/' + 38 hex + NUL */
 | 
				
			||||||
	ent = xmalloc(sizeof(*ent) + entlen);
 | 
						ent = xmalloc(sizeof(*ent) + entlen);
 | 
				
			||||||
 | 
						memcpy(ent->base, pathbuf.buf, pfxlen);
 | 
				
			||||||
	if (!is_absolute_path(entry) && relative_base) {
 | 
						strbuf_release(&pathbuf);
 | 
				
			||||||
		memcpy(ent->base, relative_base, base_len - 1);
 | 
					 | 
				
			||||||
		ent->base[base_len - 1] = '/';
 | 
					 | 
				
			||||||
		memcpy(ent->base + base_len, entry, len);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		memcpy(ent->base, entry, pfxlen);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ent->name = ent->base + pfxlen + 1;
 | 
						ent->name = ent->base + pfxlen + 1;
 | 
				
			||||||
	ent->base[pfxlen + 3] = '/';
 | 
						ent->base[pfxlen + 3] = '/';
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user